1. Components
  2. Feedback
  3. Progress Bar

Progress Bar

Progress bar show either determinate or indeterminate progress of an operation over time.

<ProgressBar value={75} />

Installation

npx dotui-cli@latest add progress

Anatomy

import { ProgressBar } from "@/components/core/progress-bar";
 
<ProgressBar value={30} />;
import { Label } from "@/components/core/field";
import {
  ProgressBarRoot,
  ProgressBarValueLabel,
  ProgressBarIndicator,
} from "@/components/core/progress-bar";
 
<ProgressBarRoot value={30}>
  <div className="flex items-center justify-between gap-2">
    <Label>Progress</Label>
    <ProgressBarValueLabel />
  </div>
  <ProgressBarIndicator />
</ProgressBarRoot>;

Visual options

Variant

Use the variant prop to control the visual style of the Progress. The default variant is "default".

primary
success
accent
danger
warning
<ProgressBar variant="primary" />
<ProgressBar variant="success" />
<ProgressBar variant="accent" />
<ProgressBar variant="danger" />
<ProgressBar variant="warning" />

Size

Use the size prop to control the size of the Progress. The default variant is "md".

sm
md
lg
<ProgressBar size="sm" />
<ProgressBar size="md" />
<ProgressBar size="lg" />

Labelling

Label

A visual label can be provided using the label prop, or a hidden label using aria-label prop.

Loading...
<ProgressBar aria-label="loading" />
<ProgressBar label="loading..." />

Value label

Set the showValueLabel prop to true to display the current value of the progress bar.

Loading75%
<ProgressBar label="Loading" showValueLabel value={75} />

Format options

Values are formatted as a percentage by default, but this can be modified by using the formatOptions prop to specify a different format.

Sending…¥60
<Progress
  label="Sending…"
  showValueLabel
  formatOptions={{ style: "currency", currency: "JPY" }}
  value={60}
/>

Custom value label

The valueLabel prop allows the formatted value to be replaced with a custom string.

Feeding…30 of 100 dogs
<Progress
  label="Feeding…"
  showValueLabel
  valueLabel="30 of 100 dogs"
  value={30}
/>

Value

Value scale

A custom value scale can be used by setting the minValue and maxValue props.

<Progress
  aria-label="Min and max values"
  minValue={50}
  maxValue={150}
  value={100}
/>

Indeterminate

The isIndeterminate prop can be used to represent an interdeterminate operation.

<ProgressBar isIndeterminate aria-label="Loading" />

Duration

Use the duration prop to indicate an approximate duration of an indeterminate task. Once the duration times out, the progress bar will start an indeterminate animation.

<ProgressBar duration="30s" />

Composition

If you need to customize things further, you can drop down to the composition level.

Progress
50%
<ProgressBarRoot value={50} className="flex-row items-center gap-4">
  <Label>Progress</Label>
  <ProgressBarIndicator />
  <ProgressBarValueLabel />
</ProgressBarRoot>

API Reference

PropTypeDefaultDescription
variant"primary" | "primary" | "danger" | "success" | "warning""default"The visual style of the progress indicator.
size"sm" | "md" | "lg""md"The size of the progress indicator
isIndeterminateboolean-Whether presentation is indeterminate when progress isn't known.
duration`${number}s` | `${number}ms`'0s'The estimated duration of an indeterminate progress.
formatOptionsIntl.NumberFormatOptions{style: 'percent'}The display format of the value label.
valueLabelReactNode-The content to display as the value's label (e.g. 1 of 4).
showValueLabelbooleanfalseWhether the value's label is displayed.
valuenumber0The current value (controlled).
minValuenumber0The smallest value allowed for the input.
maxValuenumber100The largest value allowed for the input.
childrenReactNode | (values: ProgressBarRenderProps & {defaultChildren: ReactNode | undefined}) => ReactNode-The children of the component. A function may be provided to alter the children based on component state.
classNamestring-The CSS className for the element.
styleCSSProperties | (values: ProgressBarRenderProps & {defaultStyle: CSSProperties}) => CSSProperties-The inline style for the element. A function may be provided to compute the style based on component state.

Last updated on 6/19/2024

dotUI

Bringing singularity to the web.

Built by mehdibha. The source code is available on GitHub.