# Progress

> A bar or circle that shows how far a task has run.

```tsx title="hero.tsx"
import {
  Progress,
  ProgressIndicator,
  ProgressLabel,
  ProgressTrack,
  ProgressValue,
} from '@langgenius/dify-ui/progress'

export function ProgressHeroDemo() {
  return (
    <Progress value={64} className="flex w-full max-w-80 flex-col gap-2">
      <div className="flex items-center justify-between gap-2">
        <ProgressLabel className="truncate">Uploading product-handbook.pdf</ProgressLabel>
        <ProgressValue className="shrink-0" />
      </div>
      <ProgressTrack>
        <ProgressIndicator />
      </ProgressTrack>
    </Progress>
  )
}
```

## Usage guidelines

- **Use Progress for task completion**: Progress shows how far a running task, such as an upload, an import or an indexing run, has moved toward done. A value that sits in a range and can rise or fall at any time, such as quota usage, storage or a score, uses `Meter`. Both draw the same bar, but assistive technology announces them as `progressbar` and `meter`, so choose by meaning, not by look.
- **Pass `null` while the amount is unknown**: A `null` value makes the progress indeterminate. The bar hides its indicator, `aria-valuenow` is removed, and Base UI falls back to the English value text "indeterminate progress"; pass a localized `getAriaValueText` in other locales. Use `Spinner` instead when no track needs to show.
- **Name the progress**: Use `ProgressLabel` for a visible label; it names the root. `ProgressCircle` has no label part, so it requires `aria-label` or `aria-labelledby`.
- **Describe the value in task terms**: Set `max` to the real total and `getAriaValueText` when a percentage alone does not say what is counted. `ProgressValue` takes a render function for the same visible text.
- **Keep completion announcements with the feature**: Progress exposes the current value on request. Announcing that a task finished or failed belongs to the feature's status owner.

## Anatomy

```tsx
import {
  Progress,
  ProgressCircle,
  ProgressIndicator,
  ProgressLabel,
  ProgressTrack,
  ProgressValue,
} from '@langgenius/dify-ui/progress'
```

```tsx
<Progress>
  <ProgressLabel />
  <ProgressValue />
  <ProgressTrack>
    <ProgressIndicator />
  </ProgressTrack>
</Progress>

<ProgressCircle />
```

The linear parts style Base UI Progress and leave the layout of the label and value to the caller. `ProgressCircle` is a single part that draws a pie from the value.

## Examples

### Indeterminate

With `value={null}` the track stays empty until the task can report an amount. Keep `ProgressIndicator` inside `ProgressTrack` so it hides automatically while indeterminate and appears once a number arrives. The indeterminate bar does not animate, so this example adds a decorative `SpinnerIcon` to show the task is running.

```tsx title="indeterminate.tsx"
import {
  Progress,
  ProgressIndicator,
  ProgressLabel,
  ProgressTrack,
} from '@langgenius/dify-ui/progress'
import { SpinnerIcon } from '@langgenius/dify-ui/spinner'

export function ProgressIndeterminateDemo() {
  return (
    <Progress value={null} className="flex w-full max-w-80 flex-col gap-2">
      <div className="flex items-center justify-between gap-2">
        <ProgressLabel className="truncate">Preparing log export</ProgressLabel>
        <SpinnerIcon size="small" className="text-text-tertiary" />
      </div>
      <ProgressTrack>
        <ProgressIndicator />
      </ProgressTrack>
    </Progress>
  )
}
```

### Updating value

The indicator width follows `value` with a transition that is removed for reduced motion. Here `max` is the segment count, and the value text counts segments instead of a percentage. The button uses `loading` so it keeps focus while the run is in progress.

```tsx title="live.tsx"
import { Button } from '@langgenius/dify-ui/button'
import {
  Progress,
  ProgressIndicator,
  ProgressLabel,
  ProgressTrack,
  ProgressValue,
} from '@langgenius/dify-ui/progress'
import * as React from 'react'

const total = 24

export function ProgressLiveDemo() {
  const [indexed, setIndexed] = React.useState<number | null>(null)

  React.useEffect(() => {
    if (indexed === null || indexed >= total) return
    const timer = setTimeout(() => setIndexed(indexed + 1), 150)
    return () => clearTimeout(timer)
  }, [indexed])

  const running = indexed !== null && indexed < total
  const labelId = React.useId()

  return (
    <div className="flex w-full max-w-80 flex-col gap-4">
      <Progress
        value={indexed ?? 0}
        max={total}
        getAriaValueText={(_formattedValue, value) => `${value ?? 0} of ${total} segments`}
        className="flex flex-col gap-2"
      >
        <div className="flex items-center justify-between gap-2">
          <ProgressLabel className="truncate">Indexing segments</ProgressLabel>
          <ProgressValue className="shrink-0">
            {(_formattedValue, value) => `${value ?? 0} / ${total}`}
          </ProgressValue>
        </div>
        <ProgressTrack>
          <ProgressIndicator />
        </ProgressTrack>
      </Progress>
      <Button
        className="self-start"
        loading={running}
        aria-labelledby={labelId}
        onClick={() => setIndexed(0)}
      >
        <span id={labelId}>
          {running ? 'Indexing…' : indexed === total ? 'Re-index' : 'Start indexing'}
        </span>
      </Button>
    </div>
  )
}
```

### Circle

`ProgressCircle` fits rows and dense lists. `color` takes `blue` (the default), `gray`, `warning`, `error` or `white` (for dark or accent surfaces). A `null` value draws an empty circle.

```tsx title="circle.tsx"
import type { ProgressCircleProps } from '@langgenius/dify-ui/progress'
import { ProgressCircle } from '@langgenius/dify-ui/progress'

const files: {
  name: string
  value: number | null
  color: NonNullable<ProgressCircleProps['color']>
  status: string
}[] = [
  { name: 'pricing-faq.md', value: 35, color: 'blue', status: 'Embedding' },
  { name: 'release-notes.pdf', value: null, color: 'gray', status: 'Queued' },
  { name: 'contracts-2025.zip', value: 50, color: 'warning', status: 'Retrying' },
  { name: 'scan-0042.png', value: 60, color: 'error', status: 'Failed' },
]

export function ProgressCircleDemo() {
  return (
    <ul className="flex w-full max-w-80 flex-col gap-2">
      {files.map((file) => (
        <li key={file.name} className="flex items-center gap-2">
          <ProgressCircle
            value={file.value}
            color={file.color}
            size="medium"
            aria-label={`${file.status} ${file.name}`}
          />
          <span className="min-w-0 flex-1 truncate system-sm-regular text-text-secondary">
            {file.name}
          </span>
          <span className="shrink-0 system-xs-regular text-text-tertiary">{file.status}</span>
        </li>
      ))}
    </ul>
  )
}
```

### Circle sizes

`small` (the default), `medium` and `large` render 12, 16 and 20 pixels.

```tsx title="circle-sizes.tsx"
import { ProgressCircle } from '@langgenius/dify-ui/progress'

const sizes = [
  { size: 'small', pixels: '12px' },
  { size: 'medium', pixels: '16px' },
  { size: 'large', pixels: '20px' },
] as const

export function ProgressCircleSizesDemo() {
  return (
    <div className="flex flex-wrap items-end gap-8">
      {sizes.map(({ size, pixels }) => (
        <div key={size} className="flex flex-col items-center gap-2">
          <ProgressCircle value={65} size={size} aria-label={`Indexing progress (${size})`} />
          <span className="system-xs-regular text-text-tertiary tabular-nums">
            {size} · {pixels}
          </span>
        </div>
      ))}
    </div>
  )
}
```

## API reference

### Progress

Groups all parts of a linear progress bar and exposes task completion status to assistive technology. Renders a `<div>` element.

Use `Meter` instead for a numeric value within a known range rather than task completion.

Inherits `className`, `aria-valuetext`, `format`, `getAriaValueText`, `locale`, `max`, `min`, `value`, `render`, `style` from [Base UI Progress.Root](https://base-ui.com/react/components/progress#root).

**Data attributes**

| Attribute            | Description                                          |
| -------------------- | ---------------------------------------------------- |
| `data-complete`      | Present when the progress has completed.             |
| `data-indeterminate` | Present when the progress is in indeterminate state. |
| `data-progressing`   | Present while the progress is progressing.           |

### ProgressCircle

Displays task completion as a circular pie indicator; requires `aria-label` or `aria-labelledby`. Renders a `<div>` element.

**Props**

| Prop                 | Type                                                  | Default   | Description                                                                        |
| -------------------- | ----------------------------------------------------- | --------- | ---------------------------------------------------------------------------------- |
| `aria-label?`        | `string`                                              | —         | Names the element for assistive technology. Pass either this or `aria-labelledby`. |
| `aria-labelledby?`   | `string`                                              | —         | Identifies the element that names this one. Pass either this or `aria-label`.      |
| `color?`             | `'blue' \| 'error' \| 'gray' \| 'warning' \| 'white'` | `'blue'`  | The color scheme of the indicator.                                                 |
| `size?`              | `'large' \| 'medium' \| 'small'`                      | `'small'` | The diameter of the indicator.                                                     |
| `circleStrokeWidth?` | `number`                                              | `1`       | The width of the outer ring in pixels.                                             |

Valid prop combinations:

- `aria-label: string`, `aria-labelledby?: undefined`
- `aria-label?: undefined`, `aria-labelledby: string`

Inherits `className`, `render`, `style`, `aria-valuetext`, `format`, `getAriaValueText`, `locale`, `max`, `min`, `value` from [Base UI Progress.Root](https://base-ui.com/react/components/progress#root).

**Data attributes**

| Attribute            | Description                                          |
| -------------------- | ---------------------------------------------------- |
| `data-complete`      | Present when the progress has completed.             |
| `data-indeterminate` | Present when the progress is in indeterminate state. |
| `data-progressing`   | Present while the progress is progressing.           |

### ProgressIndicator

Visualizes the completion status of the task. Renders a `<div>` element.

Inherits `className`, `render`, `style` from [Base UI Progress.Indicator](https://base-ui.com/react/components/progress#indicator).

**Data attributes**

| Attribute            | Description                                          |
| -------------------- | ---------------------------------------------------- |
| `data-complete`      | Present when the progress has completed.             |
| `data-indeterminate` | Present when the progress is in indeterminate state. |
| `data-progressing`   | Present while the progress is progressing.           |

### ProgressLabel

An accessible label for the progress bar. Renders a `<span>` element.

Inherits `className`, `render`, `style` from [Base UI Progress.Label](https://base-ui.com/react/components/progress#label).

**Data attributes**

| Attribute            | Description                                          |
| -------------------- | ---------------------------------------------------- |
| `data-complete`      | Present when the progress has completed.             |
| `data-indeterminate` | Present when the progress is in indeterminate state. |
| `data-progressing`   | Present while the progress is progressing.           |

### ProgressTrack

Contains the progress bar indicator. Renders a `<div>` element.

Inherits `className`, `render`, `style` from [Base UI Progress.Track](https://base-ui.com/react/components/progress#track).

**Data attributes**

| Attribute            | Description                                          |
| -------------------- | ---------------------------------------------------- |
| `data-complete`      | Present when the progress has completed.             |
| `data-indeterminate` | Present when the progress is in indeterminate state. |
| `data-progressing`   | Present while the progress is progressing.           |

### ProgressValue

A text element displaying the current value. Renders a `<span>` element.

Inherits `children`, `className`, `render`, `style` from [Base UI Progress.Value](https://base-ui.com/react/components/progress#value).

**Data attributes**

| Attribute            | Description                                          |
| -------------------- | ---------------------------------------------------- |
| `data-complete`      | Present when the progress has completed.             |
| `data-indeterminate` | Present when the progress is in indeterminate state. |
| `data-progressing`   | Present while the progress is progressing.           |
