Drop-in theme picker
This is enough for most apps because persistence and root theme updates are built in.
<CwThemePicker />Toggle between dark, light, and system themes. Applies data-theme on the root element.
<CwThemePicker onchange={(theme) => console.log(theme)} />CwThemePicker controls the library theme and persists the chosen mode. It can manage itself, or you can bind the current theme if the parent also wants to react to it.
| API | Type | Details |
|---|---|---|
theme Default: | 'dark' | 'light' | 'system' | Current theme mode. |
onchange | (theme: 'dark' | 'light' | 'system') => void | Runs after the user selects a theme. |
These snippets intentionally show the full public API surface the live demo relies on.
This is enough for most apps because persistence and root theme updates are built in.
<CwThemePicker />Bind the state when the parent also wants the selected theme.
<script lang="ts">
let theme = $state<'dark' | 'light' | 'system'>('system');
</script>
<CwThemePicker
bind:theme={theme}
onchange={(nextTheme) => console.log('Theme changed:', nextTheme)}
/>