Checkbox example

This commit is contained in:
Pieter Vander Vennet 2020-07-20 13:37:33 +02:00
parent 4abe74fbf1
commit dc0da41fb1
2 changed files with 11 additions and 6 deletions

View file

@ -3,15 +3,17 @@ import {UIEventSource} from "../UIEventSource";
export class CheckBox extends UIElement{ export class CheckBox extends UIElement{
private data: UIEventSource<boolean>;
constructor(data: UIEventSource<boolean>) { constructor(data: UIEventSource<boolean>) {
super(data); super(data);
this.data = data;
} }
protected InnerRender(): string { protected InnerRender(): string {
return ""; return "Current val: "+this.data.data;
} }
} }

13
test.ts
View file

@ -7,11 +7,14 @@ import {OsmLink} from "./Customizations/Questions/OsmLink";
import {ConfirmDialog} from "./UI/ConfirmDialog"; import {ConfirmDialog} from "./UI/ConfirmDialog";
import {Imgur} from "./Logic/Imgur"; import {Imgur} from "./Logic/Imgur";
import {VariableUiElement} from "./UI/Base/VariableUIElement"; import {VariableUiElement} from "./UI/Base/VariableUIElement";
import {CheckBox} from "./UI/Base/CheckBox";
const html = new UIEventSource<string>("Some text"); const eventSource = new UIEventSource(false);
eventSource.addCallback(console.log)
const uielement = new VariableUiElement(html); new CheckBox(eventSource)
uielement.AttachTo("maindiv") .onClick(() => {
eventSource.setData(!eventSource.data);
window.setTimeout(() => {html.setData("Different text")}, 1000) })
.AttachTo("maindiv");