Bento growth
A headline metric and prior-period comparison with compact animated columns and a disclosure for exact figures.
pnpm dlx shadcn@latest add @haze/bento-growth---
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>When to use
- A KPI needs both its latest value and a short history.
- You want readers to see the comparison even when the chart is small.
When not to use
- The item needs a shared axis for signed values or multiple data series.
Installation
Add the Haze registry to components.json once, then install Bento growth with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/bento-growthnpx shadcn@latest add @haze/bento-growthyarn dlx shadcn@latest add @haze/bento-growthbunx --bun shadcn@latest add @haze/bento-growthFirst 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 | Active workspaces | Metric name. |
| value | string | 2,480 | Formatted current amount. |
| comparison | string | – | Text that names the direction, change and comparison period. Pass an empty string to omit it. |
| direction | up | down | flat | up | Selects the comparison arrow. |
| samples | Sample[] | – | Ordered, nonnegative finite values with period labels and optional formatted values. |
| detailsLabel | string | View values | Caption of the disclosure for the period values. |
| motion | boolean | true | Animate columns as they enter the viewport where scroll-driven motion is supported and enabled. |
| class | string | – | Classes on the figure. |
Keyboard interactions
- EnterSpace
- Open or close the period values.
Accessibility
- The exact chart values are in a native disclosure.
- The comparison is written out and the decorative bars respect reduced motion.
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 "Bento growth" with `npx shadcn@latest add @haze/bento-growth`. 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 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: http://localhost:4329/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.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.