File tree Expand file tree Collapse file tree 6 files changed +76
-34
lines changed
Expand file tree Collapse file tree 6 files changed +76
-34
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,9 @@ export class Card extends Component {
44 static template = "awesome_owl.card" ;
55 static props = {
66 title : String ,
7- content : String
7+ content : {
8+ type : String ,
9+ validate : c => c == "World"
10+ } ,
811 } ;
912}
Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" UTF-8" ?>
22<templates xml : space =" preserve" >
33 <t t-name =" awesome_owl.card" >
4- <div class =" card d-inline-block m-2" style =" width: 18rem; border: 2px solid black; border-radius: 12px; margin-top: 10px; text-align:center;" >
5- <div class =" card-body" >
6- <h4 class =" card-title" style =" background-color: blue; margin:0; border-radius:14px;" >
7- <t t-esc =" props.title" />
4+ <div class =" card d-inline-block m-2"
5+ style =" width: 18rem;
6+ border: 2px solid #444;
7+ border-radius: 16px;
8+ margin-top: 10px;
9+ text-align:center;" >
10+
11+ <div class =" card-body" style =" padding: 16px;" >
12+
13+ <h4 class =" card-title"
14+ style =" background-color: #4c6ef5;
15+ color: white;
16+ margin: 0;
17+ padding: 10px 0;
18+ border-radius: 12px;
19+ font-size: 1.2rem;" >
20+ <t t-out =" props.title" />
821 </h4 >
9- <p class =" card-text" style =" background-color: green; margin:10px; border-radius:14px;" >
10- <t t-esc =" props.content" />
22+
23+ <p class =" card-text"
24+ style =" background-color: #69db7c;
25+ color: black;
26+ margin: 12px 0 0 0;
27+ padding: 10px;
28+ border-radius: 12px;
29+ font-size: 1rem;" >
30+ <t t-out =" props.content" />
1131 </p >
32+
1233 </div >
1334 </div >
35+
1436 </t >
1537</templates >
Original file line number Diff line number Diff line change @@ -2,17 +2,25 @@ import { Component, useState } from "@odoo/owl";
22
33export class Counter extends Component {
44 static template = "awesome_owl.counter" ;
5-
5+ static props = {
6+ onChange : { type : Function , optional : true }
7+ }
68 setup ( ) {
79 this . state = useState ( { value : 0 } ) ;
810 }
911
1012 increment ( ) {
1113 this . state . value ++ ;
14+ if ( this . props . onChange ) {
15+ this . props . onChange ( 1 ) ;
16+ }
1217 }
1318
1419 decrement ( ) {
1520 this . state . value -- ;
21+ if ( this . props . onChange ) {
22+ this . props . onChange ( - 1 ) ;
23+ }
1624 }
1725
1826 reset ( ) {
Original file line number Diff line number Diff line change 22<templates xml : space =" preserve" >
33 <t t-name =" awesome_owl.counter" >
44 <div style =" border: 2px solid black; border-radius: 12px; width: fit-content; padding: 10px; margin-top:10px;" >
5- <p >Counter: <t t-esc =" state.value" /></p >
6- <button class =" btn btn-primary" t-on-click =" increment" >Increment</button >
7- <button class =" btn btn-primary" t-on-click =" decrement" >Decrement</button >
8- <button t-if =" state.value != 0" class =" btn btn-primary" t-on-click =" reset" >Reset</button >
5+ <p style =" font-weight: bold;" >Counter: <t t-esc =" state.value" /></p >
6+ <button
7+ t-on-click =" increment"
8+ style =" background:#6a5acd; color:white; border:none; padding:8px 18px; border-radius:8px; margin-right: 5px" >
9+ Increment
10+ </button >
11+ <button
12+ t-on-click =" decrement"
13+ style =" background:#6a5acd; color:white; border:none; padding:8px 18px; border-radius:8px; margin-right: 5px" >
14+ Decrement
15+ </button >
16+ <button
17+ t-if =" state.value != 0"
18+ t-on-click =" reset"
19+ style =" background:#6a5acd; color:white; border:none; padding:8px 18px; border-radius:8px;" >
20+ Reset
21+ </button >
922 </div >
1023 </t >
1124</templates >
Original file line number Diff line number Diff line change 1- import { Component , useState } from "@odoo/owl" ;
1+ import { markup , Component , useState } from "@odoo/owl" ;
22import { Counter } from "./counter/counter" ;
33import { Card } from "./card/card" ;
44
55export class Playground extends Component {
66 static template = "awesome_owl.playground" ;
7- static components = { Counter, Card} ;
7+ static components = { Counter, Card } ;
88
99 setup ( ) {
10- this . state = useState ( { value : 0 } ) ;
10+ this . state = useState ( {
11+ content : markup ( '<h1>Welcome to your custom dashboard editor!</h1>' ) ,
12+ sum : 0
13+ } ) ;
1114 }
1215
13- increment ( ) {
14- this . state . value ++ ;
15- }
16-
17- decrement ( ) {
18- this . state . value -- ;
19- }
20-
21- reset ( ) {
22- this . state . value = 0 ;
16+ calculateSum ( newValue ) {
17+ if ( newValue > 0 ) {
18+ this . state . sum ++ ;
19+ }
20+ if ( newValue < 0 ) {
21+ this . state . sum -- ;
22+ }
2323 }
2424}
Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" UTF-8" ?>
22<templates xml : space =" preserve" >
33 <t t-name =" awesome_owl.playground" >
4- <div style =" border: 2px solid black; border-radius: 12px; width: fit-content; padding: 10px; margin-top:5px;" >
5- <p >Counter: <t t-esc =" state.value" /></p >
6- <button class =" btn btn-primary" t-on-click =" increment" >Increment</button >
7- <button class =" btn btn-primary" t-on-click =" decrement" >Decrement</button >
8- <button t-if =" state.value != 0" class =" btn btn-primary" t-on-click =" reset" >Reset</button >
9- </div >
10- <Counter />
11- <Card title =" 'Hello'" content =" 'word'" />
12- <Card title =" 'New'" content =" 'Card'" />
4+ <Counter onChange.bind=" calculateSum" />
5+ <Counter onChange.bind=" calculateSum" />
6+ <Card title =" 'Hello'" content =" 'World'" />
7+ <t t-out =" this.state.content" />
8+ <p style =" font-weight: bold;" >Sum: <t t-esc =" state.sum" /></p >
139 </t >
1410</templates >
You can’t perform that action at this time.
0 commit comments