A number that counts to its target on a heavily damped spring.
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/counting-number.jsonnpx shadcn@latest add https://animate.prequelui.terravidhal.me/r/counting-number.json
Turn on the motion
npx @prequelui/cli@latest animate counting-numberThe 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 { CountingNumber } from "@/components/prequelui/counting-number";
export default function Demo() {
return (
<CountingNumber
number={12840}
fromNumber={0}
thousandSeparator=","
className="text-5xl font-medium"
/>
);
}import { CountingNumber } from "@/components/prequelui/counting-number";
export function Variant() {
return (
<CountingNumber tempo={1.2}>
…
</CountingNumber>
);
}Animation
The value is animated as a number, never as a string. Intermediate frames are written straight into the visual span outside React, so the digits update at frame rate while the component itself does not re-render.
- Spring: stiffness 90, damping 50, restDelta 0.001, restSpeed 0.01.
- The final value is exposed once to assistive technology in a visually hidden span.
- Digits use tabular numerals, so the width never shifts while counting.
- Reduced motion writes the target value immediately without intermediate frames.
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.
CountingNumber
| Prop | Type | Default |
|---|---|---|
| number | number | 0 |
| fromNumber | number | 0 |
| inView | boolean | false |
| inViewOnce | boolean | true |
| delay | number | 0 |
| decimalPlaces | number | 0 |
| decimalSeparator | string | "." |
| thousandSeparator | string | undefined | — |
| padStart | boolean | false |
| initiallyStable | boolean | false |
| onCompleted | () => void | — |
| transition | Transition | component spring |
| className | string | — |