chore: better example with explanations

This commit is contained in:
Ayo 2023-11-12 16:06:47 +01:00
parent 859260f578
commit d3573ec5b2
2 changed files with 8 additions and 2 deletions

View file

@ -2,7 +2,7 @@
import WebComponent from "../src/index.js"; import WebComponent from "../src/index.js";
export class HelloWorld extends WebComponent { export class HelloWorld extends WebComponent {
name = "World"; dataName = "World";
emotion = "excited"; emotion = "excited";
static properties = ["data-name", "emotion"]; static properties = ["data-name", "emotion"];

View file

@ -8,11 +8,17 @@
* import WebComponent from "https://unpkg.com/web-component-base/index.js"; * import WebComponent from "https://unpkg.com/web-component-base/index.js";
* *
* class HelloWorld extends WebComponent { * class HelloWorld extends WebComponent {
* // initialize prop
* dataName = 'World';
*
* // tell the browser which attributes to cause a render
* static properties = ["data-name", "emotion"]; * static properties = ["data-name", "emotion"];
* *
* // give the component a readonly template
* // note: props have kebab-case & camelCase counterparts
* get template() { * get template() {
* return ` * return `
* <h1>Hello ${this.dataName || 'World'}${this.emotion === "sad" ? ". 😭" : "! 🙌"}</h1>`; * <h1>Hello ${this.dataName}${this.emotion === "sad" ? ". 😭" : "! 🙌"}</h1>`;
* } * }
* } * }
* *