原语 / Animate UI
Ripple Button · Animate UI
从点击位置向外扩散涟漪的按钮。
安装
自有原语直接来自 @animate-ui/react,不依赖 Radix UI、Base UI 或 React Aria;装上包即可使用。
bun add @animate-ui/react motion用法
直接从 @animate-ui/react 的对应子路径引入,下面就是完整示例;样式由你的类名决定。
import {
RippleButton,
RippleButtonRipples,
} from '@animate-ui/react/primitives/buttons/ripple';
export function Send() {
return (
<RippleButton className="[--ripple-button-ripple-color:white]">
Send
<RippleButtonRipples />
</RippleButton>
);
}动效
- 每次点击从指针位置发出一圈涟漪,增长到 scale 并淡出,历时 0.6s 后移除。
- 连续点击会各自生成涟漪,互不影响;减少动效下不播放。
所有时长都会乘以 AnimateUIProvider 的 tempo,并遵守系统的减少动效设置。
API
动效相关的 transition 与 exitTransition 是 Animate UI 唯一新增的属性;其余 props 见上表。
| 属性 | 类型 | 默认值 |
|---|---|---|
| hoverScale | number | 1 |
| tapScale | number | 0.97 |
| transition | Transition | { type: 'spring', stiffness: 550, damping: 30, restSpeed: 10 } |
| asChild | boolean | false |
| …props | HTMLMotionProps<'button'> | — |
| color | string | 'var(--ripple-button-ripple-color)' |
| scale | number | 10 |
| transition | Transition | { duration: 0.6, ease: 'easeOut' } |
| asChild | boolean | false |
| …props | HTMLMotionProps<'span'> | — |
| --ripple-button-ripple-color | color | — |
未列出的属性与上游 API 完全一致,可在 官方文档 查阅。
内容对应官方文档 2026-10-18 版本。