mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
add color widget in discuss
This commit is contained in:
@@ -9,6 +9,7 @@ const template = `
|
|||||||
<button t-on-click="resetCounter">Reset first counter</button>
|
<button t-on-click="resetCounter">Reset first counter</button>
|
||||||
<button t-on-click="resetCounterAsync">Reset counter 2 in 3s</button>
|
<button t-on-click="resetCounterAsync">Reset counter 2 in 3s</button>
|
||||||
<button t-on-click="toggle">Toggle Clock/counters</button>
|
<button t-on-click="toggle">Toggle Clock/counters</button>
|
||||||
|
<button t-on-click="toggleColor">Toggle Color</button>
|
||||||
<button t-on-click="updateState({})">Rerender this widget</button>
|
<button t-on-click="updateState({})">Rerender this widget</button>
|
||||||
<input/>
|
<input/>
|
||||||
<t t-if="state.validcounter">
|
<t t-if="state.validcounter">
|
||||||
@@ -18,15 +19,15 @@ const template = `
|
|||||||
<t t-else="1">
|
<t t-else="1">
|
||||||
<t t-widget="Clock"/>
|
<t t-widget="Clock"/>
|
||||||
</t>
|
</t>
|
||||||
<div ref="target"/>
|
<t t-widget="ColorWidget" t-props="{color: state.color}"/>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export class Discuss extends Widget<Env> {
|
export class Discuss extends Widget<Env> {
|
||||||
name = "discuss";
|
name = "discuss";
|
||||||
template = template;
|
template = template;
|
||||||
widgets = { Clock, Counter };
|
widgets = { Clock, Counter, ColorWidget };
|
||||||
state = { validcounter: true };
|
state = { validcounter: true, color: "red" };
|
||||||
|
|
||||||
mounted() {}
|
mounted() {}
|
||||||
resetCounter(ev: MouseEvent) {
|
resetCounter(ev: MouseEvent) {
|
||||||
@@ -46,4 +47,19 @@ export class Discuss extends Widget<Env> {
|
|||||||
toggle() {
|
toggle() {
|
||||||
this.updateState({ validcounter: !this.state.validcounter });
|
this.updateState({ validcounter: !this.state.validcounter });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleColor() {
|
||||||
|
const newColor = this.state.color === "red" ? "blue" : "red";
|
||||||
|
this.updateState({ color: newColor });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ColorWidget extends Widget<Env> {
|
||||||
|
name = "colorwidget";
|
||||||
|
template = `<div>Current Color: <t t-esc="state.color"/></div>`;
|
||||||
|
state: { color: "red" | "blue" };
|
||||||
|
constructor(parent: Widget<Env>, props: { color: "red" | "blue" }) {
|
||||||
|
super(parent);
|
||||||
|
this.state = { color: props.color };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user