Progress
用于展示任务完成比例或不确定状态的 Shadcn 进度条组件。
Progress 用于直观展示任务在有界范围内的完成进度,并支持未知进度的不确定状态(indeterminate)。本页示例采用 Shadcn Rhea 风格。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<div class="w-[60%]">
<wc-shadcn-progress-root
style-profile="rhea"
id="hero-progress"
aria-label="Task progress"
value="13"
value-text="13%"
>
<wc-shadcn-progress-track style-profile="rhea">
<wc-shadcn-progress-indicator
style-profile="rhea"
></wc-shadcn-progress-indicator>
</wc-shadcn-progress-track>
</wc-shadcn-progress-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const el = document.querySelector('#hero-progress');
setTimeout(() => {
if (el instanceof HTMLElement)
setElementProps(el, { value: 66, valueText: '66%' });
}, 500);
</script>将于 0.3.0-rc.1 及后续版本中提供。注册包入口后可从 @proto.ui/prototypes-shadcn/progress 导入全部部件:
import { progressRoot, progressLabel, progressTrack, progressIndicator, progressValue,} from '@proto.ui/prototypes-shadcn/progress';最小组合包含 Root、Track 和 Indicator;需要标签与数值显示时,将 Label 与 Value 放在 Track 之前以自动对齐同一标题行:
<ShadcnProgressRoot styleProfile="rhea" value={56} valueText="56%" className="w-full max-w-sm"> <ShadcnProgressLabel styleProfile="rhea">Upload progress</ShadcnProgressLabel> <ShadcnProgressValue styleProfile="rhea" /> <ShadcnProgressTrack styleProfile="rhea"> <ShadcnProgressIndicator styleProfile="rhea" /> </ShadcnProgressTrack></ShadcnProgressRoot>ProgressRoot├── ProgressLabel├── ProgressValue└── ProgressTrack └── ProgressIndicator- 数值范围与不确定态:
value自动限制在[min, max]之间(当min === max时百分比为0)。省略value或设置indeterminate={true}时进入不确定进度态,此时不再向辅助技术报告具体当前值。 - 风格预设与方向:支持
styleProfile(vega、nova、maia、lyra、mira、luma、sera、rhea、new-york-v4/new-york或inherit),并支持dir="ltr" | "rtl"与逻辑末尾对齐(ms-auto)。 - 无障碍与状态:Progress 为只读展示组件,不引入键盘焦点停靠点。
Root及各部件同步暴露value、percentage、indeterminate与status,并通过--pui-percentage驱动指示条宽度过渡。
搭配 ProgressLabel 与 ProgressValue 在轨道上方同一行展示名称与百分比。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<wc-shadcn-progress-root
style-profile="rhea"
class="w-full max-w-sm"
value="56"
value-text="56%"
>
<wc-shadcn-progress-label style-profile="rhea">
Upload progress
</wc-shadcn-progress-label>
<wc-shadcn-progress-value
style-profile="rhea"
></wc-shadcn-progress-value>
<wc-shadcn-progress-track style-profile="rhea">
<wc-shadcn-progress-indicator
style-profile="rhea"
></wc-shadcn-progress-indicator>
</wc-shadcn-progress-track>
</wc-shadcn-progress-root>受控进度(搭配 Slider)
Section titled “受控进度(搭配 Slider)”通过外部状态将 Progress 与 Slider 双向联动。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<div class="flex w-full max-w-sm flex-col gap-4">
<wc-shadcn-progress-root
style-profile="rhea"
id="controlled-progress"
value="50"
value-text="50%"
>
<wc-shadcn-progress-label style-profile="rhea">
Completion
</wc-shadcn-progress-label>
<wc-shadcn-progress-value
style-profile="rhea"
></wc-shadcn-progress-value>
<wc-shadcn-progress-track style-profile="rhea">
<wc-shadcn-progress-indicator
style-profile="rhea"
></wc-shadcn-progress-indicator>
</wc-shadcn-progress-track>
</wc-shadcn-progress-root>
<wc-shadcn-slider-root
style-profile="rhea"
id="controlled-slider"
value="50"
min="0"
max="100"
step="1"
aria-label="Progress value"
>
<wc-shadcn-slider-track style-profile="rhea">
<wc-shadcn-slider-indicator
style-profile="rhea"
></wc-shadcn-slider-indicator>
<wc-shadcn-slider-thumb
style-profile="rhea"
></wc-shadcn-slider-thumb>
</wc-shadcn-slider-track>
</wc-shadcn-slider-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const progress = document.querySelector('#controlled-progress');
const slider = document.querySelector('#controlled-slider');
if (
progress instanceof HTMLElement &&
slider instanceof HTMLElement
) {
slider.addEventListener('valueChange', (event) => {
const next = Math.round(event.detail.value);
setElementProps(slider, { value: next });
setElementProps(progress, {
value: next,
valueText: `${next}%`,
});
});
}
</script>在尚无法预估任务总进度时使用 indeterminate,并在获得确切百分比后无缝切回确定态。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<wc-shadcn-progress-root
style-profile="rhea"
class="w-full max-w-sm"
indeterminate
>
<wc-shadcn-progress-label style-profile="rhea">
Syncing workspace…
</wc-shadcn-progress-label>
<wc-shadcn-progress-value
style-profile="rhea"
></wc-shadcn-progress-value>
<wc-shadcn-progress-track style-profile="rhea">
<wc-shadcn-progress-indicator
style-profile="rhea"
></wc-shadcn-progress-indicator>
</wc-shadcn-progress-track>
</wc-shadcn-progress-root>RTL 布局
Section titled “RTL 布局”通过 dir="rtl" 配合逻辑外边距与本地化 valueText,支持阿拉伯语与希伯来语等从右向左的书写方向。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<wc-shadcn-progress-root
style-profile="rhea"
dir="rtl"
value="56"
value-text="٥٦٪"
class="w-full max-w-sm"
>
<wc-shadcn-progress-label style-profile="rhea">
تقدم الرفع
</wc-shadcn-progress-label>
<wc-shadcn-progress-value
style-profile="rhea"
></wc-shadcn-progress-value>
<wc-shadcn-progress-track style-profile="rhea">
<wc-shadcn-progress-indicator
style-profile="rhea"
></wc-shadcn-progress-indicator>
</wc-shadcn-progress-track>
</wc-shadcn-progress-root>| 属性 | 类型 | 默认值 |
|---|---|---|
value | number undefined | 省略(不确定态) |
min | number | 0 |
max | number | 100 |
indeterminate | boolean | false |
ariaLabel | string | '' |
valueText | string | '' |
dir | 'ltr' 'rtl' undefined | 继承上下文 |
styleProfile | ShadcnStyleChoice | inherit → 最近 scope → luma |
子部件与暴露状态
Section titled “子部件与暴露状态”ProgressLabel、ProgressTrack、ProgressIndicator、ProgressValue均支持可选的styleProfile覆盖。- 所有部件同步暴露只读状态
value(number)、percentage(number,0–100)、indeterminate(boolean)与status('indeterminate' | 'loading' | 'complete')。