Only the letters that changed glide to their new spots.
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/swapping-text.jsonnpx shadcn@latest add https://animate.prequelui.terravidhal.me/r/swapping-text.json
Turn on the motion
npx @prequelui/cli@latest animate swapping-textThe 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 { SwappingText } from "@/components/prequelui/swapping-text";
export default function Demo() {
return (
<SwappingText
text={["handcrafted", "handwritten", "handtuned"]}
duration={2000}
direction="up"
className="text-4xl font-medium"
/>
);
}import { SwappingText } from "@/components/prequelui/swapping-text";
export function Variant() {
return (
<SwappingText tempo={1.2}>
…
</SwappingText>
);
}Animation
Only the characters that differ move. Unchanged slots stay still, changed slots lift their old glyph out while the new one rises into place, and the slot width glides from the measured old advance to the measured new one.
- Character tween: 200 ms with a fill curve.
- Stagger: 40 ms between changed slots.
- Old glyph exits with a 2 px blur and 0.5 em of travel; the new glyph mirrors it.
- Reduced motion changes the string without slot animation.
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.
SwappingText
| Prop | Type | Default |
|---|---|---|
| text | string | string[] | — |
| duration | number | 2000 |
| delay | number | 0 |
| direction | "up" | "down" | "up" |
| stagger | number | 0.04 |