Skip to content

Commit b48fa58

Browse files
committed
[IMP] awesome_owl: Chapter 1 - Intro Owl Components
1 parent f1448b2 commit b48fa58

File tree

13 files changed

+225
-4
lines changed

13 files changed

+225
-4
lines changed

awesome_owl/__manifest__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@
2929
'assets': {
3030
'awesome_owl.assets_playground': [
3131
('include', 'web._assets_helpers'),
32+
('include', 'web._assets_frontend_helpers'),
3233
'web/static/src/scss/pre_variables.scss',
3334
'web/static/lib/bootstrap/scss/_variables.scss',
34-
('include', 'web._assets_bootstrap'),
35-
('include', 'web._assets_core'),
35+
'web/static/lib/bootstrap/scss/_variables-dark.scss',
36+
'web/static/lib/bootstrap/scss/_maps.scss',
37+
('include', 'web._assets_bootstrap_frontend'),
3638
'web/static/src/libs/fontawesome/css/font-awesome.css',
39+
'web/static/src/scss/fontawesome_overridden.scss',
40+
('include', 'web._assets_core'),
3741
'awesome_owl/static/src/**/*',
3842
],
3943
},
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Component, useState } from "@odoo/owl";
2+
3+
4+
export class Card extends Component {
5+
static template = "awesome_owl.card";
6+
static props = {
7+
title: String,
8+
slots: {
9+
type: Object,
10+
optional: true,
11+
},
12+
};
13+
14+
setup() {
15+
this.state = useState({ isToggled: false });
16+
}
17+
18+
toggle() {
19+
this.state.isToggled = !this.state.isToggled;
20+
}
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="awesome_owl.card">
5+
<div class="card d-inline-block m-2" style="width: 18rem;">
6+
<div class="card-body">
7+
<h5 class="card-title"><t t-out="props.title"/><button class="btn btn-secondary" style="margin-left: 10px" t-on-click="toggle">Toggle</button></h5>
8+
<div class="card-text" t-if="this.state.isToggled">
9+
<t t-slot="default"/>
10+
</div>
11+
</div>
12+
</div>
13+
</t>
14+
15+
</templates>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Component, useState } from "@odoo/owl";
2+
3+
4+
export class Counter extends Component {
5+
static template = "awesome_owl.counter";
6+
static defaultProps = {
7+
buttonText: "Increment",
8+
}
9+
static props = {
10+
buttonText: { type: String, optional: true, },
11+
onChange: { type: Function, optional: true },
12+
};
13+
14+
setup() {
15+
this.state = useState({ value: 1 });
16+
}
17+
18+
increment() {
19+
this.state.value++;
20+
if (this.props.onChange) {
21+
this.props.onChange();
22+
}
23+
}
24+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="awesome_owl.counter">
5+
<div>
6+
Counter: <t t-esc="state.value"/>
7+
<button class="btn btn-primary" t-on-click="increment" style="margin-left: 5px">
8+
<t t-out="props.buttonText"/>
9+
</button>
10+
</div>
11+
</t>
12+
13+
</templates>
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
import { Component } from "@odoo/owl";
1+
import { Component, useState } from "@odoo/owl";
2+
import { Counter } from "./counter/counter";
3+
import { Card } from "./card/card";
4+
import { TodoList } from "./todo/todolist"
5+
26

37
export class Playground extends Component {
48
static template = "awesome_owl.playground";
9+
10+
static components = { Counter, Card, TodoList };
11+
12+
setup() {
13+
this.state = useState({ value : 2 });
14+
}
15+
16+
incrementSum() {
17+
this.state.value++;
18+
}
519
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.chapter_tuto {
2+
border: solid; padding: 10px; border-radius: 5px; margin-bottom: 5px
3+
}

awesome_owl/static/src/playground.xml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,29 @@
22
<templates xml:space="preserve">
33

44
<t t-name="awesome_owl.playground">
5-
<div class="p-3">
5+
<div class="p-3 chapter_tuto">
66
hello world
77
</div>
8+
9+
<div class="chapter_tuto">
10+
<Counter onChange.bind="incrementSum" t-props="{'buttonText': 'Custom Incr.'}"/>
11+
<Counter onChange.bind="incrementSum"/>
12+
<p>The sum id: <t t-esc="state.value"/></p>
13+
</div>
14+
15+
<div class="chapter_tuto">
16+
<Card t-props="{'title': 'Card 1'}">
17+
<p>Some content</p>
18+
</Card>
19+
20+
<Card t-props="{'title': 'Card 2'}">
21+
<Counter/>
22+
</Card>
23+
</div>
24+
25+
<div class="chapter_tuto">
26+
<TodoList/>
27+
</div>
828
</t>
929

1030
</templates>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Component } from "@odoo/owl";
2+
3+
4+
export class TodoItem extends Component {
5+
static template = "awesome_owl.todoitem";
6+
static props = {
7+
id: Number,
8+
description: String,
9+
isCompleted: Boolean,
10+
onToggle: {
11+
Function,
12+
optional: true,
13+
},
14+
onClick: {
15+
Function,
16+
optional: true,
17+
},
18+
};
19+
20+
toggleState() {
21+
this.props.onToggle(this.props.id);
22+
}
23+
24+
removeTodo() {
25+
this.props.onClick(this.props.id);
26+
}
27+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="awesome_owl.todoitem">
5+
<p t-att-class="{'text-muted': props.isCompleted, 'text-decoration-line-through': props.isCompleted}">
6+
<input type="checkbox" style="margin-right: 10px" t-att-checked="props.isCompleted" t-on-change="toggleState"/>
7+
<t t-out="props.id"/>.
8+
<t t-out="props.description"/>
9+
<span class="fa fa-remove text-danger" t-on-click="removeTodo"/>
10+
</p>
11+
</t>
12+
13+
</templates>

0 commit comments

Comments
 (0)