原语 / React Aria
Radio Group · React Aria
一组单选按钮,同一时间只能选中一项。
安装
React Aria 的原语保持上游 API 不变,安装只需要三步:加包、加组件、把 import 换掉。
bun add @animate-ui/react motion
bunx shadcn@latest add radio-group
bunx @animate-ui/cli@latest animate radio-group用法
从 Animate UI 引入原语,其余结构、属性与 data 属性都保持 React Aria 的写法。也可以按子路径单独引入:
import {
Label,
Radio,
RadioGroup,
} from '@animate-ui/react/primitives/react-aria';import {
Label,
Radio,
RadioGroup,
} from '@animate-ui/react/primitives/react-aria';
export function Density() {
return (
<RadioGroup defaultValue="comfortable">
<Label>Density</Label>
{['default', 'comfortable', 'compact'].map((value) => (
<Radio key={value} value={value}>
{({ isSelected }) => (
<>
<span data-slot="radio-group-indicator">
{isSelected && (
<span className="size-2 rounded-full bg-current" />
)}
</span>
{value}
</>
)}
</Radio>
))}
</RadioGroup>
);
}动效
- 选中圆点从 0 缩放淡入,弹簧 stiffness 200 / damping 16;卸载时在同样位置复制一份反向缩回。
- 按下整项缩放到 0.97(stiffness 550 / damping 30),悬停不缩放。
所有时长都会乘以 AnimateUIProvider 的 tempo,并遵守系统的减少动效设置。
API
动效相关的 transition 与 exitTransition 是 Animate UI 唯一新增的属性;其余 props 与 React Aria 完全一致。
| 属性 | 类型 | 默认值 |
|---|---|---|
| transition | Transition | { type: 'spring', stiffness: 200, damping: 16 } |
| exitTransition | Transition | the same spring as transition |
未列出的属性与上游 API 完全一致,可在 官方文档 查阅。
内容对应官方文档 2026-10-18 版本。