feat(site): use vanilla-hello-world

This commit is contained in:
Ayo 2023-11-12 16:56:41 +01:00
parent 09e5418a3b
commit 0e178fda79
2 changed files with 19 additions and 1 deletions

View file

@ -0,0 +1,18 @@
class HelloWorld extends HTMLElement {
static get observedAttributes() {
return ["data-name"];
}
connectedCallback() {
let count = 0;
this.onclick = () => {
this.setAttribute("data-name", `Clicked ${++count}x`);
};
}
attributeChangedCallback(property, previousValue, currentValue) {
if (property === "data-name" && previousValue !== currentValue) {
this.innerHTML = `<button style="cursor:pointer">Hello ${currentValue}!</button>`;
}
}
}

View file

@ -22,7 +22,7 @@
<h2>Welcome to {{ name }}</h2> <h2>Welcome to {{ name }}</h2>
<p> <p>
Here's a vanilla custom element: Here's a vanilla custom element:
<my-hello-world data-name="{{name}}" /> <vanilla-hello-world data-name="{{name}}" />
</p> </p>
<code-block language="js"> <code-block language="js">
class HelloWorld extends HTMLElement { class HelloWorld extends HTMLElement {