原语 / Animate UI
GitHub Stars Button · Animate UI
把仓库星数放进按钮:数字滚动、星星填充,点击可直达仓库。
安装
自有原语直接来自 @animate-ui/react,不依赖 Radix UI、Base UI 或 React Aria;装上包即可使用。
bun add @animate-ui/react motion
bunx shadcn@latest add @animate-ui/buttons-github-stars用法
直接从 @animate-ui/react 的对应子路径引入,下面就是完整示例;样式由你的类名决定。
import {
GitHubStarsButton,
GitHubStarsButtonIcon,
GitHubStarsButtonLogo,
GitHubStarsButtonNumber,
GitHubStarsButtonParticles,
} from '@/components/animate-ui/buttons/github-stars';
export function Stars() {
return (
<GitHubStarsButton username="imskyleen" repo="animate-ui" asChild>
<a href="https://github.com/imskyleen/animate-ui">
<GitHubStarsButtonLogo className="size-4" />
<GitHubStarsButtonNumber />
<GitHubStarsButtonParticles className="text-yellow-500">
<GitHubStarsButtonIcon icon={StarIcon} color="gold" />
</GitHubStarsButtonParticles>
</a>
</GitHubStarsButton>
);
}动效
- 数据加载前保持 visibility: hidden 与 aria-busy,避免闪现占位数值。
- 加载后数字滚动、星星自下而上填充并撒出粒子;减少动效下直接显示结果。
所有时长都会乘以 AnimateUIProvider 的 tempo,并遵守系统的减少动效设置。
API
动效相关的 transition 与 exitTransition 是 Animate UI 唯一新增的属性;其余 props 见上表。
| 属性 | 类型 | 默认值 |
|---|---|---|
| variant | 'default' | 'accent' | 'outline' | 'ghost' | null | 'default' |
| size | 'default' | 'sm' | 'lg' | null | 'default' |
| username | string | — |
| repo | string | — |
| value | number | — |
| delay | number | 0 |
| inView | boolean | false |
| inViewOnce | boolean | true |
| inViewMargin | string | '0px' |
| hoverScale | number | 1 |
| tapScale | number | 0.97 |
| transition | Transition | { type: 'spring', stiffness: 550, damping: 30, restSpeed: 10 } |
| asChild | boolean | false |
| …props | HTMLMotionProps<'button'> | — |
未列出的属性与上游 API 完全一致,可在 官方文档 查阅。
内容对应官方文档 2026-10-18 版本。