Skip to content
Textlab
1
Browse

ComponentsNumbers

Rolling number

Each digit rolls to its new value.

2,048

Installation

$ npx shadcn@latest add @textlab/rolling-number

Needs @textlab in your components.json. Setup takes a minute.

Usage

usage.tsx
import { RollingNumber } from "@/components/textlab/rolling-number/rolling-number";

<RollingNumber value={count} format={{ style: "currency", currency: "USD" }} />

Variants

shortestupdown

Props

PropTypeDefaultDescription
value*number–The number to show.
variant"shortest" | "up" | "down""shortest"shortest takes the nearer way round; up and down always roll one way.
formatIntl.NumberFormatOptions–Formatting, for example currency or compact notation.
localestring"en-US"Fixed by default so server and client render the same string.
durationnumber0.6Seconds a digit takes to settle.
bouncenumber0.1Spring bounce, 0 to 0.5.
livebooleanfalseAnnounce changes politely to screen readers.
asElementType"span"Rendered element.
reducedMotion"user" | "always" | "never""user"user follows the OS setting; always shows the still version.
classNamestring–Merged onto the root.

When to use it

Reach for it

  • Counters, balances and scores that change while people watch.
  • Dashboards where the change itself is information.

Skip it

  • Numbers that never change after load; use stat-reveal.
  • Values updating many times a second; the motion becomes noise.

Accessibility and motion

Accessibility

  • Screen readers read the formatted value, not the reels.
  • Set live to announce updates; leave it off for values that tick constantly.

Motion

  • Each reel runs on a spring, so rapid updates interrupt smoothly.
  • Columns are keyed from the right; new leading digits slide in and old ones slide out.
Reduced motion. The new value replaces the old one with no rolling.

Performance

  • One spring per digit. Reels re-center silently after each roll so the DOM stays fixed size.