ThemeModeSwitch
Overview
SThemeModeSwitch is a context-bound toggle bound to the active SConfigProvider theme. It reflects the current effective scheme (so an auto preference shows the OS-resolved light/dark state) and pins an explicit light / dark preference when toggled. Use it as a quick, compact light/dark switch in a header or toolbar.
Usage
Features
- 🌓 Reflects the effective scheme — with
auto, the thumb tracks the OSprefers-color-scheme - 🎚 Pins an explicit preference on toggle, overriding any
autoresolution - 🎨 Inherits
sizeandcolorfrom the theme, with a sun/moon icon by default - ♿ Forwards an accessible label to the
role="switch"control (axe-clean) - 🧩
showIcontoggles the sun/moon glyph
Demos
Basic
API
Aria Layer
1ThemeModeSwitch
Props
| Prop | Type | Default | Description |
|---|---|---|---|
size | ThemeSize | 'md' | Visual size of the switch. |
color | ThemeColor | 'accent' | Theme color of the switch track. |
showIcon | boolean | true | Whether to render a sun/moon icon inside the switch thumb. |
aria-label | string | 'Toggle color scheme' | Accessible label for the switch control. |
Notes
Scope
SThemeModeSwitch is a theme-layer component that operates directly on the theme context from a parent SConfigProvider. It does not accept a modelValue; state is owned by the provider and shared across all theme components. To select auto (which a binary switch cannot express), pair it with SThemeModeSelect.
Cautions
- The component must be rendered inside a
SConfigProviderthat provides the theme context, otherwiseuseThemethrows. - Toggling a switch that is currently following
autopins an explicitlight/darkpreference; useSThemeModeSelectto return toauto.