Theme Toggle
A light/dark theme switch available as a single morphing sun-to-moon icon button or a Light · System · Dark segmented control with a sliding pill. It persists the choice, follows the OS in System mode, writes the resolved theme to <html>, and can reveal the new theme as a circle grown from the button via View Transitions.
Installation
Requires @reactframe in the registries of your components.json (shadcn adds official directory namespaces automatically).
Usage
import { ThemeToggle } from "@/components/theme-toggle";export function Header() { return ( <header className="flex items-center justify-between p-4"> <ThemeToggle variant="icon" /> </header> );}- Adding a compact dark/light mode toggle to a navbar, header, or settings area where a single icon button is enough.
- Offering a full Light · System · Dark preference picker in a settings page or account menu.
- Needing the theme persisted in localStorage and applied to <html> via a class or data-theme attribute without extra wiring.
- Wanting a circular View Transitions reveal when switching themes, while still respecting reduced-motion preferences.
Examples
Icon toggle in a navbar
Default icon variant, persisting the choice under the default storage key and applying the theme class to <html>.
import { ThemeToggle } from "@/components/theme-toggle";export function Navbar() { return ( <nav className="flex items-center gap-4 p-4"> <ThemeToggle /> </nav> );}Segmented Light · System · Dark control
Segmented variant in a settings panel, with the choice tracked in controlled state and reported through onValueChange.
import * as React from "react";import { ThemeToggle, type ThemeChoice } from "@/components/theme-toggle";export function AppearanceSettings() { const [theme, setTheme] = React.useState<ThemeChoice>("system"); return ( <section className="space-y-2"> <p className="text-sm font-medium">Appearance</p> <ThemeToggle variant="segmented" value={theme} onValueChange={(next) => setTheme(next)} /> </section> );}Report-only mode with data-theme attribute
Disables writing to <html> and storage so the host app owns theme application, while still reporting the resolved theme; uses data-theme and light appearance for a light backdrop.
import { ThemeToggle } from "@/components/theme-toggle";export function CustomThemeBar() { return ( <ThemeToggle apply={false} attribute="data-theme" appearance="light" reveal={false} onValueChange={(choice, resolved) => { console.log(choice, resolved); }} /> );}API reference
Accessibility
- Icon variant is a button with aria-label reading "Switch to dark theme" or "Switch to light theme" depending on the resolved theme, and aria-pressed reflecting whether dark is active.
- Segmented variant is a role="radiogroup" labelled "Theme" with role="radio" buttons exposing aria-checked for each option.
- Decorative SVG icons are marked aria-hidden="true"; the visible text labels in the segmented control provide the accessible names.
- Focus is shown with focus-visible:ring-2 using a palette-specific ring colour, keeping keyboard focus visible.
- Animations respect prefers-reduced-motion: the icon morph, hover scale, pill sliding, and View Transition reveal are disabled or set to zero duration.
- Controls are real <button> elements, so they are keyboard operable with Enter and Space.
- System mode resolves through prefers-color-scheme, and the server render uses dark as the initial value to avoid hydration mismatch.
Docs written by anthropic:claude-haiku-5-5 from the registry source.
Use with Coding Agent
Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.
Use the "Theme Toggle" component (reactframe/theme-toggle) from its shadcn registry.1. Install it with: npx shadcn@latest add @reactframe/theme-toggle2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: variant, value, defaultValue, onValueChange, apply, attribute, storageKey, reveal, appearance, className.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { ThemeToggle } from "@/components/theme-toggle";export function Header() { return ( <header className="flex items-center justify-between p-4"> <ThemeToggle variant="icon" /> </header> );}```Files & dependencies
- registry/new-york/theme-toggle/theme-toggle.tsx
Looks similar, elsewhere
There is no screenshot of this item to compare yet.