A theme button whose icon spins, shrinks and blurs away.
Installation
Install the packages
npm install @prequelui/react motion@prequelui/react reuses the primitive library your components already depend on.
Add the component
npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/theme-toggler-button.jsonnpx shadcn@latest add https://animate.prequelui.terravidhal.me/r/theme-toggler-button.json
Turn on the motion
npx @prequelui/cli@latest animate theme-toggler-buttonThe 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.
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.
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.