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

Stat

FreeNew

One number with its label and its change, where the arrow shows direction and the color shows whether that is good.

Installation

pnpm dlx shadcn@latest add @viewport/stat

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above.

stat-demo.tsx
import { Stat } from "@/components/viewport/stat";

export default function StatDemo() {
  return (
    <div className="grid w-full max-w-lg grid-cols-1 divide-y divide-border rounded-2xl border border-border bg-card sm:grid-cols-3 sm:divide-x sm:divide-y-0">
      <Stat className="p-5" label="Pipeline value" value="$482k" change="12.4%" trend="up" hint="vs last month" />
      <Stat className="p-5" label="Churn rate" value="1.8%" change="0.6 pts" trend="down" sentiment="positive" hint="vs last month" />
      <Stat className="p-5" label="Avg. reply time" value="3h 12m" change="No change" trend="flat" />
    </div>
  );
}

Props

PropTypeDefault
label*string

What is measured, e.g. "Open deals".

—
value*React.ReactNode

The formatted number, e.g. "$48.2k".

—
changestring

The change against the comparison period, already formatted, e.g. "12.4%".

—
trend"up" | "down" | "flat"

The direction of the change. It picks the arrow.

"flat"
sentiment"positive" | "negative" | "neutral"

Whether the change is good news. A falling churn rate is `positive` although it points down. Defaults to positive for up and negative for down.

—
hintstring

What the change is compared with, e.g. "vs last month".

—

Accessibility

  • The direction is written out for screen readers.
  • Tabular numerals keep values aligned across a row.
  • Server component with no client JavaScript.