Files
maoyingjie 145a208687 docs: close documentation facts, structure and related-component mapping
HD-04 scope, against heroui ce90ea3 cn sources:

- stale/fictional content: input.md no longer claims TextField is
  unmigrated; color-field.md no longer claims ColorPicker is private;
  header.md drops the fictional Header.Root subcomponent and the stale
  'menus not migrated' wording (MenuSection label registration is now
  documented from HeaderRoot source); radio-group.md drops three copied
  CheckboxGroup wordings (variant override is Radio's, scalar emits,
  native single-value submit); input-otp.md drops the fictional
  data-complete state and lists the real missing upstream props
- toggle-button disabled row now matches the real CSS hooks
  (:disabled / [aria-disabled], with data-disabled as a marker only)
- part API / CSS classes / interactive states restored per pinned
  sources: button (full class lists + real variable-based global CSS),
  accordion (per-part tables + variant/state lists), card (per-part
  tables + variant list), switch (SwitchGroup snippet + Switch/
  SwitchGroup class lists + states), color-field Group (class list +
  states), input-otp (variant notes, global CSS, class/state lists);
  input-group gains the two upstream usage chapters
- RelatedComponents restored from the pinned componentRelationships
  (first-3, filtered against componentsMap): 64 pages rewritten,
  list-box/slider sections added, 7 empty-mapping pages' fabricated
  entries removed; RelatedShowcases left unmigrated with its real data
  inventory recorded (2 cases, showcase-site cards)
- defaults unified on implementation evidence: granularity (inferred
  day/minute) and visibleYears (full min-max span, no "or 20" fallback);
  HD-03 hand-offs resolved (trigger focus-visible noted for HD-06,
  width guards kept)
- new demos: header-collection-grouping (MenuSection/ListBoxSection
  label wiring), empty-state-collection (collection empty slot);
  empty-state page deduplicated with a boundary compatibility note
- ComponentPreview minHeight/isBgSolid restored per the 30 upstream
  marks; tabs-overflow max-w-full kept after measuring internal scroll
- tests: +3 header registration/demo cases, +1 empty-state collection
  case; full suite 110 files / 1630 tests, typecheck and build:docs
  pass
2026-10-28 22:32:10 +08:00

202 lines
7.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: ProgressBar 进度条
description: 进度条用于展示某项操作随时间变化的确定或不确定进度。
component: progress-bar
group: 组件
---
## 用法
```vue
<script setup lang="ts">
import {
Label,
ProgressBar,
ProgressBarFill,
ProgressBarOutput,
ProgressBarTrack,
} from "@heroui-vue/components";
</script>
<template>
<ProgressBar aria-label="加载中" class="w-64" :value="60">
<Label>加载中</Label>
<ProgressBarOutput />
<ProgressBarTrack>
<ProgressBarFill />
</ProgressBarTrack>
</ProgressBar>
</template>
```
<ComponentPreview name="progress-bar-basic" />
## 组件结构
```vue
<script setup lang="ts">
import {
Label,
ProgressBar,
ProgressBarFill,
ProgressBarOutput,
ProgressBarTrack,
} from "@heroui-vue/components";
</script>
<template>
<ProgressBar :value="60">
<Label>Loading</Label>
<ProgressBarOutput />
<ProgressBarTrack>
<ProgressBarFill />
</ProgressBarTrack>
</ProgressBar>
</template>
```
`ProgressBar` 渲染为 `role="progressbar"` 的容器。默认插槽为作用域插槽,可读取 `percentage`、`valueText`、`isIndeterminate`。`ProgressBarOutput` 在未提供内容时展示格式化后的数值文本。
## 示例
### 尺寸
<ComponentPreview name="progress-bar-sizes" />
### 颜色
<ComponentPreview name="progress-bar-colors" />
### 无可见标签
无需可见标签时,使用 `aria-label` 提供无障碍标签。
<ComponentPreview name="progress-bar-without-label" />
### 不确定进度
无法确定进度时使用 `isIndeterminate`。此时不输出 `aria-valuenow`,填充条进入不确定动画。
<ComponentPreview name="progress-bar-indeterminate" />
### 自定义数值范围
使用 `minValue`、`maxValue` 与 `formatOptions` 自定义取值范围与显示格式。
<ComponentPreview name="progress-bar-custom-value" />
> 控件说明:该示例与上游一致,使用本库公共 `NumberField` 与 `Select` 调节数值与格式。清空或无效输入草稿被拒绝并恢复上一个接受值;越界输入收敛到当前最小/最大值范围内,不会产生 NaN 或进度显示失配。
## 自定义样式
### Tailwind CSS
<ComponentPreview name="progress-bar-custom-styles" />
### 全局 CSS
若要自定义组件类,可使用 `@layer components` 指令。
```css
@layer components {
.hv-progress-bar {
@apply w-full gap-2;
}
.hv-progress-bar__track {
@apply h-3 rounded-full;
}
.hv-progress-bar__fill {
@apply rounded-full;
}
}
```
## 样式参考
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
### CSS 类
ProgressBar 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/progress-bar.css)):
#### 基础与元素类 [!toc]
- `.hv-progress-bar` - 基础容器(网格布局)
- `.hv-progress-bar__output` - 数值文本展示
- `.hv-progress-bar__track` - 轨道背景
- `.hv-progress-bar__fill` - 轨道上已填充部分
#### 尺寸类 [!toc]
- `.hv-progress-bar--sm` - 小尺寸变体(更细的轨道)
- `.hv-progress-bar--md` - 中等尺寸变体(默认)
- `.hv-progress-bar--lg` - 大尺寸变体(更粗的轨道)
#### 颜色类 [!toc]
- `.hv-progress-bar--default` - 默认颜色变体
- `.hv-progress-bar--accent` - 强调色变体
- `.hv-progress-bar--success` - 成功色变体
- `.hv-progress-bar--warning` - 警告色变体
- `.hv-progress-bar--danger` - 危险色变体
## API 参考
### ProgressBar
进度取值与格式化语义对齐 React Aria ProgressBar:`value` 会夹在 `[minValue, maxValue]`;`formatOptions.style` 为 `percent` 时格式化 0–1 比例,否则格式化夹紧后的原值。
| 属性 | 类型 | 默认值 | 描述 |
| ----------------- | ------------------------------------------------------------- | ---------------------- | -------------------------------------------------- |
| `value` | `number` | `0` | 当前值 |
| `minValue` | `number` | `0` | 最小值 |
| `maxValue` | `number` | `100` | 最大值 |
| `isIndeterminate` | `boolean` | `false` | 是否为不确定进度;为 true 时不输出 `aria-valuenow` |
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | 进度轨道尺寸 |
| `color` | `"default" \| "accent" \| "success" \| "warning" \| "danger"` | `"accent"` | 填充条颜色 |
| `formatOptions` | `Intl.NumberFormatOptions` | `{ style: "percent" }` | 数值展示的数字格式 |
| `valueLabel` | `string \| number` | - | 自定义数值标签内容,覆盖默认格式化文本 |
| `class` | `string \| Array \| Object` | - | 合并到根元素 |
| 默认插槽 | `{ percentage, valueText, isIndeterminate }` | - | 内容或作用域插槽 |
`$attrs` 落到根元素。无 `aria-label` / `aria-labelledby` 时,根元素通过 `aria-labelledby` 关联内部 `Label`。
### ProgressBarRenderProps
默认作用域插槽提供:
| 属性 | 类型 | 描述 |
| ----------------- | --------------------- | ------------------------------------------- |
| `percentage` | `number \| undefined` | 进度百分比(0–100);不确定时为 `undefined` |
| `valueText` | `string \| undefined` | 格式化后的数值文本 |
| `isIndeterminate` | `boolean` | 是否为不确定进度 |
### ProgressBarOutput
| 属性 | 类型 | 默认值 | 描述 |
| -------- | --------------------------- | ------ | --------------------------- |
| `class` | `string \| Array \| Object` | - | 合并到 `span` |
| 默认插槽 | - | - | 覆盖默认的 `valueText` 展示 |
渲染为 `span[data-slot="progress-bar-output"]`。
### ProgressBarTrack
| 属性 | 类型 | 默认值 | 描述 |
| -------- | --------------------------- | ------ | ------------- |
| `class` | `string \| Array \| Object` | - | 合并到 `div` |
| 默认插槽 | - | - | 通常放置 Fill |
渲染为 `div[data-slot="progress-bar-track"]`。
### ProgressBarFill
| 属性 | 类型 | 默认值 | 描述 |
| ------- | --------------------------- | ------ | -------------- |
| `class` | `string \| Array \| Object` | - | 合并到 `div` |
| `style` | `StyleValue` | - | 与计算宽度合并 |
渲染为 `div[data-slot="progress-bar-fill"]`。确定进度时宽度为 `percentage%`;不确定进度时不设置宽度,由 CSS 动画驱动。