# Stat Card

One figure on a dashboard: a title, a 32 px navy figure, and either a sparkline of recent values or the change against the last period. Each direction has its own arrow; a good change is green and a bad one red, where better says which way is good.

- Beta: ready to use; its API can still change in a minor release.
- Category: Layout & surfaces

```tsx
import { StatCard } from "@leap-crm/design-system";
```

## Best practices

- Do: Set `better="down"` on a delta where a fall is good news, like days to convert, so a drop shows green and not red.
- Do: Give a delta a `label`, like "vs prev period", so the reader knows what the change is measured against.
- Do: Line stat cards up in a row of equal height. The figure and what's under it sit on the card's bottom edge, so the figures line up whatever the titles.
- Do: Show either a `trend` or a `delta`, so the figure stays the strongest thing on the card.
- Don't: Move the figure up under its title with a class. In a row of cards with different titles, the figures would sit at different heights.
- Don't: Use it for a figure the user picks to filter by, like a pipeline stage. Use `CardButton` with `CardLabel` and `CardValue`.

## Related

- [Card](./card.md)
- [Rolling Number](./rolling-number.md)
- [Progress](./progress.md)

## Examples

What the examples import:

```tsx
import { StatCard } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
const monthly = [3, 6, 4, 8, 7, 11, 10, 13, 12, 16, 14, 18] as const;
```

### Sparkline and delta

```tsx
<div className="flex flex-wrap gap-4">
  <StatCard
    className="w-65"
    title="New opportunities"
    value="148"
    rate="12 / month"
    trend={monthly}
  />
  <StatCard
    className="w-65"
    title="Converted to matters"
    subtitle="Share of closed opportunities"
    value="31%"
    delta={{ value: "4.2%", direction: "up", label: "vs prev period" }}
  />
  <StatCard
    className="w-65"
    title="Average days to convert"
    value="23"
    delta={{
      value: "3 days",
      direction: "down",
      label: "vs prev period",
    }}
  />
</div>
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `title` (required) | `ReactNode` |  | What's counted, like "New opportunities". |
| `subtitle` | `ReactNode` |  | A muted line under the title, like "Share of closed opportunities". |
| `value` (required) | `ReactNode` |  | The figure, formatted, like "148" or "31%". Text or a number rolls its digits when it changes. |
| `rate` | `ReactNode` |  | A rate beside the figure, like "12 / month". |
| `trend` | `unknown` |  | Recent values, oldest first, drawn as a sparkline under the figure. |
| `delta` | `{ /** The change, formatted, like "4.2%". */ value: string; /** Whether it went up or down, shown by its own arrow and read out. */ direction: "up" \| "down"; /** Which way is good, like "down" for days to convert. A good change is green, a bad one red. */ better?: "up" \| "down"; /** What it's compared with, like "vs prev period". */ label?: string; }` |  | The change against the previous period, under the figure. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
