Progress
A progress bar built on the @zag-js/progress machine. The machine wires role="progressbar", the live value text, and the aria-value* range automatically, so they are correct by construction rather than hand-wired.
Interactive Preview
Section titled “Interactive Preview”React Progresslive
Svelte Progresslive
Guide setup
62%
Solid Progresslive
Guide setup
62%
import { Progress } from "@/components/ui/progress";
<Progress label="Guide setup" value={62} showValue /><Progress value={null} /> {/* indeterminate */}<script lang="ts"> import Progress from "@/components/ui/progress.svelte";</script>
<Progress label="Guide setup" value={62} showValue /><Progress value={null} />import { Progress } from "@/components/ui/progress";
<Progress label="Guide setup" value={62} showValue /><Progress value={null} />Installation
Section titled “Installation”npx @glaceon/cli add progress --framework react # or svelte, solidbun add @zag-js/progress @zag-js/react clsx tailwind-merge# replace @zag-js/react with @zag-js/svelte or @zag-js/solid for other frameworksThen copy the source for your framework:
import { useId } from "react"import { normalizeProps, useMachine } from "@zag-js/react"import * as zagProgress from "@zag-js/progress"import { cn } from "@/lib/cn"
export interface ProgressProps { /** Current value. Pass `null` for the indeterminate state. */ value?: number | null min?: number max?: number label?: string /** Renders the machine's value text (also exposed to screen readers via aria-live). */ showValue?: boolean className?: string}
const rootClass = "flex w-full flex-col gap-1.5"const labelClass = "text-xs font-bold text-muted"const trackClass = "h-2.5 w-full overflow-hidden rounded-sm bg-line"const rangeClass = "h-full rounded-sm bg-green transition-[width] duration-300 ease-out"const valueTextClass = "text-xs tabular-nums text-muted"
export function Progress({ value, min = 0, max = 100, label, showValue = false, className,}: ProgressProps) { const uid = useId().replace(/[^a-zA-Z0-9_-]/g, "") const service = useMachine(zagProgress.machine, { id: uid, value, min, max }) const api = zagProgress.connect(service, normalizeProps)
return ( <div {...api.getRootProps()} className={cn(rootClass, className)}> {label ? ( <span {...api.getLabelProps()} className={labelClass}> {label} </span> ) : null} <div {...api.getTrackProps()} className={trackClass}> <div {...api.getRangeProps()} className={rangeClass} /> </div> {showValue ? ( <span {...api.getValueTextProps()} className={valueTextClass}> {api.valueAsString} </span> ) : null} </div> )}<script lang="ts"> import { normalizeProps, useMachine } from "@zag-js/svelte" import * as zagProgress from "@zag-js/progress" import { cn } from "@/lib/cn"
interface Props { value?: number | null min?: number max?: number label?: string showValue?: boolean class?: string }
const { value = undefined, min = 0, max = 100, label = undefined, showValue = false, class: className, }: Props = $props()
const rootClass = "flex w-full flex-col gap-1.5" const labelClass = "text-xs font-bold text-muted" const trackClass = "h-2.5 w-full overflow-hidden rounded-sm bg-line" const rangeClass = "h-full rounded-sm bg-green transition-[width] duration-300 ease-out" const valueTextClass = "text-xs tabular-nums text-muted"
const uid = $props.id() const service = useMachine(zagProgress.machine, () => ({ id: uid, value, min, max })) const api = $derived(zagProgress.connect(service, normalizeProps))</script>
<div {...api.getRootProps()} class={cn(rootClass, className)}> {#if label} <span {...api.getLabelProps()} class={labelClass}>{label}</span> {/if} <div {...api.getTrackProps()} class={trackClass}> <div {...api.getRangeProps()} class={rangeClass}></div> </div> {#if showValue} <span {...api.getValueTextProps()} class={valueTextClass}>{api.valueAsString}</span> {/if}</div>import { createMemo, createUniqueId, Show } from "solid-js"import { normalizeProps, useMachine } from "@zag-js/solid"import * as zagProgress from "@zag-js/progress"import { cn } from "@/lib/cn"
export interface ProgressProps { /** Current value. Pass `null` for the indeterminate state. */ value?: number | null min?: number max?: number label?: string /** Renders the machine's value text (also exposed to screen readers via aria-live). */ showValue?: boolean class?: string}
const rootClass = "flex w-full flex-col gap-1.5"const labelClass = "text-xs font-bold text-muted"const trackClass = "h-2.5 w-full overflow-hidden rounded-sm bg-line"const rangeClass = "h-full rounded-sm bg-green transition-[width] duration-300 ease-out"const valueTextClass = "text-xs tabular-nums text-muted"
export function Progress(props: ProgressProps) { const uid = createUniqueId() const service = useMachine(zagProgress.machine, { id: uid, value: props.value, min: props.min ?? 0, max: props.max ?? 100, }) const api = createMemo(() => zagProgress.connect(service, normalizeProps))
return ( <div {...api().getRootProps()} class={cn(rootClass, props.class)}> <Show when={props.label}> <span {...api().getLabelProps()} class={labelClass}> {props.label} </span> </Show> <div {...api().getTrackProps()} class={trackClass}> <div {...api().getRangeProps()} class={rangeClass} /> </div> <Show when={props.showValue}> <span {...api().getValueTextProps()} class={valueTextClass}> {api().valueAsString} </span> </Show> </div> )}Data Attributes
Section titled “Data Attributes”| Element | Data Attribute | Value | Description |
|---|---|---|---|
root |
data-value |
number | Current value. Omitted when indeterminate. |
root |
data-state |
"indeterminate" | "loading" | "complete" |
Derived from value against max. |
root |
data-max |
number | The maximum value. |
root |
data-orientation |
"horizontal" | "vertical" |
Layout axis. |
track |
data-state |
"indeterminate" | "loading" | "complete" |
Matches the root state. |
range |
data-state |
"indeterminate" | "loading" | "complete" |
Matches the root state. |
API Reference (Props)
Section titled “API Reference (Props)”| Prop | Type | Default | Description |
|---|---|---|---|
value |
number | null |
undefined |
Current value. Pass null for the indeterminate state. |
min |
number |
0 |
Range minimum. |
max |
number |
100 |
Range maximum. |
label |
string |
undefined |
Renders a visible label linked to the track. |
showValue |
boolean |
false |
Renders the value text. Also exposed through an aria-live region. |
class / className |
string |
undefined |
Extra classes, appended last. |
Accessibility
Section titled “Accessibility”role="progressbar" and aria-valuenow / aria-valuemin / aria-valuemax come from the machine. The value text node is aria-live="polite", so progress updates are announced without interrupting the user.