Number 9: Rolling figures
Specification
- Catalogue
- No. 9 of 110
- Section
- Charts and numbers
- Interaction
- Text Animation
- Element
- Counter
- Preview
- Live component
- Imports
- react 19.3.1, @number-flow/react 0.6.2
- Added
Notes
Key numbers roll up to their value when they arrive, in tabular digits.
A figure that moves draws the eye to the one fact that matters. Fixed-width digits mean nothing around it shifts.
NumberFlow roll, respects reduced motion. Plain text on the server, rolls after mount. Tabular figures in a fixed-width box.
The names, figures and pictures in the demo are sample content; a real build uses the client's own.
Code
React and plain CSS"use client";
import { useEffect, useState } from "react";
import { Num } from "@/components/pieces/shared";
import type { LivePreviewProps } from "@/components/live/types";
import { PieceStage } from "@/components/pieces/stage/PieceStage";
import { useStageMode } from "@/components/pieces/stage/mode";
import "./rolling-figures.css";
const FIGURES = [
{ value: 1284, label: "Projects delivered", format: {} },
{ value: 98, label: "On time", format: {}, suffix: "%" },
{ value: 4.9, label: "Average rating", format: { minimumFractionDigits: 1, maximumFractionDigits: 1 } },
];
function RollingFiguresDemo() {
// A resting card shows the final figures from the first paint.
const { still } = useStageMode();
const [shown, setShown] = useState(still);
useEffect(() => {
const id = window.setTimeout(() => setShown(true), 250);
return () => window.clearTimeout(id);
}, []);
return (
<div className="dm">
<div className="dm-figures">
{FIGURES.map((f) => (
<div key={f.label} className="dm-figure">
<strong>
<Num value={shown ? f.value : 0} format={f.format} suffix={f.suffix} />
</strong>
<span>{f.label}</span>
</div>
))}
</div>
</div>
);
}
export default function RollingFiguresEntry(props: LivePreviewProps) {
return (
<PieceStage {...props} label="Rolling figures" sample replay>
<RollingFiguresDemo />
</PieceStage>
);
}