Metric Card
KPI stat card for dashboards and analytics: a metric name, a large tabular value, an optional outline badge with a trend-up or trend-down icon and screen-reader label, and an optional description line.
pnpm dlx shadcn add @01orbital/metric-cardimport type { ComponentProps, ReactNode } from "react"
import { TrendDownIcon, TrendUpIcon } from "@phosphor-icons/react/dist/ssr"
import { Badge } from "@/components/ui/badge"
import {
Card,
CardAction,
CardDescription,
CardHeader,
} from "@/components/ui/card"
type MetricCardProps = Omit<
ComponentProps<typeof Card>,
"title" | "children" | "size"
> & {
/**
* The stock `Card` size: `default` puts 24px of space around and between
* the card's parts, `sm` 16px.
*/
size?: ComponentProps<typeof Card>["size"]
/** The metric's name, shown as a small muted label at the top. */
name: ReactNode
/** The figure itself, in large type with tabular numerals. */
value: ReactNode
/**
* A change badge in the top-right corner. `value` is its visible text,
* `trend` picks an up or down arrow, and `label` is read to screen readers
* before the value, since the arrow is hidden from them.
*/
change?: { value: ReactNode; trend: "up" | "down"; label: string }
/** A line of muted text under the value. */
description?: ReactNode
}
/**
* A card that shows one metric on a dashboard: its name, its value in large
* type, an optional change badge and an optional line of text below.
*
* It takes no children. `className` and other props land on the `Card`.
*/
function MetricCard({
name,
value,
change,
description,
...props
}: MetricCardProps) {
return (
<Card data-slot="metric-card" {...props}>
<CardHeader>
<CardDescription>{name}</CardDescription>
{change && (
<CardAction>
<Badge variant="outline">
{change.trend === "up" ? (
<TrendUpIcon
weight="light"
aria-hidden="true"
data-icon="inline-start"
/>
) : (
<TrendDownIcon
weight="light"
aria-hidden="true"
data-icon="inline-start"
/>
)}
<span className="sr-only">{change.label}</span>
{change.value}
</Badge>
</CardAction>
)}
<p className="text-2xl font-medium tabular-nums">{value}</p>
{description != null && (
<CardDescription>{description}</CardDescription>
)}
</CardHeader>
</Card>
)
}
export { MetricCard }
import { MetricCard } from "@/components/card/metric-card"
// The demo's words. Change copy here, not in the markup.
const COPY = {
name: "Total visitors",
value: "248.5k",
change: "12.4%",
up: "Up",
period: "vs last period",
} as const
export default function MetricCardDemo() {
return (
<>
{/* 276px: one column of the four-up dashboard row this card is made
for (72rem less three 16px gaps, over four). The card sets its own
width: a centred grid item otherwise shrinks to its content. */}
<MetricCard
className="w-full max-w-[17.25rem]"
name={COPY.name}
value={COPY.value}
change={{ value: COPY.change, trend: "up", label: COPY.up }}
description={COPY.period}
/>
</>
)
}
Usage
import { MetricCard } from "@/components/card/metric-card"
// The demo's words. Change copy here, not in the markup.
const COPY = {
name: "Total visitors",
value: "248.5k",
change: "12.4%",
up: "Up",
period: "vs last period",
} as const
export default function MetricCardDemo() {
return (
<>
{/* 276px: one column of the four-up dashboard row this card is made
for (72rem less three 16px gaps, over four). The card sets its own
width: a centred grid item otherwise shrinks to its content. */}
<MetricCard
className="w-full max-w-[17.25rem]"
name={COPY.name}
value={COPY.value}
change={{ value: COPY.change, trend: "up", label: COPY.up }}
description={COPY.period}
/>
</>
)
}Examples
Dispute Ratemetric-card-dispute-rate
Example of the Metric Card: a falling dispute rate stat on a navy ground, with a note and two supporting figures. The metric card is a KPI stat tile for dashboards and analytics.
pnpm dlx shadcn add @01orbital/metric-card-dispute-rateimport { MetricCard } from "@/components/card/metric-card"
import { Eyebrow } from "@/components/eyebrow/eyebrow"
import {
Stat,
StatGroup,
StatLabel,
StatValue,
} from "@/components/stats/stats"
import { Text } from "@/components/text/text"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import { Separator } from "@/components/ui/separator"
// The copy: change text here, not in the markup.
const COPY = {
eyebrow: "PENNYWELL / RISK OPERATIONS",
period: "OCT 2026",
name: "Card disputes",
value: "0.18%",
change: "0.06 pp",
changeLabel: "Decreased by ",
description: "18 disputed payments out of 10,000 settled.",
body: "Down from 0.24% in September. We measure disputes by settlement month, including cases still under review.",
} as const
const FIGURES = [
{ term: "Internal alert threshold", value: "0.50%" },
{ term: "Open cases", value: "6" },
] as const
/** A Metric Card showing a falling dispute rate on a navy ground, with a note and two supporting figures. */
export default function MetricCardDisputeRate() {
return (
<Card className="w-full max-w-md rounded-2xl bg-background text-foreground shadow-none ring-0 [--card-spacing:--spacing(5)]">
<CardHeader className="flex justify-between gap-4">
<Eyebrow variant="caps" tone="ink" className="font-semibold">
{COPY.eyebrow}
</Eyebrow>
<Eyebrow variant="caps" tone="ink">
{COPY.period}
</Eyebrow>
</CardHeader>
<CardContent className="flex flex-col gap-5">
<MetricCard
name={COPY.name}
value={COPY.value}
change={{
value: COPY.change,
trend: "down",
label: COPY.changeLabel,
}}
description={COPY.description}
className="rounded-xl shadow-none ring-0"
/>
<Text className="text-sm/6">{COPY.body}</Text>
<Separator className="bg-current/20" />
<StatGroup cols={2} gap="sm">
{FIGURES.map((figure) => (
<Stat key={figure.term}>
<StatLabel className="order-first text-xs/5">
{figure.term}
</StatLabel>
<StatValue className="text-lg/7">{figure.value}</StatValue>
</Stat>
))}
</StatGroup>
</CardContent>
</Card>
)
}
import { mergeProps } from "@base-ui/react/merge-props"
import { useRender } from "@base-ui/react/use-render"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
// default is a quiet 14px line, cased as written; icon puts a 16px icon in
// front of it; mono is a 12px uppercase mono label for spec-sheet designs;
// caps is the same size in a sans face. tone picks the ink: muted (the
// default) or the surrounding text color, for a label over art or on a dark
// island where muted-foreground is too quiet.
const eyebrowVariants = cva("", {
variants: {
/**
* The label style. `default` (the default) is a 14px line at weight 500,
* cased as written. `icon` is the same line with a 16px icon, placed
* first among the children, 12px before the words. `mono` is a 12px
* uppercase mono label at weight 500 with 0.12em letter spacing. `caps`
* is the same label in the sans face, for a brand and series label such
* as "Studio Neri / Clay school". The color comes from `tone`.
*/
variant: {
default: "text-sm/5 font-medium",
icon: "flex items-center gap-3 text-sm/5 font-medium [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
mono: "font-mono text-xs/5 font-medium tracking-[0.12em] uppercase",
caps: "text-xs/5 font-medium tracking-[0.12em] uppercase",
},
/**
* The ink. `muted` (the default) is `muted-foreground`. `ink` leaves the
* color to the surrounding text, for a label over art, on a dark island
* or anywhere the muted grey is too quiet to read.
*/
tone: {
muted: "text-muted-foreground",
ink: "",
},
},
defaultVariants: { variant: "default", tone: "muted" },
})
/**
* A short label set above a heading, such as a section name, rendered as a
* `<p>`. Leave 8px between it and the heading. Pass `render` to use another
* element.
*
* `default` is a 14px line at weight 500, cased as written. `icon` adds a
* 16px icon before the words: put the icon first, with `aria-hidden`. `mono`
* is a 12px uppercase mono label with 0.12em letter spacing; `caps` the same
* in the sans face, for a brand and series name such as "Studio Neri / Clay
* school". `tone="muted"` (the default) sets it in `muted-foreground`;
* `tone="ink"` takes the surrounding text color, for a label over art or on
* a dark island where the grey is too quiet.
*/
function Eyebrow({
className,
variant = "default",
tone = "muted",
render,
...props
}: useRender.ComponentProps<"p"> & VariantProps<typeof eyebrowVariants>) {
return useRender({
defaultTagName: "p",
render,
state: { slot: "eyebrow", variant, tone },
props: mergeProps<"p">(
{ className: cn(eyebrowVariants({ variant, tone }), className) },
props
),
})
}
export { Eyebrow, eyebrowVariants }
import type { ComponentProps, ReactNode } from "react"
import { TrendDownIcon, TrendUpIcon } from "@phosphor-icons/react/dist/ssr"
import { Badge } from "@/components/ui/badge"
import {
Card,
CardAction,
CardDescription,
CardHeader,
} from "@/components/ui/card"
type MetricCardProps = Omit<
ComponentProps<typeof Card>,
"title" | "children" | "size"
> & {
/**
* The stock `Card` size: `default` puts 24px of space around and between
* the card's parts, `sm` 16px.
*/
size?: ComponentProps<typeof Card>["size"]
/** The metric's name, shown as a small muted label at the top. */
name: ReactNode
/** The figure itself, in large type with tabular numerals. */
value: ReactNode
/**
* A change badge in the top-right corner. `value` is its visible text,
* `trend` picks an up or down arrow, and `label` is read to screen readers
* before the value, since the arrow is hidden from them.
*/
change?: { value: ReactNode; trend: "up" | "down"; label: string }
/** A line of muted text under the value. */
description?: ReactNode
}
/**
* A card that shows one metric on a dashboard: its name, its value in large
* type, an optional change badge and an optional line of text below.
*
* It takes no children. `className` and other props land on the `Card`.
*/
function MetricCard({
name,
value,
change,
description,
...props
}: MetricCardProps) {
return (
<Card data-slot="metric-card" {...props}>
<CardHeader>
<CardDescription>{name}</CardDescription>
{change && (
<CardAction>
<Badge variant="outline">
{change.trend === "up" ? (
<TrendUpIcon
weight="light"
aria-hidden="true"
data-icon="inline-start"
/>
) : (
<TrendDownIcon
weight="light"
aria-hidden="true"
data-icon="inline-start"
/>
)}
<span className="sr-only">{change.label}</span>
{change.value}
</Badge>
</CardAction>
)}
<p className="text-2xl font-medium tabular-nums">{value}</p>
{description != null && (
<CardDescription>{description}</CardDescription>
)}
</CardHeader>
</Card>
)
}
export { MetricCard }
import type { ComponentProps } from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
import { Grid, type GridProps } from "@/components/grid/grid"
/**
* 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.
*/
function StatGroup({
cols = 3,
gap = "lg",
...props
}: ComponentProps<"ul"> & {
/**
* The most columns, 3 by default. They step up as the list's space
* widens, the way `Grid`'s do.
*/
cols?: GridProps["cols"]
/**
* Space between stats: `xs` 8px, `sm` 16px, `md` 24px, `lg` 40px, `xl` 64px, `px` 1px, `none` 0. `lg`
* is the default.
*/
gap?: GridProps["gap"]
}) {
return (
<Grid
data-slot="stat-group"
render={<ul role="list" />}
cols={cols}
gap={gap}
// Grid's props are typed for its default div; this group renders a list.
{...(props as Omit<GridProps, "cols" | "gap">)}
/>
)
}
// card sets the stat on a filled panel; rule sets a line down its left side.
const statVariants = cva("grid content-start gap-2", {
variants: {
/**
* The stat style. `default` (the default) adds nothing. `card` sets it
* on a `rounded-xl` panel with 32px padding, filled with `muted`, or
* with `card` and `card-foreground` text in dark mode. `rule` draws a
* 1px line in `border` down its left side, 24px from the text.
*/
variant: {
default: "",
card: "rounded-xl bg-muted p-8 dark:bg-card dark:text-card-foreground",
rule: "border-l border-border pl-6",
},
},
defaultVariants: { variant: "default" },
})
/**
* 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.
*/
function Stat({
className,
variant = "default",
...props
}: ComponentProps<"li"> & VariantProps<typeof statVariants>) {
return (
<li
data-slot="stat"
data-variant={variant}
className={cn(statVariants({ variant }), className)}
{...props}
/>
)
}
/** The figure itself, such as a number or a percentage, at 32px in the body font. */
function StatValue({ className, ...props }: ComponentProps<"p">) {
return (
<p
data-slot="stat-value"
className={cn("text-[2rem]/10 tracking-tight", className)}
{...props}
/>
)
}
/**
* 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.
*/
function StatLabel({ className, ...props }: ComponentProps<"p">) {
return (
<p
data-slot="stat-label"
className={cn("text-sm/5 text-pretty text-muted-foreground", className)}
{...props}
/>
)
}
export { StatGroup, Stat, StatValue, StatLabel }
import { mergeProps } from "@base-ui/react/merge-props"
import { useRender } from "@base-ui/react/use-render"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
const GRID_DEFAULTS = { cols: 3, gap: "lg" } as const
// Columns follow the screen, stepping at 40rem and 48rem (and 64rem for six). Gap sizes read the shared --gap-*
// values in globals.css. The grid fills its parent's width: without that, a
// grid given `mx-auto` or set inside a centering parent shrinks to fit its
// content, and a part built on it that is a container collapses to nothing.
const containerGridVariants = cva("grid w-full grid-cols-1", {
variants: {
/**
* The most columns. Below 40rem of screen width the grid is one
* column (two for `6`); it steps up at 40rem and 48rem: `2` is two
* columns from 40rem, `3` two then three, `4` two then four, `5` three
* then five, and `6` three, then four, then six from 64rem. The default
* is 3.
*/
cols: {
1: "",
2: "sm:grid-cols-2",
3: "sm:grid-cols-2 md:grid-cols-3",
4: "sm:grid-cols-2 md:grid-cols-4",
5: "sm:grid-cols-3 md:grid-cols-5",
6: "grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6",
},
/**
* Space between items: `xs` 8px, `sm` 16px, `md` 24px, `lg` 40px, `xl` 64px, `px` 1px, `none` 0. `lg`
* is the default. The sizes are the `--gap-*` values in globals.css.
*/
gap: {
xs: "gap-(--gap-xs)",
sm: "gap-(--gap-sm)",
md: "gap-(--gap-md)",
lg: "gap-(--gap-lg)",
xl: "gap-(--gap-xl)",
px: "gap-px",
none: "gap-0",
},
},
defaultVariants: GRID_DEFAULTS,
})
type GridState = { slot: "grid" } & VariantProps<typeof containerGridVariants>
type GridProps = useRender.ComponentProps<"div", GridState> &
VariantProps<typeof containerGridVariants>
// className, render and every other prop go to the grid. To narrow a Grid,
// pass a `max-w-*` class or size its parent.
function Grid({
className,
cols = GRID_DEFAULTS.cols,
gap = GRID_DEFAULTS.gap,
render,
...props
}: GridProps) {
const grid = useRender({
defaultTagName: "div",
render,
state: { slot: "grid", cols, gap },
props: mergeProps<"div">(
{ className: cn(containerGridVariants({ cols, gap }), className) },
props
),
})
return grid
}
export { Grid, type GridProps }
import { mergeProps } from "@base-ui/react/merge-props"
import { useRender } from "@base-ui/react/use-render"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
// The paragraph under a Heading or Subheading, in a hero or a section
// header. No width of its own: give it one with a `max-w-*` class when the
// layout wants it. Inherits the surrounding ink, so it reads over art;
// muted steps it down on a flat ground.
const textVariants = cva("w-full min-w-0 text-pretty", {
variants: {
/**
* The text color. `default` (the default) keeps the inherited color.
* `muted` uses `muted-foreground`.
*/
variant: {
default: "",
muted: "text-muted-foreground",
},
/**
* The text size: `md` (the default) 16px with 28px lines, `lg` 18px
* with 32px lines, the lead under a page headline.
*/
size: {
md: "text-base/7",
lg: "text-lg/8",
},
},
defaultVariants: { variant: "default", size: "md" },
})
/**
* The paragraph under a heading, a `p` by default. For several paragraphs,
* pass `render={<div />}` and put your own `p` elements inside.
*
* `size` sets the text: `md` (the default) 16px with 28px lines, `lg` 18px
* with 32px lines for the lead under a page headline. `variant="muted"`
* uses the muted text color; the default inherits the ink around it.
*/
function Text({
className,
variant = "default",
size = "md",
render,
...props
}: useRender.ComponentProps<"p"> & VariantProps<typeof textVariants>) {
return useRender({
defaultTagName: "p",
render,
state: { slot: "text", variant, size },
props: mergeProps<"p">(
{ className: cn(textVariants({ variant, size }), className) },
props
),
})
}
export { Text }
API reference
A card that shows one metric on a dashboard: its name, its value in large type, an optional change badge and an optional line of text below.
It takes no children. className and other props land on the Card.
Prop
Type
It also accepts the HTML attributes of the element it renders.
Dependencies
npm: @phosphor-icons/react. The CLI installs them for you.
Registry pieces it installs with it: