# ProgressBar 进度条 · HeroUI

> 进度条用于展示某项操作随时间变化的确定或不确定进度。

- 页面: https://jiguang132.com/zh/systems/heroui/docs/components/progress-bar
- 改编自: HeroUI 文档 (Apache-2.0) @ 60edd8ed751b1d2a270623fbb182bbcfa8baa9af

## 引入

```tsx
import { ProgressBar, Label } from '@heroui/react';
```

### 用法


> 示例 `progress-bar-basic`: 交互预览见 https://jiguang132.com/zh/systems/heroui/docs/components/progress-bar


### 组件结构

```tsx
import { ProgressBar, Label } from '@heroui/react';

export default () => (
  <ProgressBar value={60}>
    <Label>Loading</Label>
    <ProgressBar.Output />
    <ProgressBar.Track>
      <ProgressBar.Fill />
    </ProgressBar.Track>
  </ProgressBar>
);
```

### 尺寸


> 示例 `progress-bar-sizes`: 交互预览见 https://jiguang132.com/zh/systems/heroui/docs/components/progress-bar


### 颜色


> 示例 `progress-bar-colors`: 交互预览见 https://jiguang132.com/zh/systems/heroui/docs/components/progress-bar


### 不确定进度

在无法确定具体进度时，使用 `isIndeterminate`。


> 示例 `progress-bar-indeterminate`: 交互预览见 https://jiguang132.com/zh/systems/heroui/docs/components/progress-bar


### 自定义数值范围

使用 `minValue`、`maxValue` 与 `formatOptions` 自定义取值范围与展示格式。


> 示例 `progress-bar-custom-value`: 交互预览见 https://jiguang132.com/zh/systems/heroui/docs/components/progress-bar


### 无可见标签

不需要可见标签时，请使用 `aria-label` 保证无障碍。


> 示例 `progress-bar-without-label`: 交互预览见 https://jiguang132.com/zh/systems/heroui/docs/components/progress-bar


## 样式

### 传入 Tailwind CSS 类

你可以为 ProgressBar 的各个部分单独添加类名：

```tsx
import { ProgressBar, Label } from '@heroui/react';

function CustomProgressBar() {
  return (
    <ProgressBar value={60}>
      <Label>Loading</Label>
      <ProgressBar.Output />
      <ProgressBar.Track className="bg-purple-100 dark:bg-purple-900">
        <ProgressBar.Fill className="bg-purple-500" />
      </ProgressBar.Track>
    </ProgressBar>
  );
}
```

### 自定义组件类

要自定义 ProgressBar 的组件类，可使用 `@layer components` 指令。
  
[了解更多](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes).

```css
@layer components {
  .progress-bar {
    @apply w-full gap-2;
  }

  .progress-bar__track {
    @apply h-3 rounded-full;
  }

  .progress-bar__fill {
    @apply rounded-full;
  }
}
```

HeroUI 遵循 [BEM](https://getbem.com/) 方法论，确保组件变体与状态可复用且易于自定义。

### CSS 类

ProgressBar 使用以下 CSS 类（[查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/progress-bar.css)）：

#### 基础与元素类

- `.progress-bar` - 基础容器（网格布局）
- `.progress-bar__output` - 数值文本展示
- `.progress-bar__track` - 轨道背景
- `.progress-bar__fill` - 轨道上已填充部分

#### 尺寸类

- `.progress-bar--sm` - 小尺寸变体（更细的轨道）
- `.progress-bar--md` - 中等尺寸变体（默认）
- `.progress-bar--lg` - 大尺寸变体（更粗的轨道）

#### 颜色类

- `.progress-bar--default` - 默认颜色变体
- `.progress-bar--accent` - 强调色变体
- `.progress-bar--success` - 成功色变体
- `.progress-bar--warning` - 警告色变体
- `.progress-bar--danger` - 危险色变体

## API 参考

### ProgressBar Props

继承自 [React Aria ProgressBar](https://react-spectrum.adobe.com/react-aria/ProgressBar.html)。

| Prop | 类型 | 默认值 | 描述 |
|------|------|--------|------|
| `value` | `number` | `0` | 当前值 |
| `minValue` | `number` | `0` | 最小值 |
| `maxValue` | `number` | `100` | 最大值 |
| `isIndeterminate` | `boolean` | `false` | 是否为不确定进度 |
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | 进度轨道尺寸 |
| `color` | `"default" \| "accent" \| "success" \| "warning" \| "danger"` | `"accent"` | 填充条颜色 |
| `formatOptions` | `Intl.NumberFormatOptions` | `{style: 'percent'}` | 数值展示的数字格式 |
| `valueLabel` | `ReactNode` | - | 自定义数值标签内容 |
| `children` | `ReactNode \| (values: ProgressBarRenderProps) => ReactNode` | - | 内容或渲染 prop |

### ProgressBarRenderProps

使用渲染 prop 模式时，会提供以下值：

| Prop | 类型 | 描述 |
|------|------|------|
| `percentage` | `number` | 进度百分比（0–100） |
| `valueText` | `string` | 格式化后的数值文本 |
| `isIndeterminate` | `boolean` | 是否为不确定进度 |

---

JGuang 全部资源索引: https://jiguang132.com/llms.txt
