Bar list
A compact horizontal bar chart with a shared scale and visible labels and values.
pnpm dlx shadcn@latest add @haze/bar-list---
import { cn } from "../../../lib/haze/utils";
interface Props {
label?: string;
items?: { label: string; value: number; displayValue?: string }[];
max?: number;
class?: string;
}
const {
label = "Deployment volume",
items = [
{ label: "Production", value: 36 },
{ label: "Preview", value: 57 },
{ label: "Development", value: 21 },
],
max,
class: className,
} = Astro.props;
const observedMax = items.reduce((highest, item) => Number.isFinite(item.value) ? Math.max(highest, item.value) : highest, 0);
const scaleMax = max && Number.isFinite(max) && max > 0 ? max : observedMax || 1;
---
<figure class={cn("grid min-w-0 gap-4 rounded-xl border border-border bg-card p-4.5 text-card-foreground", className)}>
<figcaption class="text-[0.9375rem]/5 font-medium tracking-[-0.01em]">{label}</figcaption>
<ul class="grid gap-3.5">
{items.map(({ label: itemLabel, value, displayValue }) => {
const proportion = Number.isFinite(value) ? Math.min(100, Math.max(0, value / scaleMax * 100)) : 0;
return (
<li class="grid min-w-0 gap-1.5">
<div class="flex min-w-0 items-start justify-between gap-3 text-[0.8125rem]/5">
<span class="min-w-0 wrap-anywhere text-muted-foreground">{itemLabel}</span>
<span class="shrink-0 font-medium tabular-nums">{displayValue ?? value}</span>
</div>
<div aria-hidden="true" class="h-1.5 overflow-hidden rounded-full bg-muted forced-colors:border forced-colors:border-current">
<div style={`--bar-width: ${proportion}%`} class="h-full w-(--bar-width) rounded-full bg-brand/70 forced-colors:bg-[Highlight]"></div>
</div>
</li>
);
})}
</ul>
</figure>When to use
- Readers compare a handful of categories by a single nonnegative measure
- A dashboard needs a chart that stays legible in a narrow column
When not to use
- The values represent a series over time. Use table for the raw figures.
- Multiple measures per row need their own scales.
Installation
Add the Haze registry to components.json once, then install Bar list with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/bar-listnpx shadcn@latest add @haze/bar-listyarn dlx shadcn@latest add @haze/bar-listbunx --bun shadcn@latest add @haze/bar-listFirst 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 | "Deployment volume" | Caption for the group of bars. |
| items | { label: string; value: number; displayValue?: string }[] | – | Values and labels in display order. Use displayValue for formatted units. |
| max | number | – | Positive shared maximum. Defaults to the largest value. |
| class | string | – | Additional classes on the figure. |
Accessibility
- Bars are decorative. The complete data is available in the list of labels and textual values.
- Keep the units and scale consistent across all rows.
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 "Bar list" with `npx shadcn@latest add @haze/bar-list`. 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 BarList from "@/components/haze/ui/bar-list.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/bar-list.md
Customize with real content
Adapt the Haze bar-list ui for our product. Replace the demo values of these props with our real content: label, items, max, class. Keep the layout, the heading level rules and these accessibility details: Bars are decorative. The complete data is available in the list of labels and textual values. Keep the units and scale consistent across all rows. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using bar-list, check it fits: use it when readers compare a handful of categories by a single nonnegative measure; a dashboard needs a chart that stays legible in a narrow column. Avoid it when the values represent a series over time. use table for the raw figures.; multiple measures per row need their own scales.. Alternatives: @haze/stat, @haze/table, @haze/progress.
Dependencies
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.