{title ? (
{head}
) : (
)}
:first-child]:pr-12"}>{children}
)
}
/** A number that counts up once when it first appears. */
export function CountUp({ value, format, ms = 1600 }: { value: number; format: (n: number) => string; ms?: number }) {
const [v, setV] = useState(0)
const done = useRef(false)
useEffect(() => {
if (done.current || matchMedia("(prefers-reduced-motion: reduce)").matches) {
setV(value)
return
}
done.current = true
let raf = 0
const t0 = performance.now()
const tick = (t: number) => {
const p = Math.min(1, (t - t0) / ms)
setV(value * (1 - Math.pow(1 - p, 3)))
if (p < 1) raf = requestAnimationFrame(tick)
}
raf = requestAnimationFrame(tick)
return () => cancelAnimationFrame(raf)
}, [value, ms])
// Serif figures are proportional: the final value, hidden, holds the width while it counts.
return (