chore: update examples

This commit is contained in:
Ayo 2023-09-16 23:08:52 +02:00
parent 2b306b5dde
commit f2409ab545
3 changed files with 7 additions and 21 deletions

View file

@ -21,7 +21,7 @@ export class HelloWorld extends WebComponent {
this.emotion === 'sad' this.emotion === 'sad'
? '. 😭' ? '. 😭'
: '! 🙌' : '! 🙌'
}</h1> }</h1>`
} }
} }
``` ```
@ -38,4 +38,4 @@ Then changes in the attributes observed will cause the UI to render.
</script> </script>
``` ```
![UI showing feeling toward Web Components changing from SAD to EXCITED](./assets/wc-feeling.gif) <img alt="UI showing feeling toward Web Components changing from SAD to EXCITED" src="./assets/wc-base-demo.gif" width="250" />

BIN
assets/wc-base-demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

View file

@ -1,34 +1,20 @@
// @ts-check // @ts-check
import { WebComponent } from "./WebComponent.mjs"; import { WebComponent } from "./WebComponent.mjs";
const emotionPostfix = {
excited: "!",
sad: " :(",
};
const emotionColor = {
excited: "green",
sad: "red",
};
/**
* Component to greet a person
* and display sentiment toward web components
*/
export class HelloWorld extends WebComponent { export class HelloWorld extends WebComponent {
name = "World"; name = "World";
emotion = "excited"; emotion = "excited";
static get observedAttributes() { static get observedAttributes() {
return ["name", "emotion"]; return ["name", "emotion"];
} }
get template() { get template() {
return ` return `
<h1>Hello ${this.name}${emotionPostfix[this.emotion]}</h1> <h1>Hello ${this.name}${
<h2>How do you feel about web components: this.emotion === 'sad'
<span style="color:${emotionColor[this.emotion]}"> ? '. 😭'
${this.emotion.toUpperCase()} : '! 🙌'
</span> }</h1>`
</h2>`;
} }
} }