# Progress
How far a task has run, as an accessible bar.
Source page: https://dinachi.dev/docs/components/progress

## Installation
```bash
npx @dinachi/cli@latest add progress
```
Adds to your project:
- `components/ui/progress/progress.tsx`
- `components/ui/progress/index.ts`
Installs:
- `@base-ui/react` ^1.9.0

## Usage
```tsx
import {
  Progress,
  ProgressIndicator,
  ProgressLabel,
  ProgressTrack,
  ProgressValue,
} from "@/components/ui/progress"

export function UploadProgress() {
  return (
    <Progress value={40}>
      <ProgressLabel>Upload</ProgressLabel>
      <ProgressValue />
      <ProgressTrack>
        <ProgressIndicator />
      </ProgressTrack>
    </Progress>
  )
}
```

## Anatomy
```tsx
<Progress>
  <ProgressLabel />
  <ProgressValue />
  <ProgressTrack>
    <ProgressIndicator />
  </ProgressTrack>
</Progress>
```
- `Progress`: Holds the value and exposes it as a progressbar.
- `ProgressLabel`: The visible name of the bar.
- `ProgressValue`: Shows the formatted value as text.
- `ProgressTrack`: The full-width rail behind the indicator.
- `ProgressIndicator`: The filled part, sized to the value.

## Examples

### With label
A label and the formatted value.
```tsx
import { Progress, ProgressTrack, ProgressIndicator, ProgressLabel, ProgressValue } from '@/components/ui/progress';

export function Example() {
  return (
    <Progress value={75} className="w-full max-w-sm">
      <div className="flex items-center justify-between">
        <ProgressLabel>Uploading...</ProgressLabel>
        <ProgressValue />
      </div>
      <ProgressTrack>
        <ProgressIndicator />
      </ProgressTrack>
    </Progress>
  );
}
```

### Default
A bar at 60 percent.
```tsx
import { Progress, ProgressTrack, ProgressIndicator } from '@/components/ui/progress';

export function Example() {
  return (
    <Progress value={60} className="w-full max-w-sm">
      <ProgressTrack>
        <ProgressIndicator />
      </ProgressTrack>
    </Progress>
  );
}
```

### Animated
The bar eases between values.
```tsx
import React from 'react';
import { Progress, ProgressTrack, ProgressIndicator, ProgressLabel } from '@/components/ui/progress';

export function Example() {
  const [progress, setProgress] = React.useState(0);

  React.useEffect(() => {
    const timer = setInterval(() => {
      setProgress((prev) => {
        if (prev >= 100) return 0;
        return prev + 10;
      });
    }, 800);
    return () => clearInterval(timer);
  }, []);

  return (
    <Progress value={progress} className="w-full max-w-sm">
      <div className="flex items-center justify-between">
        <ProgressLabel>Loading</ProgressLabel>
        <span className="text-xs text-muted-foreground">{progress}%</span>
      </div>
      <ProgressTrack>
        <ProgressIndicator />
      </ProgressTrack>
    </Progress>
  );
}
```

## Notes

### Indeterminate
Pass `value={null}` when the amount of work is unknown. The root then sets `data-indeterminate` instead of `data-progressing` or `data-complete`; style the indicator from these.

### Agent
Not registered with the [agent bridge](/docs/components/agent); read from the accessibility tree like any `progressbar`. Listed as `progress` with `value`, `min` and `max`, and no actions. Indeterminate, it has no `value`.

```ts
agent.snapshot()
// [{ component: "progress", label: "Upload", value: 40, min: 0, max: 100, actions: [] }]
```

## API reference

### Progress
Holds the value and exposes it as a progressbar.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `number \| null` | - | Current value. `null` makes the bar indeterminate. |
| `min` | `number` | `0` | The value at an empty bar. |
| `max` | `number` | `100` | The value at a full bar. |
| `format` | `Intl.NumberFormatOptions` | - | Number format for `ProgressValue` and the announced text. |
| `locale` | `Intl.LocalesArgument` | - | Locale for formatting the value. |
| `getAriaValueText` | `(formattedValue, value) => string` | - | Text announced in place of the number. |

### ProgressLabel
The visible name of the bar.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` | - | Names the progressbar for screen readers and the agent. |

### ProgressValue
Shows the formatted value as text.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `(formattedValue, value) => ReactNode` | - | Custom formatting. Both are `null` while indeterminate. |

### ProgressTrack
The full-width rail behind the indicator.

Takes the props of the element it renders.

### ProgressIndicator
The filled part, sized to the value.

Takes the props of the element it renders.

## Accessibility
- The root is a progressbar with aria-valuenow, aria-valuemin and aria-valuemax.
- `ProgressLabel` names the bar through aria-labelledby. Without one, pass aria-label on Progress.
- Use `getAriaValueText` when a percentage is unclear, such as "3 of 10 files".
- Reduced motion turns off the indicator's width transition.

## Source
`components/ui/progress/progress.tsx`
```tsx
"use client"

import * as React from "react"
import { Progress as ProgressPrimitive } from "@base-ui/react/progress"
import { cn } from "@/lib/utils"

const Progress = React.forwardRef<
  React.ComponentRef<typeof ProgressPrimitive.Root>,
  React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root>
>(({ className, ...props }, ref) => (
  <ProgressPrimitive.Root data-slot="progress" ref={ref} className={cn("grid gap-2", className)} {...props} />
))
Progress.displayName = "Progress"

const ProgressTrack = React.forwardRef<
  React.ComponentRef<typeof ProgressPrimitive.Track>,
  React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Track>
>(({ className, ...props }, ref) => (
  <ProgressPrimitive.Track
    data-slot="progress-track"
    ref={ref}
    className={cn("relative h-2 w-full overflow-hidden rounded-full bg-secondary", className)}
    {...props}
  />
))
ProgressTrack.displayName = "ProgressTrack"

const ProgressIndicator = React.forwardRef<
  React.ComponentRef<typeof ProgressPrimitive.Indicator>,
  React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Indicator>
>(({ className, ...props }, ref) => (
  <ProgressPrimitive.Indicator
    data-slot="progress-indicator"
    ref={ref}
    className={cn("h-full rounded-full bg-primary transition-[width] duration-[var(--motion-duration-base,200ms)] ease-[var(--motion-ease-out,cubic-bezier(0.23,1,0.32,1))] motion-reduce:transition-none", className)}
    {...props}
  />
))
ProgressIndicator.displayName = "ProgressIndicator"

const ProgressLabel = React.forwardRef<
  React.ComponentRef<typeof ProgressPrimitive.Label>,
  React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Label>
>(({ className, ...props }, ref) => (
  <ProgressPrimitive.Label
    data-slot="progress-label"
    ref={ref}
    className={cn("text-sm font-medium leading-none", className)}
    {...props}
  />
))
ProgressLabel.displayName = "ProgressLabel"

const ProgressValue = React.forwardRef<
  React.ComponentRef<typeof ProgressPrimitive.Value>,
  React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Value>
>(({ className, ...props }, ref) => (
  <ProgressPrimitive.Value
    data-slot="progress-value"
    ref={ref}
    className={cn("text-xs text-muted-foreground", className)}
    {...props}
  />
))
ProgressValue.displayName = "ProgressValue"

export { Progress, ProgressTrack, ProgressIndicator, ProgressLabel, ProgressValue }
```
