Skip to content

ThemeToggle ​

Switches between light and dark modes, or picks light, dark or system. The component drives useTheme: the state is shared by the whole application and saved in the browser when persist is on.

Usage ​

Toggle button ​

vue
<SuThemeToggle />

The button is named "Dark mode" and reports its state with aria-pressed: pressed in dark mode. From system mode, it switches to the opposite of the applied mode.

Light, dark or system ​

vue
<SuThemeToggle variant="segmented" />

Sizes ​

vue
<SuThemeToggle variant="segmented" size="sm" />
<SuThemeToggle variant="segmented" size="lg" />

API ​

Props ​

PropTypeDefaultDescription
variant'button' | 'segmented''button'Toggle button, or three options
size'sm' | 'md' | 'lg''md'Size
labelstring'Dark mode' / 'Appearance'Name of the button, or of the group (segmented variant)
lightLabelstring'Light'Light option
darkLabelstring'Dark'Dark option
systemLabelstring'System'System option (follows prefers-color-scheme)

Events ​

EventPayloadDescription
changeThemeModeChosen mode: 'light', 'dark' or 'system'

Accessibility ​

  • button variant: toggle button named "Dark mode", state reported by aria-pressed; the icon (sun or moon) is decorative.
  • segmented variant: group named "Appearance" (role="group") of three aria-pressed buttons with visible labels.
  • Server rendering: the saved preference is only read after mount, with no hydration mismatch.

Publié sous licence MIT.