Progress
Horizontal progress bar with a label, an optional percentage and status colors, set from a value and a max.
pnpm dlx shadcn@latest add @haze/progress---
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>When to use
- 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
When not to use
- Work of unknown length; use spinner
- Named steps in a flow; use stepper
Installation
Add the Haze registry to components.json once, then install Progress with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/progressnpx shadcn@latest add @haze/progressyarn dlx shadcn@latest add @haze/progressbunx --bun shadcn@latest add @haze/progressFirst 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 |
|---|---|---|---|
| value* | number | – | Current amount from 0 to max; values outside the range are clamped. |
| max | number | 100 | Amount that counts as complete. |
| label* | string | – | Names the bar for assistive technology and is printed above it. |
| hideLabel | boolean | false | Hides the printed label; the accessible name stays. |
| showValue | boolean | false | Prints the percentage next to the label. |
| variant | "default" | "success" | "warning" | "destructive" | "default" | Fill color. |
| size | "sm" | "md" | "md" | Bar height, 6 or 10 px. |
| class | string | – | 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.
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 "Progress" with `npx shadcn@latest add @haze/progress`. 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 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: http://localhost:4329/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.
Dependencies
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.