# Theme toggle

Switches the page between light, dark and system.

Import from `@a31labs/rax/theme-toggle`.

## Usage

```tsx
<ThemeToggle />  // const { mode, resolved, setMode } = useMode();
// in the head, to avoid a flash:
<script dangerouslySetInnerHTML={{ __html: modeScript }} />
```

## Rules

`useMode()` returns `{ mode: "light" | "dark" | "system", resolved, setMode }`. It sets `data-mode` on `<html>` (removed for `system`), stores the choice in localStorage under `rax-mode`, and follows `prefers-color-scheme` for `resolved`. All callers share one module-level store, so no provider is needed; on the server it reports `system` and `light`. `ThemeToggle` is a ghost IconButton (moon or sun) that switches between light and dark from the resolved mode; its label names the action ("Switch to dark mode"). Put `modeScript` in an inline `<script>` in `<head>` to apply the stored mode before first paint.

Page: https://rax.a31.at/components/theme-toggle
