Skip to Content

Stats

Stats component: a list of statistics, each pairing a large value in the display face with a label. Show them plain, on a filled card panel, or with a rule down the left side. Built on Grid for metrics rows.

Installation

pnpm dlx shadcn@latest add @01orbital/stats

Usage

import {
  Stat,
  StatGroup,
  StatLabel,
  StatValue,
} from "@/components/stats/stats"

// The copy: change text here, not in the markup.
const COPY = {
  title: "Orbcore edge network",
  period: "Last 30 days",
} as const

// Every figure on the panel. The unit sits beside the number, muted.
const ITEMS = [
  { value: "99.99", unit: "%", label: "Uptime across every region" },
  { value: "38", unit: "ms", label: "Median response time" },
  { value: "2.4", unit: "B", label: "Requests served" },
  { value: "142", unit: "", label: "Edge locations online" },
] as const

// Four stats on one panel, split by hairlines: the group's 1px gap lets its
// border-colored ground show between the cells. Four across from 48rem, two
// by two from 40rem, stacked on a phone.
export default function StatsDemo() {
  return (
    <section className="grid w-full max-w-4xl gap-4 p-6">
      <div className="flex flex-wrap items-baseline justify-between gap-2">
        <h3 className="text-sm/5 font-medium">{COPY.title}</h3>
        <p className="font-mono text-xs/4 text-muted-foreground">
          {COPY.period}
        </p>
      </div>
      <StatGroup
        cols={4}
        gap="px"
        className="overflow-hidden rounded-xl border border-border bg-border"
      >
        {ITEMS.map(({ value, unit, label }) => (
          <Stat key={label} className="bg-background p-6">
            <StatValue className="tabular-nums">
              {value}
              {unit ? (
                <span className="text-muted-foreground">{unit}</span>
              ) : null}
            </StatValue>
            <StatLabel>{label}</StatLabel>
          </Stat>
        ))}
      </StatGroup>
    </section>
  )
}

This example installs with everything it uses:

pnpm dlx shadcn@latest add @01orbital/stats-demo

Examples

Sleep Weekstats-sleep-week

Stats example: a ruled stat group of three weekly sleep figures on a summary card. Shows the stats parts inside a card for health and tracking dashboards.

pnpm dlx shadcn@latest add @01orbital/stats-sleep-week

Midnight Repair Ledgerstats-midnight-repair-ledger

Stats example: a compact two-by-two repair report built from the stats parts. Shows four labeled figures in a small ledger, for service summaries and status reports.

pnpm dlx shadcn@latest add @01orbital/stats-midnight-repair-ledger

Anatomy

Stats is built from 4 parts. In the example they nest like this:

StatGroup
└─ Stat
   ├─ StatValue
   └─ StatLabel
  • StatGroup: A list of Stat items laid out by Grid, rendered as a ul. It defaults to 3 columns and the large gap. Like Grid, its columns follow the width it is given, so size its parent to narrow it. className lands on the list.
  • Stat: One figure and its label, as an li inside StatGroup. Holds a StatValue and a StatLabel, stacked with 8px gaps.
  • StatValue: The figure itself, such as a number or a percentage, at 32px in the body font.
  • StatLabel: The caption under the figure: what it measures, in a few words. Small muted text, 14px on a 20px line, so the number carries the weight. Longer explanation belongs in the section's lead or a note, not here.

API reference

StatGroup

A list of Stat items laid out by Grid, rendered as a ul. It defaults to 3 columns and the large gap. Like Grid, its columns follow the width it is given, so size its parent to narrow it. className lands on the list.

Prop

Type

It also accepts the HTML attributes of the element it renders.

Stat

One figure and its label, as an li inside StatGroup. Holds a StatValue and a StatLabel, stacked with 8px gaps.

card sets it on a filled, rounded panel with 32px padding. rule draws a line down its left side.

Prop

Type

It also accepts the HTML attributes of the element it renders.

StatValue

The figure itself, such as a number or a percentage, at 32px in the body font.

It accepts the HTML attributes of the element it renders.

StatLabel

The caption under the figure: what it measures, in a few words. Small muted text, 14px on a 20px line, so the number carries the weight. Longer explanation belongs in the section's lead or a note, not here.

It accepts the HTML attributes of the element it renders.

Dependencies

npm: class-variance-authority, cn. The CLI installs them for you.

Requires these pieces. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:

Used in blocks

27 blocks are built with Stats; the first 12:

Last updated on