diff options
| author | Josh Kingsley <josh@joshkingsley.me> | 2025-11-06 22:31:12 +0200 |
|---|---|---|
| committer | Josh Kingsley <josh@joshkingsley.me> | 2025-11-06 22:31:12 +0200 |
| commit | 6ea86b1b56aebbae7edeb37b01d7bf5cd145bf60 (patch) | |
| tree | bfd0178097a56087471543950caebed5f8280040 /web/src/components/toolbar | |
| parent | dad5b47f0bb480532043df8d488f5609f731b00d (diff) | |
feat(web): change subvisions
Diffstat (limited to 'web/src/components/toolbar')
| -rw-r--r-- | web/src/components/toolbar/index.css | 2 | ||||
| -rw-r--r-- | web/src/components/toolbar/index.ts | 62 |
2 files changed, 54 insertions, 10 deletions
diff --git a/web/src/components/toolbar/index.css b/web/src/components/toolbar/index.css index e082f7d..653c326 100644 --- a/web/src/components/toolbar/index.css +++ b/web/src/components/toolbar/index.css @@ -18,11 +18,13 @@ padding: 0 0.5rem; height: 1.25rem; color: white; + font-weight: 600; font-size: 0.75rem; } ntv-toolbar button:hover { background: var(--color-green-400); + color: var(--color-neutral-900); } ntv-toolbar button[data-icon] { diff --git a/web/src/components/toolbar/index.ts b/web/src/components/toolbar/index.ts index da4b69d..b8a383d 100644 --- a/web/src/components/toolbar/index.ts +++ b/web/src/components/toolbar/index.ts @@ -1,24 +1,66 @@ -import NotiveElement, { customElement } from "../../element"; -import h, { fragment } from "../../html"; +import NotiveElement, { customElement, eventHandler } from "../../element"; +import h from "../../html"; +import { minus16Icon, plus16Icon } from "../icons"; import "./index.css"; -@customElement("ntv-toolbar") -class NotiveToolbarElement extends NotiveElement { - connectedCallback() { - this.append(this.#view()); +export class SubdivisionsChangeEvent extends Event { + static readonly TYPE = "ntv:toolbar:subdivisionschange"; + + constructor(public subdivisions: number | undefined) { + super(SubdivisionsChangeEvent.TYPE); } +} +@customElement("ntv-toolbar") +class NotiveToolbarElement extends NotiveElement { #subdivisionsInputEl: HTMLInputElement = h.input({ title: "Subdivisions", disabled: true, }); - #view() { - return fragment( + get subdivisions(): number | undefined { + if (this.#subdivisionsInputEl.value === "") return; + return parseInt(this.#subdivisionsInputEl.value); + } + + set subdivisions(n: number | undefined) { + const m = n && Math.max(n, 1); + this.#subdivisionsInputEl.value = m === undefined ? "" : m.toString(); + } + + @eventHandler(SubdivisionsChangeEvent.TYPE) + onsubdivisionschange?: (event: SubdivisionsChangeEvent) => any; + + connectedCallback() { + this.append( h.section( - h.button({ dataset: { icon: "" } }, "-"), + h.button( + { + dataset: { icon: "" }, + onclick: () => { + if (!this.subdivisions) return; + this.subdivisions = this.subdivisions - 1; + this.dispatchEvent( + new SubdivisionsChangeEvent(this.subdivisions), + ); + }, + }, + h.span(minus16Icon()), + ), this.#subdivisionsInputEl, - h.button({ dataset: { icon: "" } }, "+"), + h.button( + { + dataset: { icon: "" }, + onclick: () => { + if (!this.subdivisions) return; + this.subdivisions = this.subdivisions + 1; + this.dispatchEvent( + new SubdivisionsChangeEvent(this.subdivisions), + ); + }, + }, + h.span(plus16Icon()), + ), ), h.section(h.button("Play")), ); |
