ThemeToggle
The button and its accessible label. The consumer owns persistence and the actual class/attribute switch.
Design intent
Theme persistence is app-specific (cookie, localStorage, server session), but the control is the same everywhere. ThemeToggle owns the button, icon state, and accessible label while the consumer owns storage and the actual class/attribute switch.
npx @slipstream-ui/cli@latest add theme-toggleThemeToggle is presentational only — it does not persist the choice or switch the class/attribute itself. See Theming for the persistence and attribute-switch half.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| theme | 'light' | 'dark' | — | Current theme. |
| onThemeChange | (theme: 'light' | 'dark') => void | — | Fired with the next theme. |
| labels | { toLight?: string; toDark?: string } | — | Accessible labels for the next action. |
| size | 'sm' | 'md' | 'md' | Control size. |
Anti-patterns
validate_usage is the MCP tool that rejects these mistakes: the same list agents see over MCP and in the canonical markdown.
Don't let the component own persistence
Theme storage differs by app (cookie for SSR, localStorage for SPAs). Keep persistence in the consumer and pass theme/onThemeChange.
Don't use an icon-only button without a label
The component always sets aria-label and title; don't override them with empty values.
Accessibility
- aria-label and title describe the next action.
- Native button with Enter/Space activation and a visible focus ring.
- Icons are aria-hidden; the label carries the meaning.
Content guidelines
Labels
- Name the action
- Use sentence case
- Avoid 'Toggle'
Good examples
- Switch to dark theme
- Switch to light theme
Bad examples
- Theme
- Toggle
- Click
Composition
Compose with SiteHeader: Place in SiteHeader actions or the app shell header.
Related components: Button, SiteHeader, AppShell
Dependencies
What the registry installs alongside this component. Package imports already include these.
npm packages
- class-variance-authority
- clsx
- tailwind-merge
Browser support
| Browser | Tested versions |
|---|---|
| Chrome | 111+ (Mar 2023) |
| Edge | 111+ (Mar 2023) |
| Firefox | 121+ (Dec 2023) |
| Safari | 17.2+: macOS & iOS (Dec 2023) |
Slipstream components rely only on CSS custom properties, Flexbox/Grid, and ARIA, the everyday baseline of the last two years of evergreen releases. Anything newer is progressive enhancement: unsupported browsers keep full functionality with static behavior instead of animations.