Animated Number
Transitions changing values with digit rolls or continuous numeric interpolation.
Contract
TRAnimatedNumber displays a number supplied by application state. It does not own a timer or counter. The default roll animation moves changed digits in the value trend, while count interpolates the numeric value before applying the same locale-aware format. The first render is static so server rendering and hydration show the final value immediately.
| Axis | Values | Default |
|---|---|---|
animation | roll, count | roll |
duration | non-negative milliseconds | 600 |
rollDirection | auto, up, down | auto |
format | Intl.NumberFormatOptions | decimal format |
locale | Intl.LocalesArgument | runtime locale |
Install
pnpm add @tinyrack/uiScroll inside the code area to read long lines.
Styles
@import '@tinyrack/ui/components/animated-number.css';Scroll inside the code area to read long lines.
Imports
import { TRAnimatedNumber } from '@tinyrack/ui/components/animated-number';Scroll inside the code area to read long lines.
Playground
Usage
Changing metric permalink
Update the controlled value to roll each changed digit in the overall value direction.
Examples
Roll and count permalink
Use roll when individual digit movement matters. Use count when the path between two numeric values should remain visible.
Locale-aware formats permalink
Currency, percent, unit, grouping, signs, and decimal characters come from Intl.NumberFormat.
Forced roll direction permalink
Keep auto for ordinary metrics. Force up or down when the visual direction has domain meaning, such as a countdown-style display.
API
valueis required. Updating it starts the selected animation; mounting the component does not animate from zero.animation="roll"aligns integer digits from the right and fractional digits from the left.rollDirectionaffects only this mode.animation="count"formats the eased intermediate numeric value on each frame.durationcontrols both modes in milliseconds.0and negative values settle immediately; a non-finite duration falls back to600.formatandlocaleare passed toIntl.NumberFormat. Changing either setting settles the current value immediately instead of animating between incompatible formats.NaNand infinite values are also displayed without animation.- The visual digit layers are hidden from assistive technology, leaving one formatted text value. Changes are not live announcements by default. Pass native
aria-livewith the valuepoliteonly when the update should be announced. - When
prefers-reduced-motionisreduce, active movement is canceled and the final value is preserved. Native span props, event handlers, styles, class names, and React 19 refs are forwarded.
| CSS token | Default | Purpose |
|---|---|---|
--tr-animated-number-duration | --tinyrack-duration-number | Roll and character transition duration when the duration prop is omitted |
--tinyrack-duration-number | 600ms | Foundation timing for readable number transitions |