Experimental theme switcher
The experimental theme switcher is a public Vue component for choosing the application color scheme. It presents light, dark, and system choices as preview cards, applies the selected scheme through the shared color-scheme state, and supports branded previews and custom labels. It is available from the experimental package and is deprecated for new work in favor of composing useColorScheme with a current selection control.
Scope and role
The switcher is the full preview-card experience for theme selection. Smaller controls can use the same shared state without rendering this component, so a page can place a toggle or a menu beside the full switcher and keep all controls aligned.
The component is exported from experimental/…/index.ts. The broader experimental feature context is described in Experimental features. Related controls include the rich text editor, list view, and experimental calendar.
Public selection control
The public control gives an engineer one labeled choice set with three supported color schemes. It combines a visible heading and helper text with an accessible horizontal radio group, then uses the shared color-scheme state when the caller does not provide a value.
Option model
The option model is fixed to the three values below. Each value has a preview card and a selected marker, which lets users compare the choices before they change the application scheme.
| Value | Meaning | Default label |
|---|---|---|
light | Use the light appearance. | Light |
dark | Use the dark appearance. | Dark |
system | Follow the operating system appearance. | System |
modelValue makes the control usable as a bound component. Without it, the control reads the shared useColorScheme selection. A selection always goes through the shared setter and emits update:modelValue, so the document theme and a bound parent can respond to the same choice.
References: experimental/…/ThemeSwitcher.vue• L22-40 experimental/…/ThemeSwitcher.vue• L86-106 experimental/…/types.ts• L4-7
Labels and accessible names
The control shows Theme and Switch between light, dark, or system theme by default. Callers can replace these strings with the label and description props or provide the label and description slots. The label also supplies the accessible name when it is visible; otherwise the control uses the label value or Theme as its accessible name.
Each option label can be changed with themeLabels. The item-label slot takes precedence when an option needs richer content, and it receives that option’s ColorScheme value.
References: experimental/…/ThemeSwitcher.vue• L4-20 experimental/…/ThemeSwitcher.vue• L108-118 experimental/…/ThemeSwitcher.vue• L135-147 experimental/…/types.ts• L9-18 experimental/…/types.ts• L29-35
Preview presentation
The preview UI is a visual explanation of each choice rather than a live copy of the application. It places a small window inside a desktop frame and changes the window tone to make the light and dark choices easy to distinguish.
Preview variants
Light and dark options use one wide preview window. The window includes simple content bars and uses the matching light or dark tone. The system option uses two clipped windows side by side, one light and one dark, to show that the final appearance depends on the operating system setting.
The preview is presentational. It does not change the current theme by itself; the surrounding radio option owns selection and the shared color-scheme state owns the application change.
References: experimental/…/ThemePreview.vue• L5-21 experimental/…/ThemePreview.vue• L38-74 experimental/…/PreviewWindow.vue• L5-26 experimental/…/PreviewWindow.vue• L68-73
Branded presentation
The same brand content appears inside every preview window. name adds the brand name, while logo accepts either an image source string or a Vue component. The image form is treated as a decorative image, and the component form is rendered as the logo mark.
References: experimental/…/types.ts• L20-27 experimental/…/ThemeSwitcher.vue• L44-49 experimental/…/ThemePreview.vue• L31-35 experimental/…/PreviewWindow.vue• L28-43
Menu and toggle variants
The menu and toggle variants are composition patterns around the shared color-scheme state. They are not additional modes of the preview-card component, which keeps the full comparison UI separate from compact navigation controls.
Toggle variant
The toggle variant is a single labeled action for a header or sidebar. It uses toggleColorScheme to move between light and dark, and it remains in sync with the preview control because both read and update the same shared state. It does not represent the system choice unless the surrounding product adds a separate control for that value.
References: experimental/…/ThemeSwitcher.md• L30-38 experimental/…/ThemeSwitcher.md• L49-64
Menu variant
The menu variant places the three scheme choices in a user menu, usually as a submenu of Dropdown. Each menu item reads the shared selection and marks the active item as selected. This pattern gives users access to the same choices without taking space for preview cards.
References: experimental/…/ThemeSwitcher.md• L40-47 experimental/…/ThemeSwitcher.md• L49-58
Theme selection types
Theme selection uses the ColorScheme type from the shared color-scheme composable. The type is the contract shared by component props, emitted updates, option labels, and custom option-label content.
Color scheme values
ColorScheme is the union of light, dark, and system. ThemeSwitcherProps.modelValue is optional because the component can use the shared selection as its source when it is unbound. themeLabels is a partial map, so callers can override only the labels that need a change.
The public package entry point exports ThemeSwitcher and ThemeSwitcherProps. The ColorScheme type remains owned by useColorScheme, which keeps the component and compact variants on one selection contract.
References: experimental/…/types.ts• L1-7 experimental/…/types.ts• L29-35 experimental/…/index.ts• L1-2 experimental/…/ThemeSwitcher.vue• L86-95
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the
ColorSchemevalues aligned across the radio options, emitted updates, label map, and menu or toggle variants. - Keep unbound selection tied to the shared color-scheme state so compact controls and the preview-card control do not show different choices.
- Keep the
systempreview distinct from the single-tone previews when changing preview content or branding. - Keep the image-string and component-logo paths aligned when changing branded presentation.
- Keep the experimental export and the deprecation guidance aligned when moving or replacing the component.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
A caller treats modelValue as the only source of truth while another control changes the shared scheme. | The bound control can show a stale choice. | Update the bound value from update:modelValue and keep all controls connected to the shared color-scheme state. |
| A new scheme is added to the type but not to the switcher options or label map. | Users cannot select or label the new scheme through the public control. | Update the selection contract and the option presentation together. |
| A logo URL is passed through the component path intended for a Vue component, or the reverse. | The brand mark does not render as intended. | Use a string for an image source and a component value for a rendered logo component. |
| The system preview is changed to use one tone. | The preview no longer explains that system mode follows the operating system. | Preserve the paired light and dark representation for system. |
Key files
| File | Why to read it |
|---|---|
| experimental/…/ThemeSwitcher.vue | Shows the public selection flow, option set, accessibility model, and shared-state behavior. |
| experimental/…/types.ts | Defines the public props and the theme-selection type contract. |
| experimental/…/ThemePreview.vue | Explains the visual difference between light, dark, and system previews. |
| experimental/…/PreviewWindow.vue | Shows the branded window treatment used inside each preview card. |
| experimental/…/index.ts | Shows the experimental public exports. |
| experimental/…/ThemeSwitcher.md | Describes the compact toggle and user-menu composition patterns. |