Theme Toggler

A theme switch revealed by a 700 ms clip-path wipe.

theme-toggler.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.json

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

3

Turn on the motion

npx @prequelui/cli@latest animate theme-toggler

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.tsx
import { ThemeToggler } from "@/components/prequelui/effects/theme-toggler";
import { useTheme } from "@/components/site/theme-provider";

export default function Demo() {
  const { theme, resolvedTheme, setTheme } = useTheme();
  return (
    <ThemeToggler theme={theme} resolvedTheme={resolvedTheme} setTheme={setTheme}>
      {({ resolved, toggleTheme }) => (
        <button onClick={() => toggleTheme(resolved === "dark" ? "light" : "dark")}>
          Toggle theme
        </button>
      )}
    </ThemeToggler>
  );
}
import { ThemeToggler } from "@/components/prequelui/theme-toggler";

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

Animation

The theme change is performed inside a View Transition, and the new snapshot is revealed by a clip-path wipe. The button, the preview and the theme provider all read the same resolved value, so no element flashes the wrong colour.

  • Wipe: 700 ms ease-in-out, scaled by the motion tempo.
  • Four directions: left-to-right, right-to-left, top-to-bottom and bottom-to-top.
  • The old and new roots never crossfade; the new one is clipped over the old one.
  • Without View Transitions or with reduced motion, the theme changes instantly.
wipe 700 msease-in-out4 directionsview transitions

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.

ThemeToggler

PropTypeDefault
theme"light" | "dark" | "system"—
resolvedTheme"light" | "dark"—
setTheme(theme) => void—
direction"ltr" | "rtl" | "ttb" | "btt""ltr"
onImmediateChange(theme) => void—
childrenReactNode | (state) => ReactNode—

Built by Vidhal. The source is available on GitHub.

Last updated: 11/17/2026