Theme Toggle
theme-toggleA sun that sets into a crescent moon, and the new theme revealed from the button with a View Transition: a circle, a soft-edged spill or a shutter, measured to the farthest corner. No theme library, no flash, and a setTheme you can call from anywhere.
import { ThemeToggle } from "@/components/forme/theme-toggle/theme-toggle";
import type { ThemeReveal } from "@/components/forme/theme-toggle/theme-toggle";
const reveals: { reveal: ThemeReveal; label: string }[] = [
{ reveal: "circle", label: "Circle" },
{ reveal: "soft", label: "Soft edge" },
{ reveal: "shutter", label: "Shutter" },
{ reveal: "none", label: "Instant" },
];
export function ThemeToggleDemo() {
return (
<ul className="grid w-full max-w-lg grid-cols-2 gap-3 sm:grid-cols-4">
{reveals.map(({ reveal, label }) => (
<li
key={reveal}
className="flex flex-col items-center gap-2 rounded-xl border border-border bg-card lit edge py-4"
>
<ThemeToggle reveal={reveal} />
<span className="text-caption-1-regular text-muted-foreground">{label}</span>
</li>
))}
</ul>
);
}Install
Adds the component, its registry dependencies, and the token stylesheet you import once.
Usage
import { ThemeToggle, themeScript } from "@/components/forme/theme-toggle/theme-toggle";
// In <head>, so the stored theme applies before the first paint:
<script dangerouslySetInnerHTML={{ __html: themeScript }} />
<ThemeToggle reveal="circle" />When to use
Reach for it
- Switching between the light and dark theme from a header or a settings page.
Use something else
- Offering a “system” option as well — that needs a three-way control, such as a
SegmentedControl.
API reference
Read from the source, so it is the API of the file you install. A prop marked * is required.
ThemeToggle
Switches between the light and dark theme: a sun that sets into a crescent moon, and a reveal of the new theme that grows out of the button.
| Prop | Type | Default | Description |
|---|---|---|---|
reveal | 'circle' | 'none' | 'soft' | 'shutter' | "circle" | |
onChange | (theme: Theme) => void | — | Called with the new theme, e.g. to save it to an account. |
Also takes every prop of <button> attributes.
Accessibility
- It is a toggle button named “Dark mode” and pressed while dark is on.
- The icon is drawn from the
.darkclass, so the server and client render the same and there is no flash of the wrong icon.
Motion
- The new theme is revealed from the button with a View Transition: a circle, a soft circle, a shutter, or
none. - Where View Transitions are missing, or with reduced motion, the theme simply changes.
Related


Button
The primary action element. Four variants and three sizes, gradient primaries that crossfade on hover rather than snap, and an icon contract where the button owns the icon size. No client boundary, so it works in a server component and ships no JavaScript.
buttons

Hold Button
Press and hold to confirm, with a fill that sweeps across while you hold and drains back if you let go early. For actions too serious for one click and too small for a dialog. Space and Enter hold it from the keyboard.
buttons