# Bar list

> A compact horizontal bar chart with a shared scale and visible labels and values.

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

## Use 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 when
- The values represent a series over time. Use table for the raw figures.
- Multiple measures per row need their own scales.

## Alternatives
- [stat](https://hazeui.com/ui/stat.md)
- [table](https://hazeui.com/ui/table.md)
- [progress](https://hazeui.com/ui/progress.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| label | `string` | "Deployment volume" | no | Caption for the group of bars. |
| items | `{ label: string; value: number; displayValue?: string }[]` |  | no | Values and labels in display order. Use displayValue for formatted units. |
| max | `number` |  | no | Positive shared maximum. Defaults to the largest value. |
| class | `string` |  | no | 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.

## Agent prompts

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

## Example requests that should lead here
- Show project storage usage as four horizontal bars with visible GB values.

## Source

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