A button showing a repository's GitHub stars, counted up with a filling star.
Installation
Usage
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>
);
}A button built on GitHub Stars: its parts are GitHub Stars' (GithubStarsLogo, GithubStarsNumber, GithubStarsIcon, GithubStarsParticles), exported here under the button's name. The count is fetched from the GitHub API (api.github.com/repos/<username>/<repo>), unauthenticated; pass it with value to skip the request.
Animation
- The button stays hidden (
visibility: hidden,aria-busy) until the count is loaded. Then the number counts up from 0 with rolling digits (Sliding Number), the star fills from the bottom as it climbs, and bursts into particles when the count is reached. - Pressing scales the button to
tapScale(0.97), on Motion's spring for scale (stiffness: 550, damping: 30). It doesn't scale on hover, unless you sethoverScale. <AnimateUIProvider tempo>paces the press spring.- Under reduced motion, the digits change without rolling, the burst is skipped and the button doesn't scale.
API Reference
GitHubStarsButton
| Prop | Type | Default |
|---|---|---|
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'> | - |
GitHubStarsButtonLogo, GitHubStarsButtonNumber, GitHubStarsButtonIcon, GitHubStarsButtonParticles
The parts of GitHub Stars: GithubStarsLogo, GithubStarsNumber, GithubStarsIcon and GithubStarsParticles.