55 lines
1.2 KiB
HTML
55 lines
1.2 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>WC demo</title>
|
|
<style>
|
|
* {
|
|
font-size: larger;
|
|
}
|
|
</style>
|
|
<script type="module">
|
|
import {
|
|
WebComponent,
|
|
html,
|
|
} from "https://unpkg.com/web-component-base@latest/index.js";
|
|
|
|
export class Counter extends WebComponent {
|
|
static props = {
|
|
count: 0,
|
|
};
|
|
get template() {
|
|
return html`<button onClick=${() => ++this.props.count}>
|
|
${this.props.count}
|
|
</button>`;
|
|
}
|
|
}
|
|
|
|
class Toggle extends WebComponent {
|
|
static props = {
|
|
toggle: false,
|
|
};
|
|
onInit() {
|
|
this.onclick = () => (this.props.toggle = !this.props.toggle);
|
|
}
|
|
get template() {
|
|
return `<button>${this.props.toggle ? "On" : "Off"}</button>`;
|
|
}
|
|
}
|
|
|
|
customElements.define("my-counter", Counter);
|
|
customElements.define("my-toggle", Toggle);
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div>
|
|
Counter:
|
|
<my-counter />
|
|
</div>
|
|
<div>
|
|
Toggle:
|
|
<my-toggle />
|
|
</div>
|
|
</body>
|
|
</html>
|