Problem Statement
Users need light and dark mode options for comfortable viewing during extended monitoring sessions. Implement a theme system with CSS custom properties, automatic system preference detection (prefers-color-scheme), manual toggle, and persistent preference stored in localStorage.
Technical Bounds
- Theme tokens: 60+ CSS custom properties (colors, spacing, shadows, border-radius).
- System preference: read
prefers-color-scheme on mount; update on change via matchMedia listener.
- Toggle: navbar button cycling system -> light -> dark.
- Persistence:
localStorage.setItem('theme', 'light'|'dark'|'system').
- Transition: smooth color transitions (
transition: background-color 0.3s, color 0.3s).
- Charts: Lightweight Charts theme sync with current mode.
Steps
- Define CSS custom properties in
:root (light) and [data-theme="dark"] selectors.
- Implement
ThemeProvider context with useTheme() returning (theme, setTheme, resolvedTheme).
- On mount, read localStorage; fallback to
prefers-color-scheme; apply data-theme attribute.
- Build
ThemeToggle button with sun/moon/monitor icons.
- Migrate all component styles to use
var(--color-*) tokens.
- Sync chart theme on mode change via
chart.applyOptions().
Problem Statement
Users need light and dark mode options for comfortable viewing during extended monitoring sessions. Implement a theme system with CSS custom properties, automatic system preference detection (
prefers-color-scheme), manual toggle, and persistent preference stored in localStorage.Technical Bounds
prefers-color-schemeon mount; update on change viamatchMedialistener.localStorage.setItem('theme', 'light'|'dark'|'system').transition: background-color 0.3s, color 0.3s).Steps
:root(light) and[data-theme="dark"]selectors.ThemeProvidercontext withuseTheme()returning(theme, setTheme, resolvedTheme).prefers-color-scheme; applydata-themeattribute.ThemeTogglebutton with sun/moon/monitor icons.var(--color-*)tokens.chart.applyOptions().