Theme Toggle Circular

A wrapper component that animates a circular reveal from the click point when toggling the theme, using the View Transitions API. It wraps any children and calls onToggle inside document.startViewTransition, falling back to a plain toggle when the API is unavailable.

Theme Toggle Circular
LIVE · running in a sandboxed iframe
Installed with plain shadcn add · no workarounds · theme neutral (none shipped)
See how it was built

Installation

pnpm dlx shadcn@latest add @animbits/transitions-theme-toggle-circular

Requires @animbits in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { ThemeToggleCircular } from "@/components/animations/transitions/theme-toggle-circular"export function Example() {  return (    <ThemeToggleCircular onToggle={() => document.documentElement.classList.toggle("dark")}>      <button type="button">Toggle theme</button>    </ThemeToggleCircular>  )}
  • Adding a theme toggle button (light/dark) that should feel like a spreading ripple from the click point
  • Upgrading a plain theme switch with a polished, modern page-wide transition
  • Creating a playful, eye-catching dark mode switch for landing pages or settings screens
  • Wrapping an existing toggle control without changing how its state is managed

Examples

Basic dark mode toggle

Toggles the dark class on the html element when the wrapped button is clicked.

basic-dark-mode-toggle.tsx
import { ThemeToggleCircular } from "@/components/animations/transitions/theme-toggle-circular"export function BasicToggle() {  return (    <ThemeToggleCircular      onToggle={() => document.documentElement.classList.toggle("dark")}    >      <button type="button" className="rounded-md border px-3 py-2">        Switch theme      </button>    </ThemeToggleCircular>  )}

Slower transition with blur

Sets a longer duration and a soft blur on the transitioning layers.

slower-transition-with-blur.tsx
import { ThemeToggleCircular } from "@/components/animations/transitions/theme-toggle-circular"export function SlowBlurToggle() {  return (    <ThemeToggleCircular      speed={1}      blur={4}      onToggle={() => document.documentElement.classList.toggle("dark")}    >      <button type="button" className="rounded-full bg-black px-4 py-2 text-white">        Dark mode      </button>    </ThemeToggleCircular>  )}

Icon toggle with state

Uses a React state value for the icon while the component handles the animated switch.

icon-toggle-with-state.tsx
import * as React from "react"import { ThemeToggleCircular } from "@/components/animations/transitions/theme-toggle-circular"export function IconToggle() {  const [dark, setDark] = React.useState(false)  return (    <ThemeToggleCircular      className="inline-flex cursor-pointer"      onToggle={() => {        setDark((prev) => !prev)        document.documentElement.classList.toggle("dark")      }}    >      <span aria-hidden="true">{dark ? "☀️" : "🌙"}</span>    </ThemeToggleCircular>  )}

API reference

PropTypeDefaultDescription
childrenReact.ReactNode—Content rendered inside the clickable wrapper div; typically a toggle button or icon.
onToggle() => void—Callback that performs the theme change. Runs inside document.startViewTransition, or directly when the API is unsupported.
theme"light" | "dark"—Declared in the props interface and destructured, but not used by the implementation.
classNamestring—Class name applied to the wrapper div.
speednumber0.5Duration in seconds of the circular transition, applied as --transition-speed.
blurnumber0Blur radius in pixels applied to the transitioning layers, applied as --transition-blur.

Accessibility

  • The wrapper is a plain div with an onClick handler and is not keyboard-focusable; place an interactive button or link inside children so keyboard users can activate it.
  • Keyboard activation (Enter/Space) is not forwarded by the wrapper; rely on the focusable child element's native click behavior.
  • The transition respects prefers-reduced-motion: reduce through the bundled CSS, which disables view transition animations.
  • Provide an accessible label (aria-label or visible text) on the toggle control so screen reader users know what it changes.
  • During the transition pointer events are disabled on the wrapper to prevent repeated clicks.

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.

prompt.md
Use the "Theme Toggle Circular" component (animbits/transitions-theme-toggle-circular) from its shadcn registry.1. Install it with: npx shadcn@latest add @animbits/transitions-theme-toggle-circular2. 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: children, onToggle, theme, className, speed, blur.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { ThemeToggleCircular } from "@/components/animations/transitions/theme-toggle-circular"export function Example() {  return (    <ThemeToggleCircular onToggle={() => document.documentElement.classList.toggle("dark")}>      <button type="button">Toggle theme</button>    </ThemeToggleCircular>  )}```

Files & dependencies

  • registry/new-york/animations/transitions/theme-toggle-circular.tsx

Looks similar, elsewhere