Number Counter
FreeNewA numeric-row presentation: compact icons, animated values, prefixes, suffixes and captions supplied through React props.
Installation
pnpm dlx shadcn@latest add @viewport/number-counter
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above.
"use client";
import { useState } from "react";
import { Clock3, Globe2, Handshake, ShoppingCart } from "lucide-react";
import { NumberCounter, type NumberCounterItem } from "@/components/viewport/number-counter";
const store: NumberCounterItem[] = [
{ id: "orders", value: 123.45, decimals: 2, prefix: "$", suffix: "+", caption: "Orders verified", icon: <Handshake strokeWidth={1.5} /> },
{ id: "catalog", value: 20456, caption: "items in our catalog", icon: <ShoppingCart strokeWidth={1.5} /> },
{ id: "delivery", value: 2, suffix: " Days", caption: "average delivery time", icon: <Clock3 strokeWidth={1.5} /> },
{ id: "countries", value: 195, caption: "countries we ship to", icon: <Globe2 strokeWidth={1.5} /> },
];
const views = [
{ id: "store", label: "Online store" },
{ id: "color", label: "Colored numbers" },
] as const;
export default function NumberCounterDemo() {
const [view, setView] = useState<(typeof views)[number]["id"]>("store");
return (
<div className="w-full max-w-5xl min-w-0">
<div role="group" aria-label="Counter style" className="mb-5 flex justify-center gap-2">
{views.map((option) => (
<button key={option.id} type="button" aria-pressed={view === option.id} onClick={() => setView(option.id)} className="rounded-md px-3 py-1.5 text-xs font-medium text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring aria-pressed:bg-foreground aria-pressed:text-background">
{option.label}
</button>
))}
</div>
{view === "store"
? <NumberCounter title="Online Store in Numbers" counters={store} />
: <NumberCounter title="Our numbers" counters={store.map((item, i) => ({ ...item, color: ["#d63f37", "#198e5e", "#1b72bd", "#a266ba"][i] }))} />}
</div>
);
}Props
| Prop | Type | Default |
|---|---|---|
| counters* | NumberCounterItem[] | — |
| title | string | — |
| layout | "grid" | "row" | "grid" |
| columns | 2 | 3 | 4 | 4 |
| animation | "easeout" | "linear" | "none"An eased count-up, a linear count or an immediate final value. | "easeout" |
| duration | number | 2 |
| stagger | number | 0 |
| locale | string | "en-US" |
| separator | boolean | true |
| background | string | "#fff" |
| textColor | string | "#111" |
| numbersColor | string | "#1686ff" |
| captionsColor | string | — |
| iconsColor | string | "#8a8a8a" |
| className | string | — |
Accessibility
- A description list pairs each caption with its final value.
- Visible digits count on entry without announcing every frame or shifting width.
- Reduced motion shows the final value at once.