Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

AnimatedNumber

A number that tweens smoothly to its target value — a count-up roll for live dashboard KPIs like attendee scans, throughput, or revenue. On first reveal it counts from 0; on every update it rolls from the prior value to the new one.

Import

import { AnimatedNumber } from "@roger-emerson/ploxum-primitives";

Usage

<AnimatedNumber value={12480} />
 
// custom formatter — currency, percent, units
<AnimatedNumber
  format={(n) => n.toLocaleString(undefined, { style: "currency", currency: "USD", maximumFractionDigits: 0 })}
  value={184500}
/>
 
// live KPI — pass a new value and it rolls from the last one
<AnimatedNumber value={liveCount} />

Props

PropTypeDefaultDescription
valuenumberTarget value to count toward. Required.
fromnumberprev value, else 0Starting value for the tween. Defaults to the previous value, or 0 on first mount.
format(n: number) => string(n) => Math.round(n).toLocaleString()Maps the tweened value to display text.
durationnumber0.6Tween length in seconds.
classNamestringMerged onto the rendered span.
refRef<HTMLSpanElement>Ref to the <span>.

The span carries aria-label set to the formatted target value, so assistive tech announces the destination, not the intermediate roll.

Design rules

  • KPI display only — never use it for alert, status, or validation values. Per the motion hard-rules, critical metric updates never animate; render those instantly with a plain <span>.
  • Respects prefers-reduced-motion — when reduced, the value snaps to its target with no tween.
  • Uses tabular numerals so digits don't reflow width as they roll.
  • The roll uses easings.outQuart (decelerating) — it settles into the value rather than overshooting, keeping data legible.

Storybook

Primitives/AnimatedNumber ↗