File tree Expand file tree Collapse file tree 9 files changed +81
-10
lines changed Expand file tree Collapse file tree 9 files changed +81
-10
lines changed Original file line number Diff line number Diff line change 11import { Component } from "@odoo/owl" ;
22
3+
34export class Card extends Component {
45 static template = "awesome_owl.Card" ;
56 static props = {
Original file line number Diff line number Diff line change 11import { Component , useState } from "@odoo/owl" ;
22
3+
34export class Counter extends Component {
45 static template = "awesome_owl.Counter" ;
56
@@ -16,7 +17,14 @@ export class Counter extends Component {
1617 increment ( ) {
1718 this . state . value ++ ;
1819 if ( this . props . onChange ) {
19- this . props . onChange ( this . state . value ) ;
20+ this . props . onChange ( this . state . value , true ) ;
21+ }
22+ }
23+
24+ decrement ( ) {
25+ this . state . value -- ;
26+ if ( this . props . onChange ) {
27+ this . props . onChange ( this . state . value , false ) ;
2028 }
2129 }
2230}
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.Counter" >
4- <div style =" border: 3px solid #ccc; display: inline-block; min-width: 300px; padding: 20px; margin: 20px" >
4+ <div style =" background-color: #FFFFE0; border: 3px solid #ccc; display: inline-block; min-width: 300px; padding: 20px; margin: 20px" >
55 <p >Counter: <t t-esc =" state.value" /></p >
66 <button style =" background: purple; color: white; padding: 8px; border-radius: 5px; border: 0;" class =" btn btn-primary" t-on-click =" increment" >
77 Increment
88 </button >
9+ <button style =" background: purple; color: white; padding: 8px; border-radius: 5px; border: 0; margin:5px" class =" btn btn-primary" t-on-click =" decrement" >
10+ Decrement
11+ </button >
912 </div >
1013 </t >
1114</templates >
Original file line number Diff line number Diff line change 11import { Component , useState } from "@odoo/owl" ;
22import { Counter } from "./counter/counter" ;
33import { Card } from "./card/card" ;
4+ import { TodoList } from "./todo/todo_list" ;
5+
46
57export class Playground extends Component {
6- static template = "awesome_owl.Playground " ;
7- static components = { Counter, Card } ;
8+ static template = "awesome_owl.playground " ;
9+ static components = { Counter, Card, TodoList } ;
810
911 setup ( ) {
1012 this . state = useState ( {
1113 sum : 0 ,
1214 } ) ;
1315 }
1416
15- incrementSum ( newValue ) {
16- this . state . sum ++ ;
17+ incrementSum ( newVal , Checker ) {
18+ if ( Checker )
19+ this . state . sum ++ ;
20+ else
21+ this . state . sum -- ;
1722 }
1823}
Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" UTF-8" ?>
22<templates xml : space =" preserve" >
3- <t t-name =" awesome_owl.Playground " >
3+ <t t-name =" awesome_owl.playground " >
44 <Counter onChange.bind=" incrementSum" />
55 <Counter onChange.bind=" incrementSum" />
66 <Counter onChange.bind=" incrementSum" />
7- <h3 style =" border: 3px solid #ccc; margin: 20px; padding: 20px" >Sum of Counters: <t t-esc =" state.sum" /></h3 >
8- <Card title =" 'This is title1'" content =" 'Hello from card1'" />
9- <Card title =" 'This is title2'" content =" 'Hello from card2'" />
7+ <h3 style =" background-color: #90EE90; border: 3px solid #ccc; margin: 20px; padding: 20px" >Sum of Counters: <t t-esc =" state.sum" /></h3 >
8+ <TodoList />
109 </t >
1110</templates >
Original file line number Diff line number Diff line change 1+ import { Component } from "@odoo/owl" ;
2+
3+
4+ export class TodoItem extends Component {
5+ static template = "awesome_owl.TodoItem" ;
6+
7+ static props = {
8+ todo : Object ,
9+ } ;
10+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <templates xml : space =" preserve" >
3+ <t t-name =" awesome_owl.TodoItem" >
4+ <div class =" p-1" t-att-class =" props.todo.isCompleted ? 'text-muted text-decoration-line-through' : ''" >
5+ <span t-esc =" props.todo.id" /> -
6+ <span t-esc =" props.todo.description" />
7+ </div >
8+ </t >
9+ </templates >
Original file line number Diff line number Diff line change 1+ import { Component , useState } from "@odoo/owl" ;
2+ import { TodoItem } from "./todo_item" ;
3+
4+
5+ export class TodoList extends Component {
6+ static template = "awesome_owl.TodoList" ;
7+
8+ static components = { TodoItem } ;
9+
10+ setup ( ) {
11+ this . todos = useState ( [ ] )
12+ }
13+
14+ addTodo ( ev ) {
15+ if ( ev . keyCode == '13' ) {
16+ this . todos . push ( {
17+ id : this . todos . length + 1 ,
18+ description : ev . target . value ,
19+ isCompleted : false
20+ } )
21+ ev . target . value = ''
22+ }
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <templates xml : space =" preserve" >
3+ <t t-name =" awesome_owl.TodoList" >
4+ <div style =" background-color: #ADD8E6; border: 3px solid #ccc; display: inline-block; min-width: 300px; padding: 20px; margin: 20px" >
5+ <h3 >Todo List</h3 >
6+ <input type =" text" placeholder =" Enter a new task" t-on-keyup =" addTodo" class =" form-control mb-2" />
7+ <div t-foreach =" todos" t-as =" todo" t-key =" todo.id" >
8+ <TodoItem todo =" todo" />
9+ </div >
10+ </div >
11+ </t >
12+ </templates >
You can’t perform that action at this time.
0 commit comments