Theme Toggler Button

A theme button whose icon spins, shrinks and blurs away.

theme-toggler-button.tsx

Installation

1

Install the packages

npm install @prequelui/react motion

@prequelui/react reuses the primitive library your components already depend on.

2

Add the component

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/theme-toggler-button.json

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/theme-toggler-button.json

3

Turn on the motion

npx @prequelui/cli@latest animate theme-toggler-button

The CLI finds the component through components.json, swaps the import and removes the CSS animation classes that Motion replaces.

Usage

Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.

theme-toggler-button.tsx
import { Moon, Sun } from "lucide-react";
import { useTheme } from "@/components/site/theme-provider";
import {
  ThemeTogglerButton,
  ThemeTogglerButtonIcon,
} from "@/components/prequelui/theme-toggler-button";

export default function Demo() {
  const { theme, resolvedTheme, setTheme } = useTheme();
  return (
    <ThemeTogglerButton
      theme={theme}
      resolvedTheme={resolvedTheme}
      setTheme={setTheme}
    >
      <ThemeTogglerButtonIcon light={<Sun />} dark={<Moon />} />
    </ThemeTogglerButton>
  );
}
import { ThemeTogglerButton } from "@/components/prequelui/theme-toggler-button";

export function Variant() {
  return (
    <ThemeTogglerButton tempo={1.2}>
      …
    </ThemeTogglerButton>
  );
}

Animation

The icon does not disappear: it turns a quarter turn, shrinks to half and blurs while the next icon arrives from the opposite rotation. The swap runs in 300 ms and the button keeps the shared press spring.

  • Icon swap: 300 ms ease-out with rotate 90° and scale 0.5.
  • The outgoing icon rotates one way, the incoming icon the other.
  • The first paint is instant, so hydration can never animate the initial icon.
  • Reduced motion swaps with a plain fade.
swap 300 msrotate 90°scale 0.5instant first paint

API Reference

Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.

ThemeTogglerButton

PropTypeDefault
theme"light" | "dark" | "system"—
resolvedTheme"light" | "dark"—
setTheme(theme: Theme) => void—
modesTheme[]["light","dark","system"]

ThemeTogglerButtonIcon

PropTypeDefault
lightReactNode—
darkReactNode—
systemReactNode—
rotatenumber90

Built by Vidhal. The source is available on GitHub.

Last updated: 11/17/2026