Files
owl/web/static/src/ts/widgets/Counter.ts
T

28 lines
667 B
TypeScript
Raw Normal View History

2019-01-23 11:12:54 +01:00
import Widget from "../core/widget";
2019-01-23 14:28:41 +01:00
import { Env } from "../env";
2019-01-16 13:19:58 +01:00
const template = `
2019-01-21 15:46:29 +01:00
<div>
2019-01-16 13:19:58 +01:00
<button t-on-click="increment(-1)">-</button>
2019-01-21 14:38:44 +01:00
<span style="font-weight:bold">Value: <t t-esc="state.counter"/></span>
2019-01-16 13:19:58 +01:00
<button t-on-click="increment(1)">+</button>
</div>
`;
2019-01-23 11:12:54 +01:00
export default class Counter extends Widget<Env> {
2019-01-16 13:19:58 +01:00
name = "counter";
template = template;
state = {
counter: 0
};
2019-01-23 11:12:54 +01:00
constructor(parent: Widget<Env>, props: {initialState?: number}) {
2019-01-16 13:19:58 +01:00
super(parent);
2019-01-17 12:49:13 +01:00
this.state.counter = props.initialState || 0;
2019-01-16 13:19:58 +01:00
}
increment(delta: number) {
this.updateState({ counter: this.state.counter + delta });
}
}