# 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.

- Kind: ui · Category: Data display · Interactivity: none
- Install: `npx shadcn@latest add @haze/stat`
- File: `src/components/haze/ui/stat.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/stat

## Use 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 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
- [card](https://hazeui.com/ui/card.md)
- [progress](https://hazeui.com/ui/progress.md)
- [tag](https://hazeui.com/ui/tag.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| label | `string` |  | yes | What is measured, shown as a small uppercase label above the value. |
| value | `string` |  | yes | The number, already formatted, for example "$48,200". |
| change | `string` |  | no | Change since the comparison period, for example "+12.4%". |
| trend | `"up" \| "down" \| "neutral"` | "neutral" | no | Direction of the change. Picks the arrow icon, and the color unless tone is set. |
| tone | `"positive" \| "negative" \| "neutral"` |  | no | 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` |  | no | Screen-reader text read before the change. Overrides the three words below. |
| increaseLabel | `string` | "Increased by" | no | Screen-reader text for an upward change. Translate it for other languages. |
| decreaseLabel | `string` | "Decreased by" | no | Screen-reader text for a downward change. Translate it for other languages. |
| unchangedLabel | `string` | "No change" | no | Screen-reader text for no change. Translate it for other languages. |
| description | `string` |  | no | Comparison note after the change, for example "vs. last month". |
| variant | `"plain" \| "card"` | "plain" | no | plain has no frame; card draws a bordered panel with padding. |
| icon | `(props) => unknown` |  | no | A lucide icon component shown at the right of the label. Decorative. |
| class | `string` |  | no | 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.

## Agent prompts

### 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": "https://hazeui.com/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: https://hazeui.com/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.

## Example requests that should lead here
- Show monthly revenue as $48,200 with a green +12.4% versus last month
- Add a card stat for the refund rate that rose 0.4 points and shows red
- Add three stats side by side in a card

## Source

```astro
---
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>
```
