# Bento growth

> A headline metric and prior-period comparison with compact animated columns and a disclosure for exact figures.

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

## Use when
- A KPI needs both its latest value and a short history.
- You want readers to see the comparison even when the chart is small.

## Avoid when
- The item needs a shared axis for signed values or multiple data series.

## Alternatives
- [sparkline](https://hazeui.com/ui/sparkline.md)
- [stat](https://hazeui.com/ui/stat.md)
- [bar-list](https://hazeui.com/ui/bar-list.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| label | `string` | Active workspaces | no | Metric name. |
| value | `string` | 2,480 | no | Formatted current amount. |
| comparison | `string` |  | no | Text that names the direction, change and comparison period. Pass an empty string to omit it. |
| direction | `up \| down \| flat` | up | no | Selects the comparison arrow. |
| samples | `Sample[]` |  | no | Ordered, nonnegative finite values with period labels and optional formatted values. |
| detailsLabel | `string` | View values | no | Caption of the disclosure for the period values. |
| motion | `boolean` | true | no | Animate columns as they enter the viewport where scroll-driven motion is supported and enabled. |
| class | `string` |  | no | Classes on the figure. |

## Accessibility
- The exact chart values are in a native disclosure.
- The comparison is written out and the decorative bars respect reduced motion.
- Key Enter / Space: Open or close the period values.

## Agent prompts

### Install and use

Install the Haze UI component "Bento growth" with `npx shadcn@latest add @haze/bento-growth`. 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 BentoGrowth from "@/components/haze/ui/bento-growth.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/bento-growth.md

### Customize with real content

Adapt the Haze bento-growth ui for our product. Replace the demo values of these props with our real content: label, value, comparison, direction, samples, detailsLabel, motion, class. Keep the layout, the heading level rules and these accessibility details: The exact chart values are in a native disclosure. The comparison is written out and the decorative bars respect reduced motion. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using bento-growth, check it fits: use it when a kpi needs both its latest value and a short history.; you want readers to see the comparison even when the chart is small.. Avoid it when the item needs a shared axis for signed values or multiple data series.. Alternatives: @haze/sparkline, @haze/stat, @haze/bar-list.

## Example requests that should lead here
- Show active workspaces, the change from last month and the last six exact values.

## Source

```astro
---
import { ArrowDownRight, ArrowRight, ArrowUpRight, ChevronDown } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

interface Props {
  label?: string;
  value?: string;
  comparison?: string;
  direction?: "up" | "down" | "flat";
  samples?: { label: string; value: number; displayValue?: string }[];
  detailsLabel?: string;
  motion?: boolean;
  class?: string;
}

const {
  label = "Active workspaces", value = "2,480", comparison = "+16% vs last month", direction = "up",
  detailsLabel = "View values", motion = true, class: className,
  samples = [
    { label: "Jun", value: 1620 }, { label: "Jul", value: 1800 }, { label: "Aug", value: 1730 },
    { label: "Sep", value: 1960 }, { label: "Oct", value: 2138 }, { label: "Nov", value: 2480 },
  ],
} = Astro.props;
const valid = samples.filter((sample) => Number.isFinite(sample.value) && sample.value >= 0);
const maximum = valid.reduce((max, sample) => Math.max(max, sample.value), 0) || 1;
const Direction = { up: ArrowUpRight, down: ArrowDownRight, flat: ArrowRight }[direction];
---

<figure class={cn("grid min-w-0 gap-3", className)}>
  <figcaption class="text-xs/4 font-medium text-muted-foreground">{label}</figcaption>
  <div class="flex min-w-0 flex-wrap items-end justify-between gap-2">
    <strong class="text-3xl/9 font-medium tracking-tight wrap-anywhere tabular-nums">{value}</strong>
    {comparison && (
      <span class="inline-flex min-w-0 items-center gap-1 rounded-md bg-muted px-2 py-1 text-xs/4 font-medium text-foreground">
        <Direction class="size-3 shrink-0" aria-hidden="true" />
        <span class="wrap-anywhere">{comparison}</span>
      </span>
    )}
  </div>
  {valid.length > 0 && (
    <>
      <div aria-hidden="true" style={`column-gap: ${Math.min(2, 20 / valid.length)}%`}
        class="relative flex h-22 min-w-0 items-end rounded-t-sm border-b border-border bg-background/60 px-1.5">
        <span class="absolute inset-x-0 top-1/2 border-t border-dashed border-border"></span>
        {valid.map(({ value: sample }, index) => (
          <span style={`--bar-height: ${sample / maximum * 100}%; animation-timeline: view(); animation-range: entry ${Math.min(index, 7) * 6}% entry 100%`}
            class={cn("z-10 h-(--bar-height) min-w-0 flex-1 rounded-t-sm",
              index === valid.length - 1 ? "bg-brand" : "bg-brand/35",
              motion && "motion-safe:supports-[animation-timeline:view()]:animate-rise")}></span>
        ))}
      </div>
      <details class="group min-w-0">
        <summary class="flex min-h-7 cursor-pointer list-none items-center justify-between gap-2 rounded-sm text-xs/4 font-medium text-muted-foreground transition-colors duration-150 ease-snappy hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring [&::-webkit-details-marker]:hidden">
          {detailsLabel}
          <ChevronDown class="size-3.5 shrink-0 transition-[rotate] duration-200 ease-snappy group-open:rotate-180" aria-hidden="true" />
        </summary>
        <dl class="mt-2 grid gap-1 border-t border-border pt-2 text-xs/5">
          {valid.map(({ label: period, value: sample, displayValue }) => (
            <div class="flex min-w-0 flex-wrap justify-between gap-x-2">
              <dt class="wrap-anywhere text-muted-foreground">{period}</dt>
              <dd class="font-mono wrap-anywhere tabular-nums">{displayValue ?? sample}</dd>
            </div>
          ))}
        </dl>
      </details>
    </>
  )}
</figure>
```
