From 5ab3532aa17f830c5d4d4d004be450fc6ac127b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Mon, 28 Jan 2019 12:13:03 +0100 Subject: [PATCH] add color widget in discuss --- web/static/src/ts/widgets/Discuss.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/web/static/src/ts/widgets/Discuss.ts b/web/static/src/ts/widgets/Discuss.ts index 26b8e316..7ffb560d 100644 --- a/web/static/src/ts/widgets/Discuss.ts +++ b/web/static/src/ts/widgets/Discuss.ts @@ -9,6 +9,7 @@ const template = ` + @@ -18,15 +19,15 @@ const template = ` -
+
`; export class Discuss extends Widget { name = "discuss"; template = template; - widgets = { Clock, Counter }; - state = { validcounter: true }; + widgets = { Clock, Counter, ColorWidget }; + state = { validcounter: true, color: "red" }; mounted() {} resetCounter(ev: MouseEvent) { @@ -46,4 +47,19 @@ export class Discuss extends Widget { toggle() { this.updateState({ validcounter: !this.state.validcounter }); } + + toggleColor() { + const newColor = this.state.color === "red" ? "blue" : "red"; + this.updateState({ color: newColor }); + } +} + +class ColorWidget extends Widget { + name = "colorwidget"; + template = `
Current Color:
`; + state: { color: "red" | "blue" }; + constructor(parent: Widget, props: { color: "red" | "blue" }) { + super(parent); + this.state = { color: props.color }; + } }