Letters glide to their new positions when the string changes.
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/morphing-text.jsonnpx shadcn@latest add https://animate.prequelui.terravidhal.me/r/morphing-text.json
Turn on the motion
npx @prequelui/cli@latest animate morphing-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 { MorphingText } from "@/components/prequelui/morphing-text";
export default function Demo() {
return (
<MorphingText
text={["motion", "design", "product", "rhythm"]}
holdDelay={2500}
loop
className="text-4xl font-medium"
/>
);
}import { MorphingText } from "@/components/prequelui/morphing-text";
export function Variant() {
return (
<MorphingText tempo={1.2}>
…
</MorphingText>
);
}Animation
Letters are matched between the two strings, so shared letters stay put while the others leave and enter. Each incoming letter starts eighty milliseconds after the change and twelve milliseconds after the previous one; layout animation carries every survivor to its new position.
- Surviving letters animate with a 300/30 position spring.
- New letters enter from 0.12 em below with a 6 px blur.
- Departing letters leave with a 150 ms blur and fade.
- The cycle pauses off-screen and the final text is announced once.
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.
MorphingText
| Prop | Type | Default |
|---|---|---|
| text | string | string[] | — |
| delay | number | 0 |
| holdDelay | number | 2500 |
| loop | boolean | false |
| inView | boolean | false |