mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[ADD] tools: add single file component example to playground
This commit is contained in:
@@ -1811,6 +1811,49 @@ const WMS_CSS = `body {
|
||||
font-size: 20px;
|
||||
}`;
|
||||
|
||||
const SFC = `// This example illustrates how Owl enables single file components,
|
||||
// which include code, template and style.
|
||||
//
|
||||
// This is very useful in some situations, such as testing or quick prototyping.
|
||||
// Note that this example has no external xml or css file, everything is
|
||||
// contained in a single js file.
|
||||
|
||||
const { Component, useState, tags } = owl;
|
||||
const { xml, css } = tags;
|
||||
|
||||
// Counter component
|
||||
const COUNTER_TEMPLATE = xml\`
|
||||
<button t-on-click="state.value++">
|
||||
Click! [<t t-esc="state.value"/>]
|
||||
</button>\`;
|
||||
|
||||
const COUNTER_STYLE = css\`
|
||||
button {
|
||||
color: blue;
|
||||
}\`;
|
||||
|
||||
class Counter extends Component {
|
||||
state = useState({ value: 0})
|
||||
}
|
||||
Counter.template = COUNTER_TEMPLATE;
|
||||
Counter.style = COUNTER_STYLE;
|
||||
|
||||
// App
|
||||
const APP_TEMPLATE = xml\`
|
||||
<div>
|
||||
<Counter/>
|
||||
<Counter/>
|
||||
</div>\`;
|
||||
|
||||
class App extends Component {}
|
||||
App.template = APP_TEMPLATE;
|
||||
App.components = { Counter };
|
||||
|
||||
// Application setup
|
||||
const app = new App();
|
||||
app.mount(document.body);
|
||||
`;
|
||||
|
||||
export const SAMPLES = [
|
||||
{
|
||||
description: "Components",
|
||||
@@ -1823,6 +1866,10 @@ export const SAMPLES = [
|
||||
code: FORM,
|
||||
xml: FORM_XML
|
||||
},
|
||||
{
|
||||
description: "Single File Components",
|
||||
code: SFC
|
||||
},
|
||||
{
|
||||
description: "Animations",
|
||||
code: ANIMATION,
|
||||
|
||||
Reference in New Issue
Block a user