1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2025-01-18 07:23:15 +01:00

🔤 introduction example (#24)

This commit is contained in:
Jan Andrle 2024-12-13 15:49:54 +01:00 committed by GitHub
parent eef4e8dfa6
commit 091546aaab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,36 @@
import { el, on } from "deka-dom-el";
import { S } from "deka-dom-el/signals";
document.body.append(
el(HelloWorldComponent, { initial: "🚀" })
);
/** @typedef {"🎉" | "🚀"} Emoji */
/** @param {{ initial: Emoji }} attrs */
function HelloWorldComponent({ initial }){
const clicks= S(0);
const emoji= S(initial);
/** @param {HTMLOptionElement} el */
const isSelected= el=> (el.selected= el.value===initial);
// @ts-expect-error 2339: The <select> has only two options with {@link Emoji}
const onChange= on("change", event=> emoji(event.target.value));
return el().append(
el("p", {
textContent: S(() => `Hello World ${emoji().repeat(clicks())}`),
className: "example",
ariaLive: "polite", //OR ariaset: { live: "polite" },
dataset: { example: "Example" }, //OR dataExample: "Example",
}),
el("button",
{ textContent: "Fire", type: "button" },
on("click", ()=> clicks(clicks() + 1)),
on("keyup", ()=> clicks(clicks() - 2)),
),
el("select", null, onChange).append(
el(OptionComponent, "🎉", isSelected),//OR { textContent: "🎉" }
el(OptionComponent, "🚀", isSelected),//OR { textContent: "🚀" }
)
);
}
function OptionComponent({ textContent }){
return el("option", { value: textContent, textContent })
}