Skip to content

Number Roll

An odometer style animated number where each digit rolls on a spring and only changed digits move. Supports Intl formatting, trend tint and reduced motion.

src/registry/ui/number-roll.tsx/r/number-roll.json

Installation

bash
npx shadcn@latest add @minidev/number-roll

MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/number-roll.json

Usage

tsx
import { NumberRoll } from "@/components/ui/number-roll"

export function Example() {
  return (
    <NumberRoll />
  )
}

API reference

NumberRoll props
PropTypeDefault
valueThe number to show. Change it to roll.number1284
formatIntl.NumberFormat options, e.g. { style: "currency", currency: "USD" }.Intl.NumberFormatOptions-
localeBCP 47 locale for formatting, e.g. "de-DE".string"en-US"
trendBriefly tint up/down changes with success/danger.boolean-
classNamestring-

When to use

Each digit is a strip of 0-9 that springs to its place, so changing $1,284 to $1,391 rolls only the digits that changed. Digits keep their identity from the right, so 999 → 1,000 grows a column instead of reshuffling. Screen readers get the plain formatted value; with reduced motion the number swaps instantly. Use it for live totals, prices and KPI values; for a static number just render it with tabular-nums.

Accessibility

  • The formatted value is in an sr-only span and the digit strips are aria-hidden, so screen readers read "$1,284", not ten digits per column.
  • It is not a live region. If a change must be announced, put the value in your own aria-live="polite" element.
  • Under reduced motion the digits swap instantly with no blur or slide.

Frequently asked questions

How do I format NumberRoll as currency or in another locale?

Pass format (any Intl.NumberFormat options) and locale: <NumberRoll value={total} locale="de-DE" format={{ style: "currency", currency: "EUR" }} />. An inline format object is fine; the formatter is cached by its contents.

How do I flash green or red when the number goes up or down?

Add trend. A rise tints the number text-success and a fall text-danger for 900ms, then it fades back.

Does NumberRoll count up from zero on load?

No. It renders the current value straight away, including in the server HTML, and only rolls when value changes. For a count-up on scroll, set the value from 0 when it comes into view, as MetricTickerBoard does.

Dependencies

npm

motion

Built from

No other MiniDev files

Examples

Formats

format takes Intl.NumberFormat options, so currency, percent and compact notation all work.

Controlled with trend

Change the value from state; with trend on, the figure flashes green or red for a moment.

Stepper

Small integers roll one digit at a time; fix the width so the buttons do not move.

Locale

locale changes the digit grouping and decimal separator along with the currency symbol.

All Animated React components

Learn more