ThemeToggle
Persisted light/dark theme switcher with system-preference fallback
Accessibility
- Keep the default aria-label or pass a custom one so the purpose of the button is announced.
- The Alt-click and Escape shortcuts return to system mode; do not remove them in custom wrappers so users can opt back into prefers-color-scheme.
Styled quick start
Copy this entrypoint first. It includes the imports required to get the component on screen.
svelte
<script lang="ts">
import '@dryui/ui/themes/default.css';
import '@dryui/ui/themes/dark.css';
import { ThemeToggle } from '@dryui/ui';
</script>
<ThemeToggle storageKey="my-app-theme" /> Import options
Root package
ts
import { ThemeToggle } from '@dryui/ui' Per-component subpath
ts
import { ThemeToggle } from '@dryui/ui/theme-toggle' API
Props, CSS variables, and the public data attributes you can target when styling.
| Prop | Type | Description | Default | Required | Bindable |
|---|---|---|---|---|---|
| storageKey | string | — | — | — | — |
| size | smmdlg | Size preset affecting density, spacing, or typography. | 'md' | — | — |
| controller | ThemeController | — | — | — | — |
| sunIcon | Snippet | — | — | — | — |
| moonIcon | Snippet | — | — | — | — |
| onModeChange | (mode: ThemeMode) => void | — | — | — | — |
| disabled | boolean | Prevents interaction and applies disabled styling. | — | — | — |
| class | ClassValue | — | — | — | — |