Stat
One metric with a small label, a large tabular value and an optional change with a trend arrow; plain or in a card panel.
pnpm dlx shadcn@latest add @haze/stat---
import { ArrowUpRight, ArrowDownRight, Minus } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Props {
label: string;
value: string;
/** Change text such as "+12.4%". The visible text keeps its sign; the screen-reader text drops one leading +, - or minus sign because the direction word already says it. */
change?: string;
/** Direction of the change. It picks the arrow, and the color unless `tone` is set. */
trend?: "up" | "down" | "neutral";
/** Whether the change is good news. Up is not always good: a rising refund rate is "negative". Defaults to positive for up, negative for down and neutral for neutral. */
tone?: "positive" | "negative" | "neutral";
/** Screen-reader text read before the change. Overrides the three words below. */
trendLabel?: string;
/** Screen-reader text for an upward change. Translate it for other languages. */
increaseLabel?: string;
/** Screen-reader text for a downward change. Translate it for other languages. */
decreaseLabel?: string;
/** Screen-reader text for no change. Translate it for other languages. */
unchangedLabel?: string;
/** Context for the change, such as "vs. last month". */
description?: string;
/** plain has no frame; card draws a panel around the stat. */
variant?: "plain" | "card";
/** An icon component, for example one from @lucide/astro. Decorative. */
icon?: (props: Record<string, unknown>) => unknown;
class?: string;
}
const {
label,
value,
change,
trend = "neutral",
tone,
trendLabel,
increaseLabel = "Increased by",
decreaseLabel = "Decreased by",
unchangedLabel = "No change",
description,
variant = "plain",
icon: Icon,
class: className,
} = Astro.props;
const spokenByTrend = { up: increaseLabel, down: decreaseLabel, neutral: unchangedLabel };
const toneByTrend = { up: "positive", down: "negative", neutral: "neutral" } as const;
const colors = { positive: "text-success", negative: "text-destructive", neutral: "text-muted-foreground" };
const variants = { plain: "", card: "rounded-2xl border border-border bg-card p-5 shadow-key" };
const spoken = trendLabel ?? spokenByTrend[trend];
const color = colors[tone ?? toneByTrend[trend]];
// The sign is shown, so for screen readers the direction word carries it: "Decreased by 0.3%", not "Decreased by -0.3%".
const spokenChange = change?.replace(/^[+\-−]/, "");
---
<div class={cn("grid gap-2", variants[variant], className)}>
<div class="flex items-center justify-between gap-3">
<p class="min-w-0 text-[0.8125rem]/5 text-muted-foreground">{label}</p>
{Icon && <Icon class="size-4 shrink-0 text-muted-foreground" aria-hidden="true" />}
</div>
<p class="text-[1.75rem]/9 font-medium tracking-[-0.01em] text-foreground tabular-nums">{value}</p>
{
(change || description) && (
<p class="flex flex-wrap items-center gap-x-1.5 text-xs/5 text-muted-foreground">
{change && (
<span class={cn("inline-flex items-center gap-1 font-medium tabular-nums", color)}>
{trend === "up" && <ArrowUpRight class="size-3.5" aria-hidden="true" />}
{trend === "down" && <ArrowDownRight class="size-3.5" aria-hidden="true" />}
{trend === "neutral" && <Minus class="size-3.5" aria-hidden="true" />}
<span class="sr-only">{spoken} {spokenChange}</span>
<span aria-hidden="true">{change}</span>
</span>
)}
{description && <span>{description}</span>}
</p>
)
}
</div>When to use
- A dashboard row of headline numbers such as revenue, signups or error rate
- Showing how a number moved since the last period
- A number inside a card header or a hero strip that needs a label and context
When not to use
- A number that is part of a sentence; write it in the text
- A full chart or a history of values; stat shows one value and one change
Installation
Add the Haze registry to components.json once, then install Stat with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/statnpx shadcn@latest add @haze/statyarn dlx shadcn@latest add @haze/statbunx --bun shadcn@latest add @haze/statFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| label* | string | – | What is measured, shown as a small uppercase label above the value. |
| value* | string | – | The number, already formatted, for example "$48,200". |
| change | string | – | Change since the comparison period, for example "+12.4%". |
| trend | "up" | "down" | "neutral" | "neutral" | Direction of the change. Picks the arrow icon, and the color unless tone is set. |
| tone | "positive" | "negative" | "neutral" | – | Whether the change is good news: success, destructive or muted color. Defaults to positive for up, negative for down and neutral for neutral. Set it when up is bad, such as a rising refund rate. |
| trendLabel | string | – | Screen-reader text read before the change. Overrides the three words below. |
| increaseLabel | string | "Increased by" | Screen-reader text for an upward change. Translate it for other languages. |
| decreaseLabel | string | "Decreased by" | Screen-reader text for a downward change. Translate it for other languages. |
| unchangedLabel | string | "No change" | Screen-reader text for no change. Translate it for other languages. |
| description | string | – | Comparison note after the change, for example "vs. last month". |
| variant | "plain" | "card" | "plain" | plain has no frame; card draws a bordered panel with padding. |
| icon | (props) => unknown | – | A lucide icon component shown at the right of the label. Decorative. |
| class | string | – | Extra classes on the wrapper. |
Accessibility
- The direction is spoken through the sr-only trendLabel, so "+12.4%" is announced as "Increased by 12.4%" and not as a bare number. One leading +, - or minus sign is dropped from the spoken text only, so a fall reads "Decreased by 0.3%".
- Up and down also differ by arrow direction, not only green and red. The icons are aria-hidden.
- Direction and meaning are separate: trend sets the arrow and the spoken word, tone sets the color. A rising refund rate is trend="up" tone="negative"; the spoken text still says it increased.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Stat" with `npx shadcn@latest add @haze/stat`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Stat from "@/components/haze/ui/stat.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/stat.md
Customize with real content
Adapt the Haze stat ui for our product. Replace the demo values of these props with our real content: label, value, change, trend, tone, trendLabel, increaseLabel, decreaseLabel, unchangedLabel, description, variant, icon, class. Keep the layout, the heading level rules and these accessibility details: The direction is spoken through the sr-only trendLabel, so "+12.4%" is announced as "Increased by 12.4%" and not as a bare number. One leading +, - or minus sign is dropped from the spoken text only, so a fall reads "Decreased by 0.3%". Up and down also differ by arrow direction, not only green and red. The icons are aria-hidden. Direction and meaning are separate: trend sets the arrow and the spoken word, tone sets the color. A rising refund rate is trend="up" tone="negative"; the spoken text still says it increased. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using stat, check it fits: use it when a dashboard row of headline numbers such as revenue, signups or error rate; showing how a number moved since the last period; a number inside a card header or a hero strip that needs a label and context. Avoid it when a number that is part of a sentence; write it in the text; a full chart or a history of values; stat shows one value and one change. Alternatives: @haze/card, @haze/progress, @haze/tag.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.