Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Number Counter

FreeNew

A 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.

number-counter-demo.tsx
"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

PropTypeDefault
counters*NumberCounterItem[]—
titlestring—
layout"grid" | "row""grid"
columns2 | 3 | 44
animation"easeout" | "linear" | "none"

An eased count-up, a linear count or an immediate final value.

"easeout"
durationnumber2
staggernumber0
localestring"en-US"
separatorbooleantrue
backgroundstring"#fff"
textColorstring"#111"
numbersColorstring"#1686ff"
captionsColorstring—
iconsColorstring"#8a8a8a"
classNamestring—

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.