A mechanical number band that scrolls and stops under a highlight.
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/scrolling-number.jsonnpx shadcn@latest add https://animate.prequelui.terravidhal.me/r/scrolling-number.json
Turn on the motion
npx @prequelui/cli@latest animate scrolling-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 { ScrollingNumber } from "@/components/prequelui/scrolling-number";
export default function Demo() {
return (
<ScrollingNumber
number={48}
fromNumber={0}
itemsSize={34}
className="w-40 text-2xl"
/>
);
}import { ScrollingNumber } from "@/components/prequelui/scrolling-number";
export function Variant() {
return (
<ScrollingNumber tempo={1.2}>
…
</ScrollingNumber>
);
}Animation
The number is a mechanical band. On first view the band leaves its resting index and settles under a fixed marker with a damped spring; changing the value retargets the same motion instead of restarting it.
- Band spring: stiffness 90, damping 30, restDelta 0.001.
- Two neighbours above and below stay visible, faded by the mask.
- The marker and the edge mask are decorative and hidden from assistive technology.
- Reduced motion places the band at its final index with no travel.
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.
ScrollingNumber
| Prop | Type | Default |
|---|---|---|
| number | number | 0 |
| fromNumber | number | 0 |
| step | number | 1 |
| itemsSize | number | 30 |
| sideItemsCount | number | 2 |
| inView | boolean | false |
| inViewOnce | boolean | true |
| delay | number | 0 |
| onCompleted | () => void | — |
| transition | Transition | component spring |
| className | string | — |