From dc0da41fb1e901874f5f2263f176bc107820d9d5 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Mon, 20 Jul 2020 13:37:33 +0200 Subject: [PATCH] Checkbox example --- UI/Base/CheckBox.ts | 4 +++- test.ts | 13 ++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/UI/Base/CheckBox.ts b/UI/Base/CheckBox.ts index 6fd92148a..9cdb21e8f 100644 --- a/UI/Base/CheckBox.ts +++ b/UI/Base/CheckBox.ts @@ -3,15 +3,17 @@ import {UIEventSource} from "../UIEventSource"; export class CheckBox extends UIElement{ + private data: UIEventSource; constructor(data: UIEventSource) { super(data); + this.data = data; } protected InnerRender(): string { - return ""; + return "Current val: "+this.data.data; } } \ No newline at end of file diff --git a/test.ts b/test.ts index b7e9bd39c..8957dc070 100644 --- a/test.ts +++ b/test.ts @@ -7,11 +7,14 @@ import {OsmLink} from "./Customizations/Questions/OsmLink"; import {ConfirmDialog} from "./UI/ConfirmDialog"; import {Imgur} from "./Logic/Imgur"; import {VariableUiElement} from "./UI/Base/VariableUIElement"; +import {CheckBox} from "./UI/Base/CheckBox"; -const html = new UIEventSource("Some text"); +const eventSource = new UIEventSource(false); +eventSource.addCallback(console.log) -const uielement = new VariableUiElement(html); -uielement.AttachTo("maindiv") - -window.setTimeout(() => {html.setData("Different text")}, 1000) \ No newline at end of file +new CheckBox(eventSource) + .onClick(() => { + eventSource.setData(!eventSource.data); + }) + .AttachTo("maindiv");