跳到正文
目录与搜索
⌘K

原语 / Radix UI

Progress · Radix UI

展示任务完成进度的进度条,支持确定与不确定状态。

安装

Radix UI 的原语保持上游 API 不变,安装只需要三步:加包、加组件、把 import 换掉。

终端
bun add @animate-ui/react motion
bunx shadcn@latest add progress
bunx @animate-ui/cli@latest animate progress

用法

从 Animate UI 引入原语,其余结构、属性与 data 属性都保持 Radix UI 的写法。也可以按子路径单独引入:

tsx
import { Progress } from '@animate-ui/react/primitives/radix-ui';
progress.tsx
import { Progress } from '@animate-ui/react/primitives/radix-ui';

export function Upload({ value }: { value: number }) {
  return (
    <Progress.Root value={value} className="h-2 overflow-hidden rounded-full">
      <Progress.Indicator
        className="size-full bg-primary"
        style={{ transform: `translateX(-${100 - value}%)` }}
      />
    </Progress.Root>
  );
}

动效

  • 指示器以 stiffness 300 / damping 35 的弹簧追随新值,约 230ms 走完大半、550ms 落定,不过冲。
  • 挂载时从当前值开始,不播放增长动画;RTL 布局由 Radix 的 inset 规则处理。

所有时长都会乘以 AnimateUIProvider 的 tempo,并遵守系统的减少动效设置。

API

动效相关的 transition 与 exitTransition 是 Animate UI 唯一新增的属性;其余 props 与 Radix UI 完全一致。

属性类型默认值
transitionTransition{ type: 'spring', stiffness: 300, damping: 35, restDelta: 0.01, restSpeed: 0.1 }

未列出的属性与上游 API 完全一致,可在 官方文档 查阅。

内容对应官方文档 2026-10-18 版本。