Change the theme at runtime
Toggle dark/light, push a brand palette, or patch single tokens — all from your own button.
Three ways to update the theme from your own code, in order of permanence: full theme swap, partial token patch, store-level override.
Quick example
How it works
handle.setTheme(theme) swaps the entire theme record; this is what
the top-bar moon/sun toggle calls under the hood. Persists the new
mode to localStorage.
handle.patchTheme({ ... }) overlays just the keys you specify on
top of the active theme. Resets on reload.
useThemeStore.setOverride(key, value) writes a single override into
persisted state — survives reload, applied on every theme swap.
Variations
Brand palette (one button)
React to system color-scheme changes
API
| Method | From | Persistence |
|---|---|---|
handle.setTheme(theme) | @elitechart/elitechart | sets mode |
handle.patchTheme(patch) | – | session only |
useThemeStore.setOverride(k, v) | – | persisted |
useThemeStore.resetAll() | – | clears overrides |