Skip to content

Commit 22e9d19

Browse files
committed
[IMP] awesome_owl, awesome_dashboard: implement cards with slots and minimize card content using toggle button. create dashboard using layout component.
- Transform the Card component to use a default slot instead of a content prop, include multiple cards with arbitrary content (e.g., Counter), and enforce prop validation for the title. - Add toggle functionality to the Card component using a boolean state, conditionally render its content with t-if, and include a header button to switch between open and closed states. - Imported layout component in dashboard and added dashboard.scss to create a basic dasboard view.
1 parent 4a0880f commit 22e9d19

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
lines changed

awesome_dashboard/static/src/dashboard.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import { Component } from "@odoo/owl";
44
import { registry } from "@web/core/registry";
5+
import { Layout } from "@web/search/layout";
56

67
class AwesomeDashboard extends Component {
78
static template = "awesome_dashboard.AwesomeDashboard";
9+
static components = { Layout };
810
}
911

1012
registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.o_dashboard {
2+
background-color: white;
3+
}

awesome_dashboard/static/src/dashboard.xml

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

44
<t t-name="awesome_dashboard.AwesomeDashboard">
5-
hello dashboard
5+
<Layout className="'o_dashboard h-100'"/>
66
</t>
77

88
</templates>

awesome_owl/static/src/card/card.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
import { Component } from "@odoo/owl";
1+
import { Component, useState } from "@odoo/owl";
22

33
export class Card extends Component {
44
static template = "awesome_owl.Card"
55
static props = {
66
title: {
77
type: String,
88
},
9-
content: {
10-
type: String,
11-
}
9+
slots: {
10+
type: Object,
11+
},
12+
}
13+
14+
setup() {
15+
this.state = useState({ isCardOpen: false })
16+
}
17+
18+
toggleCard() {
19+
this.state.isCardOpen = !this.state.isCardOpen;
1220
}
1321
}

awesome_owl/static/src/card/card.xml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
<t t-name="awesome_owl.Card">
44
<div class="card d-inline-block m-2" style="width: 18rem;">
55
<div class="card-body">
6-
<h5 class="card-title">
7-
<t t-esc="props.title"/>
8-
</h5>
9-
<p class="card-text">
10-
<t t-out="props.content"/>
11-
</p>
6+
<div class="d-flex align-items-center" style="justify-content: space-between;">
7+
<h5 class="card-title mb-0">
8+
<t t-esc="props.title"/>
9+
</h5>
10+
<button class="btn btn-primary text-black" style="background: #e7e9ed;" t-on-click="toggleCard">Toggle</button>
11+
</div>
12+
<t t-if="state.isCardOpen">
13+
<t t-slot="default"/>
14+
</t>
1215
</div>
1316
</div>
1417
</t>

awesome_owl/static/src/playground.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,17 @@
1515
<div class="p-3 border m-5" style="max-width: fit-content;">
1616
<h1>Cards</h1>
1717
<div class="d-flex gap-3">
18-
<Card title="'Gandhinagar'" content="html"/>
19-
<Card title="'Ahmedabad'" content="markup_html"/>
18+
<Card title="'Gandhinagar'">
19+
<p class="card-text">Using Slot for card 1</p>
20+
</Card>
21+
<Card title="'Ahmedabad'">
22+
<p class="card-text">
23+
<t t-out="markup_html"/>
24+
</p>
25+
</Card>
26+
<Card title="'Counter Card'">
27+
<Counter title="'Counter 3'" onChange.bind="incrementSum"/>
28+
</Card>
2029
</div>
2130
</div>
2231
</div>

0 commit comments

Comments
 (0)