跳到正文
目录与搜索
⌘K

原语 / 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 的对应子路径引入,下面就是完整示例;样式由你的类名决定。

github-stars-button.tsx
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'
usernamestring—
repostring—
valuenumber—
delaynumber0
inViewbooleanfalse
inViewOncebooleantrue
inViewMarginstring'0px'
hoverScalenumber1
tapScalenumber0.97
transitionTransition{ type: 'spring', stiffness: 550, damping: 30, restSpeed: 10 }
asChildbooleanfalse
…propsHTMLMotionProps<'button'>—

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

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