Theme

stable 1.2 kB
<HkThemeService>

Reads, writes and persists the token layer at runtime. One class on the root element retunes every component, with no rebuild and no per-component theme prop.

#theming#service
In the package npm i hellskitchen-ui Import HkThemeService and use it directly.

Live demo

Running in this page — interact with it.

Inputs

NameTypeDefaultDescription
themeSignal<HkThemeMode>'dark'Current theme ('light' | 'dark'), readable as a signal.
storageKeystring'hk-theme'Property on the service: where the choice is remembered.
accentsreadonly HkAccent[]16 named presetsThe built-in palette, from Crimson through Slate (also exported as HK_ACCENTS). A shortcut, not the API — any CSS colour works.

Methods

  • toggle()() => void

    Flips between light and dark.

  • set(theme)(theme: 'light' | 'dark') => void

    Applies a theme and persists the choice.

  • setToken(name, value)(name: string, value: string) => void

    Overrides one token at runtime.

  • setAccent(colour)(colour: string) => void

    Writes --hk-accent. Every shade is derived from it with color-mix, so an accent is one value rather than a five-step ramp.

Theming

Component tokens, each falling back to a global one:

PropertyDefaultControls
--hk-accent#dc2626Primary accent every component derives from.
--hk-radius12pxCorner radius scale.
--hk-density1Padding multiplier.

Accessibility

  • Sets color-scheme alongside the class, so browser-drawn controls — dropdown popups, scrollbars, date pickers — are painted the right way round.
  • The stored choice wins over the OS preference; the OS only decides for a first-time visitor.
  • Apply the class before first paint with a small inline script in index.html, so a dark-mode visitor never sees a white flash.

More in Utility