forked from MapComplete/MapComplete
Reformat all files with prettier
This commit is contained in:
parent
e22d189376
commit
b541d3eab4
382 changed files with 50893 additions and 35566 deletions
|
@ -1,20 +1,21 @@
|
|||
import {Store, UIEventSource} from "../../Logic/UIEventSource";
|
||||
import BaseUIElement from "../BaseUIElement";
|
||||
import {VariableUiElement} from "../Base/VariableUIElement";
|
||||
import Lazy from "../Base/Lazy";
|
||||
import { Store, UIEventSource } from "../../Logic/UIEventSource"
|
||||
import BaseUIElement from "../BaseUIElement"
|
||||
import { VariableUiElement } from "../Base/VariableUIElement"
|
||||
import Lazy from "../Base/Lazy"
|
||||
|
||||
/**
|
||||
* 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: Store<boolean>
|
||||
|
||||
public readonly isEnabled: Store<boolean>;
|
||||
|
||||
constructor(showEnabled: string | BaseUIElement, showDisabled: string | BaseUIElement, isEnabled: Store<boolean>) {
|
||||
super(
|
||||
isEnabled?.map(isEnabled => isEnabled ? showEnabled : showDisabled)
|
||||
);
|
||||
constructor(
|
||||
showEnabled: string | BaseUIElement,
|
||||
showDisabled: string | BaseUIElement,
|
||||
isEnabled: Store<boolean>
|
||||
) {
|
||||
super(isEnabled?.map((isEnabled) => (isEnabled ? showEnabled : showDisabled)))
|
||||
this.isEnabled = isEnabled
|
||||
}
|
||||
|
||||
|
@ -22,35 +23,30 @@ export default class Toggle extends VariableUiElement {
|
|||
if (constructor === undefined) {
|
||||
return undefined
|
||||
}
|
||||
return new Toggle(
|
||||
new Lazy(constructor),
|
||||
undefined,
|
||||
condition
|
||||
)
|
||||
|
||||
return new Toggle(new Lazy(constructor), undefined, condition)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as `Toggle`, but will swap on click
|
||||
*/
|
||||
export class ClickableToggle extends Toggle {
|
||||
public readonly isEnabled: UIEventSource<boolean>
|
||||
|
||||
public readonly isEnabled: UIEventSource<boolean>;
|
||||
|
||||
constructor(showEnabled: string | BaseUIElement, showDisabled: string | BaseUIElement, isEnabled: UIEventSource<boolean> = new UIEventSource<boolean>(false)) {
|
||||
super(
|
||||
showEnabled, showDisabled, isEnabled
|
||||
);
|
||||
constructor(
|
||||
showEnabled: string | BaseUIElement,
|
||||
showDisabled: string | BaseUIElement,
|
||||
isEnabled: UIEventSource<boolean> = new UIEventSource<boolean>(false)
|
||||
) {
|
||||
super(showEnabled, showDisabled, isEnabled)
|
||||
this.isEnabled = isEnabled
|
||||
}
|
||||
|
||||
|
||||
public ToggleOnClick(): ClickableToggle {
|
||||
const self = this;
|
||||
const self = this
|
||||
this.onClick(() => {
|
||||
self.isEnabled.setData(!self.isEnabled.data);
|
||||
self.isEnabled.setData(!self.isEnabled.data)
|
||||
})
|
||||
return this;
|
||||
return this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue