# Progress

> Horizontal progress bar with a label, an optional percentage and status colors, set from a value and a max.

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

## Use when
- An upload, import or quota where you know how much is done
- Showing storage or plan usage, with warning or destructive fill when it runs high
- A bar whose name is read out even when the label is visually hidden

## Avoid when
- Work of unknown length; use spinner
- Named steps in a flow; use stepper

## Alternatives
- [spinner](https://hazeui.com/ui/spinner.md)
- [stepper](https://hazeui.com/ui/stepper.md)
- [skeleton](https://hazeui.com/ui/skeleton.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| value | `number` |  | yes | Current amount from 0 to max; values outside the range are clamped. |
| max | `number` | 100 | no | Amount that counts as complete. |
| label | `string` |  | yes | Names the bar for assistive technology and is printed above it. |
| hideLabel | `boolean` | false | no | Hides the printed label; the accessible name stays. |
| showValue | `boolean` | false | no | Prints the percentage next to the label. |
| variant | `"default" \| "success" \| "warning" \| "destructive"` | "default" | no | Fill color. |
| size | `"sm" \| "md"` | "md" | no | Bar height, 6 or 10 px. |
| class | `string` |  | no | Extra classes on the wrapper. |

## Accessibility
- The wrapper has role="progressbar" with aria-valuemin, aria-valuemax, aria-valuenow and aria-valuetext, and its aria-label comes from the label prop.
- A warning or destructive fill needs words nearby, such as "90% of storage used", because the fill color is not enough.
- Updating the value in place makes screen readers announce the new percentage when the bar is focused or polled.

## Agent prompts

### Install and use

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

### Customize with real content

Adapt the Haze progress ui for our product. Replace the demo values of these props with our real content: value, max, label, hideLabel, showValue, variant, size, class. Keep the layout, the heading level rules and these accessibility details: The wrapper has role="progressbar" with aria-valuemin, aria-valuemax, aria-valuenow and aria-valuetext, and its aria-label comes from the label prop. A warning or destructive fill needs words nearby, such as "90% of storage used", because the fill color is not enough. Updating the value in place makes screen readers announce the new percentage when the bar is focused or polled. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using progress, check it fits: use it when an upload, import or quota where you know how much is done; showing storage or plan usage, with warning or destructive fill when it runs high; a bar whose name is read out even when the label is visually hidden. Avoid it when work of unknown length; use spinner; named steps in a flow; use stepper. Alternatives: @haze/spinner, @haze/stepper, @haze/skeleton.

## Example requests that should lead here
- Show storage used as a warning bar at 85 percent
- Add an upload progress bar with the percentage printed

## Source

```astro
---
import { cn } from "../../../lib/haze/utils";

interface Props {
  /** Current amount from 0 to max. Leave it out for work of unknown length: the bar then shows a moving segment and has no value. */
  value?: number;
  max?: number;
  label: string;
  hideLabel?: boolean;
  showValue?: boolean;
  variant?: "default" | "info" | "success" | "warning" | "destructive";
  size?: "sm" | "md";
  class?: string;
}

const { value, max = 100, label, hideLabel = false, showValue = false, variant = "default", size = "md", class: className } = Astro.props;

const indeterminate = value === undefined;
const safeMax = max > 0 ? max : 100;
const now = indeterminate ? 0 : Math.min(Math.max(Number.isFinite(value) ? value : 0, 0), safeMax);
const percent = Math.round((now / safeMax) * 100);
const fills = {
  default: "bg-primary",
  info: "bg-brand",
  success: "bg-success",
  warning: "bg-warning",
  destructive: "bg-destructive",
};
const heights = { sm: "h-1.5", md: "h-2" };
---

<div
  role="progressbar"
  aria-label={label}
  aria-valuemin={0}
  aria-valuemax={indeterminate ? undefined : safeMax}
  aria-valuenow={indeterminate ? undefined : now}
  aria-valuetext={indeterminate ? undefined : `${percent}%`}
  class={cn("grid gap-2", className)}
>
  {
    (!hideLabel || (showValue && !indeterminate)) && (
      <div class="flex items-center justify-between gap-3">
        {!hideLabel ? <span class="text-[0.8125rem]/5 font-medium tracking-[-0.01em] text-foreground">{label}</span> : <span />}
        {showValue && !indeterminate && <span class="text-[0.8125rem]/5 tabular-nums text-muted-foreground">{percent}%</span>}
      </div>
    )
  }
  <div class={cn("w-full overflow-hidden rounded-full bg-muted forced-colors:border forced-colors:border-solid", heights[size])}>
    {
      indeterminate ? (
        <div class={cn("h-full w-2/5 animate-indeterminate rounded-full forced-colors:border forced-colors:border-solid", fills[variant])}></div>
      ) : (
        <div
          class={cn("h-full rounded-full transition-[width] duration-500 ease-snappy forced-colors:border forced-colors:border-solid", fills[variant])}
          style={`width: ${percent}%`}
        ></div>
      )
    }
  </div>
</div>
```
