Scroll Progress

Fixed bar that tracks reading progress down the page. Install Scroll Progress from the VLLNT UI registry with the shadcn CLI.

Report a bug

Fixed bar that tracks reading progress down the page. Part of the data-display family in VLLNT UI, it ships as a machine-readable registry entry — copy the source directly into your app with the shadcn CLI and own it, no runtime dependency on a component library.

Preview

Switch between light and dark to inspect the embedded Storybook preview.

Installation

Add Scroll Progress to your project with the shadcn CLI. The source lands in your codebase, ready to adapt:

pnpm dlx shadcn@latest add https://ui.vllnt.ai/r/scroll-progress.json

Source

"use client"; import * as React from "react"; import { cn } from "../../lib/utils"; /** Props for {@link ScrollProgress}. */ export type ScrollProgressProps = React.ComponentPropsWithoutRef<"div">; function computeProgress(): number { const element = document.documentElement; const scrollable = element.scrollHeight - element.clientHeight; if (scrollable <= 0) { return 0; } return (element.scrollTop / scrollable) * 100; } /** * Fixed bar pinned to the top of the page that grows with scroll progress. * * Functional under `prefers-reduced-motion`: it updates instantly. * * @example * ```tsx * <ScrollProgress /> * ``` */ export const ScrollProgress = ({ className, ref, style, ...props }: ScrollProgressProps & { ref?: React.Ref<HTMLDivElement> }) => { const [progress, setProgress] = React.useState(0); React.useEffect(() => { const onScroll = (): void => { setProgress(computeProgress()); }; onScroll(); window.addEventListener("scroll", onScroll, { passive: true }); return () => { window.removeEventListener("scroll", onScroll); }; }, []); return ( <div aria-valuemax={100} aria-valuemin={0} aria-valuenow={Math.round(progress)} className={cn( "fixed inset-x-0 top-0 z-50 h-1 origin-left bg-primary", className, )} ref={ref} role="progressbar" style={{ width: `${progress}%`, ...style }} {...props} /> ); }; ScrollProgress.displayName = "ScrollProgress";

Stories

Explore every variant and state in the interactive Storybook:

Preview

Switch between light and dark to inspect the embedded Storybook preview.

Dependencies

  • @vllnt/ui@^0.3.0