Rolling Number
Spring-driven digit wheel counter with velocity blur, Intl.NumberFormat and custom formatter support, and direction control.
$1,248.50
Customize
Installation
npx shadcn@latest add @kinetic/rolling-numberUsage
Pass a numeric value and update it over time. Each place value rolls independently on a spring while keeping tabular alignment and clean screen-reader output.
import { RollingNumber } from "@/components/kinetic/ui/rolling-number";
interface MetricValueProps {
readonly amount: number;
}
export function MetricValue({ amount }: MetricValueProps) {
return (
<RollingNumber
as="p"
value={amount}
format={{ style: "currency", currency: "USD" }}
className="text-3xl font-semibold tracking-tight"
/>
);
}Formatting and locales
Pass Intl.NumberFormatOptions to format along with an optional locale (defaults to "en-US") to tokenize grouping separators, decimals, signs, and currency symbols accurately via formatToParts. You can also pass a custom (value: number) => string function or attach prefix and suffix.
import { RollingNumber } from "@/components/kinetic/ui/rolling-number";
interface LocalizedPriceProps {
readonly total: number;
}
export function LocalizedPrice({ total }: LocalizedPriceProps) {
return (
<div className="space-y-2">
<RollingNumber
value={total}
locale="vi-VN"
format={{ style: "currency", currency: "VND", maximumFractionDigits: 0 }}
/>
<RollingNumber
value={total}
format={(v) => `${v.toFixed(1)} ms`}
direction="shortest"
/>
</div>
);
}Entrance and imperative control
Provide from with trigger="mount", trigger="inView", or trigger="manual" to roll in from a starting number. Attach a RollingNumberHandle ref to call play() or reset() on demand.
import { useRef } from "react";
import { RollingNumber, type RollingNumberHandle } from "@/components/kinetic/ui/rolling-number";
interface RevenueCounterProps {
readonly target: number;
}
export function RevenueCounter({ target }: RevenueCounterProps) {
const ref = useRef<RollingNumberHandle>(null);
return (
<div className="space-y-3">
<RollingNumber
ref={ref}
from={0}
value={target}
trigger="manual"
format={{ style: "currency", currency: "USD" }}
/>
<div className="flex gap-2">
<button type="button" onClick={() => ref.current?.play()}>
Play
</button>
<button type="button" onClick={() => ref.current?.reset()}>
Reset
</button>
</div>
</div>
);
}Motion preferences
speed, blurPx (clamped at 8px max), stiffness, and damping scale with the global Kinetic tempo. Under reduced motion, RollingNumber cancels any active spin immediately, snaps to the target value without blur or width animation, and calls onComplete. Visual wheels stay aria-hidden="true" while an .sr-only span exposes the formatted text; enable announceChanges to announce updates politely with role="status".
API Reference
RollingNumber
Spring-driven numeric counter that rolls individual digit wheels on value updates or entrance triggers.
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | - | Target numeric value to format and display. |
format | Intl.NumberFormatOptions | ((value: number) => string) | - | Intl.NumberFormat options object or custom formatting callback. |
locale | Intl.LocalesArgument | "en-US" | Locale passed to Intl.NumberFormat when formatting numbers. |
direction | "auto" | "up" | "down" | "shortest" | "auto" | Digit roll direction strategy when values change. |
speed | number | 1 | Speed multiplier clamped between 0.25 and 4. |
blurPx | number | 2.4 | Peak vertical motion blur in pixels while spinning (max 8px). |
from | number | - | Optional initial value for entrance roll animations. |
prefix | string | - | Static prefix rendered before the formatted number. |
suffix | string | - | Static suffix rendered after the formatted number. |
stiffness | number | 340 | Spring stiffness for each digit wheel (clamped 60 to 1200). |
damping | number | 30 | Spring damping for each digit wheel (clamped 8 to 120). |
animateWidth | boolean | true | Smoothly animates container width when digit count or symbols change. |
animateMountDigits | boolean | true | Animates newly added place-value digits into view. |
trigger | "mount" | "inView" | "manual" | "mount" | When entrance rolling begins if from is provided. |
as | "span" | "p" | "div" | "h1" | "h2" | "h3" | "h4" | "span" | Semantic HTML element rendered as the outer wrapper. |
announceChanges | boolean | false | Announces value updates politely via role='status' on the sr-only node. |
onComplete | () => void | - | Called once all rolling digit wheels settle on the target value. |