MainWidget.tsx
49 lines
| 1.4 KiB
| text/x-typescript
|
TypeScriptLexer
cin
|
r99 | import { djbase, djclass } from "@implab/djx/declare"; | ||
import { DjxWidgetBase } from "@implab/djx/tsx/DjxWidgetBase"; | ||||
cin
|
r101 | import { createElement, watch } from "@implab/djx/tsx"; | ||
cin
|
r100 | import ProgressBar from "./ProgressBar"; | ||
cin
|
r101 | import Button = require("dijit/form/Button"); | ||
cin
|
r100 | |||
const ref = <W extends DjxWidgetBase, K extends keyof W>(target: W, name: K) => (v: W[K]) => target.set(name, v); | ||||
cin
|
r99 | |||
@djclass | ||||
export default class MainWidget extends djbase(DjxWidgetBase) { | ||||
cin
|
r100 | |||
titleNode?: HTMLHeadingElement; | ||||
progressBar?: ProgressBar; | ||||
cin
|
r101 | count = 0; | ||
showCounter = false; | ||||
cin
|
r99 | render() { | ||
cin
|
r101 | return <div className="tundra"> | ||
cin
|
r100 | <h2 ref={ref(this, "titleNode")}>Hi!</h2> | ||
cin
|
r101 | <ProgressBar ref={ref(this, "progressBar")} /> | ||
{watch(this, "showCounter", flag => flag && | ||||
<section style={{padding: "10px"}}> | ||||
<label> | ||||
Counter: {watch(this, "count", v => [<span>{v}</span>, " ", <span>sec</span>])} | ||||
</label> | ||||
</section> | ||||
)} | ||||
<Button onClick={this._onToggleCounterClick}>Toggle counter</Button> | ||||
cin
|
r99 | </div>; | ||
} | ||||
cin
|
r101 | |||
postCreate(): void { | ||||
super.postCreate(); | ||||
const inc = () => { | ||||
this.set("count", this.count + 1); | ||||
this.defer(inc, 1000); | ||||
} | ||||
inc(); | ||||
} | ||||
private _onToggleCounterClick = () => { | ||||
this.set("showCounter", !this.showCounter); | ||||
} | ||||
cin
|
r99 | } | ||