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.
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 {
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>
)
}
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
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>
/**
* 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.
*
* 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 }
Installation
pnpm dlx shadcn@latest add @01orbital/statsnpx shadcn@latest add @01orbital/statsyarn dlx shadcn@latest add @01orbital/statsbunx --bun shadcn@latest add @01orbital/statsUsage
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-demonpx shadcn@latest add @01orbital/stats-demoyarn dlx shadcn@latest add @01orbital/stats-demobunx --bun shadcn@latest add @01orbital/stats-demoExamples
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.
import {
Stat,
StatGroup,
StatLabel,
StatValue,
} from "@/components/stats/stats"
// Palette: Oatmeal Night · Plum, dark.
// The copy: change text here, not in the markup.
const COPY = {
title: "Drowse / Your week",
dates: "OCT 26–NOV 1",
footnote:
"From your sleep diary. Averages use the six nights you logged; Drowse does not estimate missing nights.",
} as const
const STATS = [
{ value: "7h 42m", label: "Average sleep", note: "↑ 26m from last week" },
{ value: "23:18", label: "Average bedtime", note: "Goal: before 23:30" },
{ value: "6 / 7", label: "Nights logged", note: "Saturday is missing" },
] as const
/** A ruled StatGroup of three weekly sleep figures on a summary card. */
export default function StatsSleepWeek() {
return (
<section className="bg-background p-7 text-foreground">
<div className="mb-8 flex flex-wrap items-baseline justify-between gap-2">
<h3 className="text-xl font-medium">{COPY.title}</h3>
<p className="font-mono text-xs">{COPY.dates}</p>
</div>
<StatGroup
cols={3}
gap="md"
className="grid-cols-1 min-[26rem]:grid-cols-3"
>
{STATS.map((stat, i) => (
<Stat key={stat.label} variant="rule">
<StatValue className="tabular-nums">{stat.value}</StatValue>
<StatLabel className="text-sm/6">
{stat.label}
<br />
<span
className={
i === 0 ? "text-foreground" : "text-muted-foreground"
}
>
{stat.note}
</span>
</StatLabel>
</Stat>
))}
</StatGroup>
<p className="mt-8 border-t border-border pt-4 text-xs/5 text-muted-foreground">
{COPY.footnote}
</p>
</section>
)
}
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
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>
/**
* 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.
*
* 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 }
pnpm dlx shadcn@latest add @01orbital/stats-sleep-weeknpx shadcn@latest add @01orbital/stats-sleep-weekyarn dlx shadcn@latest add @01orbital/stats-sleep-weekbunx --bun shadcn@latest add @01orbital/stats-sleep-weekMidnight 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.
import { Eyebrow } from "@/components/eyebrow/eyebrow"
import {
Stat,
StatGroup,
StatLabel,
StatValue,
} from "@/components/stats/stats"
import { Subheading } from "@/components/subheading/subheading"
import { Grain } from "@/components/texture/grain"
// Palette: Remix Graphite, dark.
// The copy: change text here, not in the markup.
const COPY = {
eyebrow: "The repair report / 2026",
title: "Built to stay in use.",
} as const
const STATS = [
{ value: "1,204", label: "Garments repaired" },
{ value: "82%", label: "Returned to daily wear" },
{ value: "16", label: "Local repair partners" },
{ value: "9 yrs", label: "Average garment age" },
] as const
/** A compact two-by-two repair report. */
export default function StatsMidnightRepairLedger() {
return (
<div className="relative isolate w-full overflow-hidden bg-background text-foreground">
<Grain variant="single" opacity={0.2} />
<div className="relative grid gap-8 p-6 sm:p-9">
<Eyebrow className="text-primary">{COPY.eyebrow}</Eyebrow>
<Subheading className="max-w-xs">{COPY.title}</Subheading>
<StatGroup cols={1} gap="none" className="grid-cols-2 gap-x-5 gap-y-8">
{STATS.map((stat) => (
<Stat
key={stat.label}
variant="rule"
className="border-border pl-4"
>
<StatValue className="text-3xl text-primary sm:text-4xl">
{stat.value}
</StatValue>
<StatLabel className="text-sm">{stat.label}</StatLabel>
</Stat>
))}
</StatGroup>
</div>
</div>
)
}
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 eyebrowVariants = cva("text-eyebrow", {
variants: {
/**
* `default` is a 14px/20px label. `icon` adds a row with a 16px icon
* and a 12px gap; put the icon first and give it `aria-hidden`.
* `mono` and `caps` are 12px/20px uppercase labels with 0.12em
* tracking, in the mono and inherited faces respectively.
*/
variant: {
default: "text-sm/5 font-medium text-eyebrow",
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",
},
},
defaultVariants: { variant: "default" },
})
/**
* A short label above a heading, rendered as a `<p>` at weight 500.
* The default is 14px/20px in the kit's eyebrow color. The surrounding
* layout controls the space to the heading. Use `className` to customize
* the typography or color, and `render` to change the element.
*/
function Eyebrow({
className,
variant = "default",
render,
...props
}: useRender.ComponentProps<"p"> & VariantProps<typeof eyebrowVariants>) {
return useRender({
defaultTagName: "p",
render,
state: { slot: "eyebrow", variant },
props: mergeProps<"p">(
{ className: cn(eyebrowVariants({ variant }), className) },
props
),
})
}
export { Eyebrow, eyebrowVariants }
import { cn } from "cn"
// Paper grain: an SVG turbulence filter as a data URI.
const PAPER_GRAIN = `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='250' height='250' viewBox='0 0 100 100'%3E%3Cfilter id='n' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='turbulence' baseFrequency='1.4' numOctaves='1' seed='2' stitchTiles='stitch' result='n'/%3E%3CfeComponentTransfer result='g'%3E%3CfeFuncR type='linear' slope='4' intercept='1'/%3E%3CfeFuncG type='linear' slope='4' intercept='1'/%3E%3CfeFuncB type='linear' slope='4' intercept='1'/%3E%3C/feComponentTransfer%3E%3CfeColorMatrix type='saturate' values='0' in='g'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E")`
// Sandpaper grain: an SVG turbulence filter as a data URI.
const SANDPAPER_GRAIN = `url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200' viewBox='0 0 100 100'%3E%3Cfilter id='n' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='turbulence' baseFrequency='2.2' numOctaves='2' seed='5' stitchTiles='stitch' result='n'/%3E%3CfeComponentTransfer result='g'%3E%3CfeFuncR type='linear' slope='2.5' intercept='0.8'/%3E%3CfeFuncG type='linear' slope='2.5' intercept='0.8'/%3E%3CfeFuncB type='linear' slope='2.5' intercept='0.8'/%3E%3C/feComponentTransfer%3E%3CfeColorMatrix type='saturate' values='0' in='g'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E")`
// Single noise: an SVG turbulence filter as a data URI.
const SINGLE_NOISE = `url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E")`
// Square grain: an SVG turbulence filter as a data URI.
const SQUARE_GRAIN = `url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22200%22%20height=%22200%22%20viewBox=%220%200%20100%20100%22%3E%3Cfilter%20id=%22n%22%20color-interpolation-filters=%22sRGB%22%3E%3CfeTurbulence%20type=%22turbulence%22%20baseFrequency=%222.1%22%20numOctaves=%223%22%20seed=%2211%22%20stitchTiles=%22stitch%22%20result=%22n%22/%3E%3CfeComponentTransfer%20result=%22g%22%3E%3CfeFuncR%20type=%22linear%22%20slope=%225.5%22%20intercept=%221.4%22/%3E%3CfeFuncG%20type=%22linear%22%20slope=%225.5%22%20intercept=%221.4%22/%3E%3CfeFuncB%20type=%22linear%22%20slope=%225.5%22%20intercept=%221.4%22/%3E%3C/feComponentTransfer%3E%3CfeColorMatrix%20type=%22saturate%22%20values=%220%22%20in=%22g%22/%3E%3C/filter%3E%3Crect%20width=%22100%%22%20height=%22100%%22%20filter=%22url(%23n)%22/%3E%3C/svg%3E")`
type Intensity = "fine" | "default" | "rich"
// One scale for every texture; `default` is the unscaled value.
const INTENSITY_MULT: Record<Intensity, number> = {
fine: 0.6,
default: 1,
rich: 1.45,
}
const alpha = (base: number, mult: number) => (base * mult).toFixed(4)
// Four grain treatments; each paints a single texture layer.
// Full-bleed art layer — drop inside a `relative` parent; sits behind content.
/** The texture treatment painted by `Grain`. */
type GrainVariant =
// Stylized paper-look variants — heavier filter chain than plain noise.
"paper" | "sandpaper" | "square" | "single"
type Layer = {
src: string
size: string
opacity: number
blend: "overlay" | "soft-light"
}
const BLEND_CLASS: Record<Layer["blend"], string> = {
overlay: "mix-blend-overlay",
"soft-light": "mix-blend-soft-light",
}
const VARIANT_TEXTURES: Record<GrainVariant, Layer> = {
paper: {
src: PAPER_GRAIN,
size: "250px",
opacity: 0.25,
blend: "overlay",
},
sandpaper: {
src: SANDPAPER_GRAIN,
size: "200px",
opacity: 0.25,
blend: "overlay",
},
square: {
src: SQUARE_GRAIN,
size: "200px",
opacity: 0.8,
blend: "soft-light",
},
single: { src: SINGLE_NOISE, size: "200px", opacity: 0.3, blend: "overlay" },
}
/**
* A decorative grain layer that fills a positioned parent without blocking
* clicks. Choose a texture and adjust its strength with `intensity` or
* `opacity`. `className` and other div props land on the outer layer.
*/
function Grain({
variant = "single",
intensity = "default",
opacity,
isolated = false,
className,
...props
}: React.ComponentProps<"div"> & {
/** The grain treatment: `single` (default), `paper`, `sandpaper` or `square`. */
variant?: GrainVariant
/** Multiplies the texture's opacity: `fine` 0.6×, `default` 1×, `rich` 1.45×. */
intensity?: Intensity
/** The texture opacity, from 0 to 1. Takes precedence over `intensity`. */
opacity?: number
/**
* Adds paint containment when true. This creates a stacking context, so
* the texture stops blending with scene layers outside this element.
*/
isolated?: boolean
}) {
const layer = VARIANT_TEXTURES[variant]
const m =
opacity != null ? opacity / layer.opacity : INTENSITY_MULT[intensity]
return (
<div
data-slot="grain"
data-variant={variant}
aria-hidden="true"
className={cn(
"pointer-events-none absolute inset-0",
isolated && "contain-[paint]",
className
)}
{...props}
>
<div
className={cn("absolute inset-0", BLEND_CLASS[layer.blend])}
style={{
backgroundImage: layer.src,
backgroundSize: layer.size,
opacity: layer.opacity * m,
}}
/>
</div>
)
}
export { Grain }
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
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>
/**
* 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.
*
* 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"
// No width of its own: the SectionHeader column (or whatever holds it) is
// the measure. text-pretty keeps a wrapped title from ending on one word.
// font-display follows font-sans unless the block switches it, for example
// with [--font-display:var(--font-serif)].
const subheadingVariants = cva(
"font-display font-[450] tracking-[-0.05em] text-pretty sm:tracking-[-0.06em]",
{
variants: {
/**
* `default` inherits the surrounding display face. `serif` uses
* the kit's serif role, without changing the surrounding font.
*/
variant: {
default: "",
serif: "[--font-display:var(--font-serif)]",
},
/**
* `md` (the default): 32px/40px, capped at 40px/44px from `sm`.
* `lg`: 32px/40px, 40px/48px from `sm`, 48px/56px from `lg`.
* `xl`: 32px/40px, 48px/56px from `sm`, 56px/56px from `lg`.
*/
size: {
md: "text-[2rem]/10 sm:text-[2.5rem]/11",
lg: "text-[2rem]/10 sm:text-[2.5rem]/12 lg:text-5xl/14",
xl: "text-[2rem]/10 sm:text-5xl/14 lg:text-[3.5rem]/14",
},
},
defaultVariants: { variant: "default", size: "md" },
}
)
/**
* The section heading in the display font, which follows `font-sans`
* unless a block switches that role. Rendered as an `<h2>` at weight 450.
* The default `size="md"` steps
* from 32px/40px to 40px/44px at `sm` and stays there. Choose `size="lg"`
* for 32px/40px, 40px/48px at `sm` and 48px/56px at `lg`, or `size="xl"`
* for 32px/40px, 48px/56px at `sm` and 56px/56px at `lg`.
* `variant="serif"` uses the kit's serif role; the default keeps the
* surrounding display face. Both variants support all three sizes.
* Pass `render` to use another heading level. A page's headline is `Heading`.
*/
function Subheading({
className,
variant = "default",
size = "md",
render,
...props
}: useRender.ComponentProps<"h2"> & VariantProps<typeof subheadingVariants>) {
return useRender({
defaultTagName: "h2",
render,
state: { slot: "subheading", variant, size },
props: mergeProps<"h2">(
{
className: cn(subheadingVariants({ variant, size }), className),
},
props
),
})
}
export { Subheading, subheadingVariants }
pnpm dlx shadcn@latest add @01orbital/stats-midnight-repair-ledgernpx shadcn@latest add @01orbital/stats-midnight-repair-ledgeryarn dlx shadcn@latest add @01orbital/stats-midnight-repair-ledgerbunx --bun shadcn@latest add @01orbital/stats-midnight-repair-ledgerAnatomy
Stats is built from 4 parts. In the example they nest like this:
StatGroup
└─ Stat
├─ StatValue
└─ StatLabelStatGroup: A list ofStatitems laid out byGrid, rendered as aul. It defaults to 3 columns and the large gap. LikeGrid, its columns follow the width it is given, so size its parent to narrow it.classNamelands on the list.Stat: One figure and its label, as anliinsideStatGroup. Holds aStatValueand aStatLabel, 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:
About Story with Stats
About with Quote and Facts
Case Study Rows with Stats
Fine Country Bars
Fine Exercise Lines
Fine Listener Areas
Fine Listening Profile
Fine Session Bars
Fine Session Line
Fine Traffic Lines
Fine Weekly Change
Five-Column Stats Ledger
Last updated on