forked from MapComplete/MapComplete
Butchering the UI framework
This commit is contained in:
parent
8d404b1ba9
commit
6415e195d1
90 changed files with 1012 additions and 3101 deletions
22
UI/Input/Toggle.ts
Normal file
22
UI/Input/Toggle.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
import {UIEventSource} from "../../Logic/UIEventSource";
|
||||
import BaseUIElement from "../BaseUIElement";
|
||||
import {VariableUiElement} from "../Base/VariableUIElement";
|
||||
|
||||
/**
|
||||
* The 'Toggle' is a UIElement showing either one of two elements, depending on the state.
|
||||
* It can be used to implement e.g. checkboxes or collapsible elements
|
||||
*/
|
||||
export default class Toggle extends VariableUiElement{
|
||||
|
||||
public readonly isEnabled: UIEventSource<boolean>;
|
||||
|
||||
constructor(showEnabled: string | BaseUIElement, showDisabled: string | BaseUIElement, data: UIEventSource<boolean> = new UIEventSource<boolean>(false)) {
|
||||
super(
|
||||
data.map(isEnabled => isEnabled ? showEnabled : showDisabled)
|
||||
);
|
||||
this.onClick(() => {
|
||||
data.setData(!data.data);
|
||||
})
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue