Animated number
TypographyA smooth, interruptible number transition for totals, metrics and small moments of progress.
Try it
Add to your project
npx shadcn@latest add https://luv-jeri.github.io/cojeev-ui/r/animated-number.jsonThe command includes the component’s shared dependencies. Your project keeps editable source files.
Include the complete example
This example also composes button, typography. Install its parts together:
npx shadcn@latest add https://luv-jeri.github.io/cojeev-ui/r/animated-number.json https://luv-jeri.github.io/cojeev-ui/r/button.json https://luv-jeri.github.io/cojeev-ui/r/typography.jsonUsing animated number
Pass a numeric value; updates animate from the current displayed value. The initial render shows the actual total. Non-finite values show the fallback (an em dash by default), never a fabricated zero.
Use locale and format for currency, percentages or compact notation. Reserve enough width for the largest expected value.
Use an external live status only when the update needs announcing.
API
Compose the exported parts below. The prop types are read from the React source during the registry build.
Native element or underlying primitive props are inherited where declared, including accessible labels, event handlers and refs.
AnimatedNumberProps
| Prop | Type | Required |
|---|---|---|
value | number | Yes |
locale | string | No |
format | Intl.NumberFormatOptions | No |
durationTransition time in milliseconds, bounded to 0–2000 and scaled by Flow speed. | number | No |
treatmentCount through values, roll each digit, or count in twelve drawn poses. | "count" | "roll" | "steps" | No |
fromOptional starting value for the first visible entrance. SSR always shows the final value. | number | No |
fallbackText for NaN or infinite values; never presents missing data as zero. | string | No |
Accessibility
Assistive technology receives the final formatted value without every intermediate animation frame.
Reduced motion, global Off and offscreen updates settle immediately.
States and appearance
For conditional content, keep a MotionPresence boundary around keyed MotionSurface children. The shared entrance and exit states work with native primitives and respect your motion preference.
Try pointer and keyboard interaction, and switch the appearance control in the navigation to compare light and dark mode. Motion respects reduced motion preferences.