ThemeModeToggle
Overview
SThemeModeToggle is a context-bound cycling button bound to the active SConfigProvider theme. Each click advances the preference through auto → light → dark → auto, and the icon always shows the current preference (monitor / sun / moon). Use it as a one-button scheme control in a header or toolbar when a dropdown is too heavy and a binary switch cannot express auto.
Usage
Features
- 🔁 Cycles
auto→light→dark→autoin one click each - 🖼 Icon reflects the current preference, so all three states are distinguishable
- 🎚 Writes the preference through the shared theme context — no
modelValue - ♿ Accessible name is the localized
Scheme: <current>text (overridable viaariaLabel), and it doubles as the tooltip - 🎨 Inherits
size/color/variant/shapefromSButtonIcon
Demos
Basic
API
Aria Layer
1ThemeModeToggle
Props
| Prop | Type | Default | Description |
|---|---|---|---|
size | ThemeSize | 'md' | Visual size of the button. |
color | ThemeColor | 'accent' | Theme color of the button. |
variant | ButtonVariant | 'ghost' | Visual variant of the button. |
shape | ButtonShape | 'square' | Shape of the button. |
ariaLabel | string | — | Accessible label of the button. Defaults to the localized
`Scheme: <current preference>` text, which also drives the `title` tooltip. |
Notes
Scope
Like SThemeModeSelect, SThemeModeSwitch, and SThemeModeSegment, SThemeModeToggle is a theme-layer component that operates on the theme context from a parent SConfigProvider. It does not accept a modelValue; the preference is owned by the provider and shared across all theme components. It is the single-button counterpart of SThemeModeSegment: same three preferences, no dropdown and no visible option list.
Cautions
- The component must be rendered inside a
SConfigProvider, otherwiseuseThemethrows. - Unlike
SThemeModeSwitch, it tracks the preference, not the effective scheme: withautothe icon stays a monitor even though the resolved scheme is light or dark. - Cycling always moves forward, so reaching a specific preference takes up to two clicks; use
SThemeModeSelectorSThemeModeSegmentfor direct selection.