diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..5a76c3bba4a --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,37 @@ +import { Component, useState } from "@odoo/owl"; + +export class Card extends Component { + static template = "awesome_owl.card"; + static props = { + id: Number, + title: String, + isCrossedOut: Boolean, + toggleState: { + Function, optional: true + }, + removeTodo: { + Function, optional: true + }, + slots: Object + } + + setup() { + this.state = useState({ + isCrossed: this.props.isCrossedOut, + isOpen: false + }) + } + + toggleState(event) { + this.state.isCrossed = !this.state.isCrossed; + this.props.toggleState(this.props.id); + } + + removeTodo(event) { + this.props.removeTodo(this.props.id); + } + + toggleCard(event) { + this.state.isOpen = !this.state.isOpen + } +} \ No newline at end of file diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..f1e6da548aa --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,16 @@ + + + +
+
+ +
+

+ + +

+ +
+
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..f09b6a02600 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,17 @@ +import { Component, useState } from "@odoo/owl"; + +export class Counter extends Component { + static template = "awesome_owl.counter"; + static props = { + onChange: { Function, optional: true } + } + + setup() { + this.state = useState({ value: 0 }); + } + + increment() { + this.state.value++ + this.props.onChange(); + } +} \ No newline at end of file diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 00000000000..2dcead84b89 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,10 @@ + + + +

+ Counter: +

+ +
+ +
\ No newline at end of file diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 4ac769b0aa5..d94b9eda163 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,5 +1,18 @@ -import { Component } from "@odoo/owl"; +import { Component, useState, markup } from "@odoo/owl"; +import { Counter } from "./counter/counter"; +import { TodoList } from "./todo_list/todo_list"; export class Playground extends Component { static template = "awesome_owl.playground"; -} + static components = { Counter, TodoList } + + content = markup("
some texte 2
") + + setup() { + this.sum = useState({ value: 0 }); + } + + incrementSum() { + this.sum.value++ + } +} \ No newline at end of file diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..474365bc200 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,10 +1,14 @@ - + -
hello world
+ + +
+ Total count : +
+
- -
+ \ No newline at end of file diff --git a/awesome_owl/static/src/todo_item/todo_item.js b/awesome_owl/static/src/todo_item/todo_item.js new file mode 100644 index 00000000000..48f4766a025 --- /dev/null +++ b/awesome_owl/static/src/todo_item/todo_item.js @@ -0,0 +1,28 @@ +import { Component, useState } from "@odoo/owl"; +import { Card } from "../card/card" + +export class TodoItem extends Component { + static template = "awesome_owl.todo_item"; + static components = { Card } + static props = { + todo: { + type: Object, + shape: { + id: Number, + description: String, + isCompleted: Boolean + } + }, + removeTodo: { + Function, optional: true + } + } + + toggleState(id) { + + } + + removeTodo(id) { + this.props.removeTodo(id); + } +} \ No newline at end of file diff --git a/awesome_owl/static/src/todo_item/todo_item.xml b/awesome_owl/static/src/todo_item/todo_item.xml new file mode 100644 index 00000000000..8941c2c055d --- /dev/null +++ b/awesome_owl/static/src/todo_item/todo_item.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/awesome_owl/static/src/todo_list/todo_list.js b/awesome_owl/static/src/todo_list/todo_list.js new file mode 100644 index 00000000000..84b022173b3 --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_list.js @@ -0,0 +1,38 @@ +import { Component, useState, useRef, onMounted } from "@odoo/owl"; +import { TodoItem } from "../todo_item/todo_item" + +export class TodoList extends Component { + static template = "awesome_owl.todo_list"; + static components = { TodoItem } + + setup() { + this.todos = useState([]); + this.state = useState({ + inputValue: "" + }); + this.inputTodo = useRef('inputTodo'); + onMounted(() => { + this.inputTodo.el.focus() + }) + } + + addTodo(event) { + if (event.keyCode !== 13 | this.state.inputValue === "") return; + + this.todos.push({ + id: this.todos.length, + description: this.state.inputValue, + isCompleted: false + }) + + this.state.inputValue = ""; + + } + + removeTodo(id) { + const idx = this.todos.findIndex(todo => todo.id === id) + if (idx !== -1) { + this.todos.splice(idx, 1) + } + } +} \ No newline at end of file diff --git a/awesome_owl/static/src/todo_list/todo_list.xml b/awesome_owl/static/src/todo_list/todo_list.xml new file mode 100644 index 00000000000..3219dd73668 --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_list.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file