A scroll-linked progress bar driven without overshoot.
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/scroll-progress.jsonnpx shadcn@latest add https://animate.prequelui.terravidhal.me/r/scroll-progress.json
Turn on the motion
npx @prequelui/cli@latest animate scroll-progressThe 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 { useRef } from "react";
import { ScrollProgress } from "@/components/prequelui/scroll-progress";
export default function Demo() {
const ref = useRef<HTMLDivElement>(null);
return (
<div className="w-[320px]">
<ScrollProgress containerRef={ref} />
<div ref={ref} className="h-40 overflow-y-auto">
{/* long content */}
</div>
</div>
);
}import { ScrollProgress } from "@/components/prequelui/scroll-progress";
export function Variant() {
return (
<ScrollProgress tempo={1.2}>
…
</ScrollProgress>
);
}Animation
The bar follows a container or the page through a spring that is damped to zero bounce. Scroll events only write the raw ratio; the spring is what gives the bar its short, smooth catch-up.
- Spring: 250 / 40 with bounce 0.
- A ref target measures its own scroll range; no ref targets the page.
- The bar scales on X from a left origin, never animating width.
- A resize listener re-measures the range.
- Scroll updates are passive and never block the page.
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.
ScrollProgress
| Prop | Type | Default |
|---|---|---|
| containerRef | RefObject<HTMLElement> | — |
| barClassName | string | — |
| transition | Transition | component spring or tween |
| className | string | — |