MyWidget.tsx
69 lines
| 1.8 KiB
| text/x-typescript
|
TypeScriptLexer
|
|
r65 | import { djbase, djclass, bind, prototype, AbstractConstructor } from "../declare"; | |
| import { DjxWidgetBase } from "../tsx/DjxWidgetBase"; | |||
|
|
r89 | import { createElement, on } from "../tsx"; | |
|
|
r65 | ||
| interface MyWidgetAttrs { | |||
| title: string; | |||
| counter: number; | |||
| } | |||
| interface MyWidgetEvents { | |||
|
|
r71 | "count-inc": Event & { | |
| detail: number; | |||
| }; | |||
|
|
r65 | ||
|
|
r71 | "count-dec": Event & { | |
| detail: number; | |||
| }; | |||
|
|
r65 | } | |
| @djclass | |||
| export class MyWidget extends djbase(DjxWidgetBase as AbstractConstructor<DjxWidgetBase<MyWidgetAttrs, MyWidgetEvents>>) { | |||
| @bind({ node: "titleNode", type: "innerHTML" }) | |||
| title = ""; | |||
| @prototype() | |||
| counter = 0; | |||
| render() { | |||
|
|
r96 | const Frame = ({children, ref}: {ref: JSX.Ref<HTMLDivElement>, children: any[]}) => <div ref={ref} >{children}</div>; | |
|
|
r65 | return <div className="myWidget" onsubmit={e => this._onSubmit(e)} tabIndex={3} style={{ alignContent: "center", border: "1px solid" }} > | |
| <h1 data-dojo-attach-point="titleNode"></h1> | |||
|
|
r96 | <Frame ref={ v => {}}> | |
|
|
r65 | <span class="up-button" onclick={e => this._onIncClick(e)}>[+]</span> | |
| <span class="down-button" onclick={() => this._onDecClick()}>[-]</span> | |||
| </Frame> | |||
| </div>; | |||
| } | |||
|
|
r72 | postCreate() { | |
| super.postCreate(); | |||
| this.on("click", () => {}); | |||
| } | |||
|
|
r65 | _onSubmit(e: Event) { | |
| } | |||
| _onIncClick(e: MouseEvent) { | |||
|
|
r72 | this.set("counter", this.counter + 1); | |
|
|
r71 | ||
|
|
r65 | this.emit("count-inc", { bubbles: false }); | |
| } | |||
| _onDecClick() { | |||
|
|
r71 | this.emit("count-dec", { bubbles: false, detail: this.counter }); | |
|
|
r65 | } | |
|
|
r72 | ||
| @on("count-inc") | |||
|
|
r93 | private _onCounterInc(evt: Event & { detail: number; x?: number; }) { | |
|
|
r73 | } | |
|
|
r85 | @on("click", "keydown") | |
| protected _onClick(event: MouseEvent | KeyboardEvent) { | |||
|
|
r72 | ||
| } | |||
|
|
r73 | } |
