mapcomplete/UI/Base/CheckBox.ts

32 lines
886 B
TypeScript
Raw Normal View History

2020-07-20 13:30:58 +02:00
import {UIElement} from "../UIElement";
import {UIEventSource} from "../UIEventSource";
2020-07-20 16:57:46 +02:00
import { FilteredLayer } from "../../Logic/FilteredLayer";
2020-07-20 13:30:58 +02:00
export class CheckBox extends UIElement{
2020-07-22 11:01:25 +02:00
private readonly _data: UIEventSource<boolean>;
private readonly _showEnabled: string|UIElement;
private readonly _showDisabled: string|UIElement;
constructor(data: UIEventSource<boolean>, showEnabled: string|UIElement, showDisabled: string|UIElement) {
2020-07-20 13:30:58 +02:00
super(data);
2020-07-22 11:01:25 +02:00
this._data = data;
this._showEnabled = showEnabled;
this._showDisabled = showDisabled;
this.onClick(() => {
data.setData(!data.data);
})
2020-07-20 13:30:58 +02:00
}
protected InnerRender(): string {
2020-07-22 11:01:25 +02:00
if (this._data.data) {
return this._showEnabled;
} else {
return this._showDisabled;
}
2020-07-20 13:30:58 +02:00
}
}