# 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.

- Kind: Component (Motion)
- Docs: https://ui.minidev.pro/docs/number-roll
- Source (registry JSON with the full file): https://ui.minidev.pro/r/number-roll.json
- License: MIT. One file, yours to edit after install.

## 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.

## Installation

### shadcn CLI (copies the source into your project)

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

Writes `components/ui/number-roll.tsx` and installs its npm dependencies. Older CLI versions: `npx shadcn@latest add https://ui.minidev.pro/r/number-roll.json`.

### npm package

```bash
npm i minidev-ui-kit motion
```

Add the tokens to your global stylesheet once:

```css
@import "tailwindcss";
@import "minidev-ui-kit/styles.css";
@source "../node_modules/minidev-ui-kit";
```

Next.js also needs `transpilePackages: ["minidev-ui-kit"]` in next.config.

## Import

After the shadcn install:

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

From the npm package:

```tsx
import { NumberRoll } from "minidev-ui-kit/ui/number-roll"
```

## Usage

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

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

## Props

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `value` | `number` | `1284` | no | The number to show. Change it to roll. |
| `format` | `Intl.NumberFormatOptions` | - | no | Intl.NumberFormat options, e.g. { style: "currency", currency: "USD" }. |
| `locale` | `string` | `"en-US"` | no | BCP 47 locale for formatting, e.g. "de-DE". |
| `trend` | `boolean` | - | no | Briefly tint up/down changes with success/danger. |
| `className` | `string` | - | no |  |

## Examples

### Formats

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

```tsx
<NumberRoll value={49200} format={{ style: "currency", currency: "USD" }} className="text-2xl font-medium" />
<NumberRoll value={0.184} format={{ style: "percent", maximumFractionDigits: 1 }} className="text-2xl font-medium" />
<NumberRoll value={1284000} format={{ notation: "compact" }} className="text-2xl font-medium" />
```

### Controlled with trend

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

```tsx
function BalanceDemo() {
  const [balance, setBalance] = React.useState(12840)
  return (
    <div className="flex flex-col items-center gap-4">
      <NumberRoll
        value={balance}
        trend
        format={{ style: "currency", currency: "USD", maximumFractionDigits: 0 }}
        className="text-4xl font-medium tracking-[-0.03em]"
      />
      <div className="flex gap-2">
        <Button variant="outline" size="sm" onClick={() => setBalance((b) => b - 1840)}>
          <MinusIcon /> Refund $1,840
        </Button>
        <Button variant="outline" size="sm" onClick={() => setBalance((b) => b + 2415)}>
          <PlusIcon /> Payment $2,415
        </Button>
      </div>
    </div>
  )
}
```

### Stepper

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

```tsx
function SeatCounter() {
  const [seats, setSeats] = React.useState(12)
  return (
    <div className="flex items-center gap-3 rounded-xl border border-border bg-surface px-4 py-3 shadow-raised">
      <div className="flex-1">
        <p className="text-sm font-medium text-fg">Seats</p>
        <p className="text-xs text-fg-muted">$24 per seat per month</p>
      </div>
      <Button variant="outline" size="icon-sm" aria-label="Remove seat" onClick={() => setSeats((s) => Math.max(1, s - 1))}>
        <MinusIcon />
      </Button>
      <NumberRoll value={seats} className="w-8 justify-center text-lg font-medium" />
      <Button variant="outline" size="icon-sm" aria-label="Add seat" onClick={() => setSeats((s) => s + 1)}>
        <PlusIcon />
      </Button>
    </div>
  )
}
```

### Locale

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

```tsx
<NumberRoll value={49200.5} locale="de-DE" format={{ style: "currency", currency: "EUR" }} className="text-2xl font-medium" />
<NumberRoll value={49200.5} locale="en-IN" format={{ style: "currency", currency: "INR" }} className="text-2xl font-medium" />
```

## 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.

## FAQ

### 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`](https://ui.minidev.pro/docs/metric-ticker-board) does.

## Rules for generating code

- Use semantic tokens only (bg, surface, sunken, border, fg, fg-muted, fg-subtle, ink, accent, success, warning, danger). Never raw hex or palette steps like blue-500.
- Shadows only from the set: shadow-xs, shadow-sm, shadow-raised, shadow-md, shadow-lg, shadow-overlay.
- Numbers use tabular-nums. Dark mode is the `dark` class on <html>; components never branch on theme.

## Dependencies

- npm: `motion`

## Related

- [Credit Balance](https://ui.minidev.pro/docs/credit-balance/md): Compact credit balance pill with a small label and a large tabular figure. Shows remaining credits or usage balance for AI and pay-as-you-go apps.
- [Split Flap](https://ui.minidev.pro/docs/split-flap/md): Split-flap display that flips each character through the alphabet like a departure board, with a column ripple, tones, sizes and reduced motion support.
- [Flip Stat Board](https://ui.minidev.pro/docs/flip-stat-board/md): A stat board where each number counts up with digits that flip in on a spring once in view. Pass values and labels; reduced motion shows the final value.
- [Launch Countdown](https://ui.minidev.pro/docs/launch-countdown/md): A React launch countdown showing days, hours, minutes and seconds to a target time, with digits that slide in on each tick and a waitlist call to action.
- [Stats Counter](https://ui.minidev.pro/docs/stats-counter/md): A single stat that counts up from zero to its value once it is in view, with a label below. Combine several in a row for landing page metrics.
- [Light Provider](https://ui.minidev.pro/docs/light-provider/md): A page wide light source that follows the pointer and drifts when idle, driving shadows via CSS variables, plus a hairline, glass, metal and paper switcher.

---

All 557 components: https://ui.minidev.pro/llms.txt (full text: https://ui.minidev.pro/llms-full.txt).
