原语 / Base UI
Progress · Base UI
展示耗时任务完成进度的进度条,支持不确定状态。
安装
Base UI 的原语保持上游 API 不变,安装只需要三步:加包、加组件、把 import 换掉。
bun add @animate-ui/react motion
bunx shadcn@latest add progress
bunx @animate-ui/cli@latest animate progress用法
从 Animate UI 引入原语,其余结构、属性与 data 属性都保持 Base UI 的写法。也可以按子路径单独引入:
import { Progress } from '@animate-ui/react/primitives/base-ui/progress';import { Progress } from '@animate-ui/react/primitives/base-ui/progress';
export function Upload({ value }: { value: number }) {
return (
<Progress.Root value={value}>
<Progress.Label>Uploading</Progress.Label>
<Progress.Value />
<Progress.Track className="h-2 overflow-hidden rounded-full">
<Progress.Indicator className="bg-primary" />
</Progress.Track>
</Progress.Root>
);
}动效
- 进度条宽度以 stiffness 300 / damping 35 的弹簧追随新值,约 230ms 走完大半、550ms 落定,不过冲,避免露出轨道起点。
- 数值与进度条同步计数,按 Base UI 的 format 与 locale 格式化;从 min 开始增长。
所有时长都会乘以 AnimateUIProvider 的 tempo,并遵守系统的减少动效设置。
API
动效相关的 transition 与 exitTransition 是 Animate UI 唯一新增的属性;其余 props 与 Base UI 完全一致。
| 属性 | 类型 | 默认值 |
|---|---|---|
| transition | Transition | { type: 'spring', stiffness: 300, damping: 35, restDelta: 0.01, restSpeed: 0.1 } |
| transition | Transition | { type: 'spring', stiffness: 300, damping: 35, restDelta: 0.01, restSpeed: 0.1 } |
未列出的属性与上游 API 完全一致,可在 官方文档 查阅。
内容对应官方文档 2026-10-18 版本。