In a site header
import { ThemeSwitcher } from "@senvenli/react/action";
export default function Example() {
return <ThemeSwitcher />;
}import { ThemeSwitcher } from "@senvenli/react/action";Examples
As a list
The same choice as three rows with a check, for a phone menu.import { ThemeSwitcher } from "@senvenli/react/action";
export default function Example() {
return (
<div className="max-w-xs">
<ThemeSwitcher variant="list" />
</div>
);
}Controlled
With `value`, the parent owns the theme: the toggle stores and applies nothing.import { ThemeSwitcher, type ThemeChoice } from "@senvenli/react/action";
import { Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";
import { useState } from "react";
export default function Example() {
const [choice, setChoice] = useState<ThemeChoice>("system");
return (
<Stack direction="horizontal" space="space-150">
<ThemeSwitcher value={choice} onChange={setChoice} />
<Text tone="subtle">Chosen: {choice}</Text>
</Stack>
);
}Guidelines
When to use it
- An app or site offers light and dark themes.
Accessibility
Keyboard
| Keys | What happens |
|---|---|
| Arrow keys | Moves between and selects the options. |
Built in
- One tab stop; a radio group named "Theme".
- System says which theme is in effect now.
API reference
ThemeSwitcher
| Prop | Type | Default | Description |
|---|---|---|---|
value | ThemeChoice | – | Controlled choice; leave out to let the toggle manage, store and apply it. |
onChange | (choice: ThemeChoice) => void | – | |
labels | Partial<ThemeLabels> | – | Localized names; the locale's built-in strings by default. |
storageKey | string | – | |
variant | "list" | "menu" | "segmented" | "segmented" |
|
valueThemeChoiceControlled choice; leave out to let the toggle manage, store and apply it.
onChange(choice: ThemeChoice) => voidlabelsPartial<ThemeLabels>Localized names; the locale's built-in strings by default.
storageKeystringvariant"list" | "menu" | "segmented"Default"segmented"segmented: three icon buttons.menu: one icon button (the theme in effect) that opens System / Light / Dark, the compact form for a busy header.list: a three-option list with a check, for the phone menu.