Theme Toggle
A light and dark switch, or light, dark and system, with the new theme spreading out as a circle.
- Category
- Navigation & layout
- Access
- Free with an account
- Source
- 155 lines · one file
- States
- 5 drawn
- Added
- 3 Nov 2026
The decision inside it
The whole page changes in one frame
The reveal uses the browser's View Transitions, so every element switches under the circle at once instead of animating its own colours. Browsers without it, and reduced motion, switch instantly. Storage is yours: it only calls onThemeChange.
When to use it
Use Theme Toggle in a header or settings page to switch light, dark and system with a circular reveal. It works with any store: a cookie, next-themes or your own state.
Installation
How you get it
Paste this into Claude Code, Cursor, Codex or any coding agent. It installs the file and uses it as it is, instead of writing a new one.
Use Liro's Theme Toggle for this.
Install it: npx shadcn@latest add @liro/theme-toggle
(the @liro registry is set up in components.json, with LIRO_KEY in .env.local)
Import it from @/components/ui/theme-toggle.
Do not rewrite or restyle it. Pass my data through its props
and keep its built-in states.For the full brief with every prop and the mistakes assistants usually make, use Copy prompt above. Free components install through the @liro registry with your CLI token: see the Namespaced tab.
Usage
"use client";
import { useState } from "react";
import { ThemeToggle, type ThemeChoice } from "@/components/ui/theme-toggle";
export function SiteThemeToggle() {
const [theme, setTheme] = useState<ThemeChoice>("system");
const apply = (next: ThemeChoice) => {
const dark = next === "dark" || (next === "system" && matchMedia("(prefers-color-scheme: dark)").matches);
document.documentElement.classList.toggle("dark", dark);
localStorage.setItem("theme", next);
setTheme(next);
};
return <ThemeToggle theme={theme} onThemeChange={apply} />;
}API reference
“Copy prompt” above puts a full brief on your clipboard, install command, dependencies, props, and the mistakes an assistant usually makes with this component.
Props
Read from the component’s own TypeScript interface when the site is built, so this table cannot drift from the file you install.
| Type | Notes | ||
|---|---|---|---|
theme | ThemeChoice | Yes | – |
onThemeChange | (theme: ThemeChoice) => void | Yes | Apply the theme here (set a class, a cookie). Called inside the transition. |
variant | "icon" | "segmented" | No | A light/dark switch button, or three segments with system. Default "icon". |
origin | "button" | "pointer" | No | Where the circle grows from: the button (default) or the pointer. |
duration | number | No | Length of the reveal in ms. Default 520. |
Dependencies
npm packages
clsxframer-motionlucide-reacttailwind-mergeLiro foundations, installed alongside it
liro-themeStates
All of them are drawn by the component. None is left for you to design.
- Light
- Dark
- System
- Segmented
- From the pointer
Accessibility
- Keyboard reachable throughout, in visual order
- Focus trapped in overlays, Escape closes them
- Focus returns to whatever opened it
- Live regions announce what changed, not that something did
- Honours prefers-reduced-motion
Responsive behavior
- Sizes to its container, not the viewport
- Usable from 320px up
- Pointer-based interaction, so trackpad and touch both work
- No hover-only affordances