A button showing a repository's GitHub stars, counted up with a filling star.
Installation
Usage
<script setup lang="ts">
import {
GitHubStarsButton,
GitHubStarsButtonIcon,
GitHubStarsButtonLogo,
GitHubStarsButtonNumber,
GitHubStarsButtonParticles,
} from '@/components/animate-ui/buttons/github-stars';
import StarIcon from './StarIcon.vue';
</script>
<template>
<GitHubStarsButton username="imskyleen" repo="animate-ui" as-child>
<a href="https://github.com/imskyleen/animate-ui">
<GitHubStarsButtonLogo class="size-4" />
<GitHubStarsButtonNumber />
<GitHubStarsButtonParticles class="text-yellow-500">
<GitHubStarsButtonIcon :icon="StarIcon" color="gold" />
</GitHubStarsButtonParticles>
</a>
</GitHubStarsButton>
</template>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
tap-scale(0.97), on Motion's spring for scale (stiffness: 550, damping: 30). It doesn't scale on hover, unless you sethover-scale. <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 |
in-view? | boolean | false |
in-view-once? | boolean | true |
in-view-margin? | string | '0px' |
hover-scale? | number | 1 |
tap-scale? | number | 0.97 |
transition? | Transition | { type: 'spring', stiffness: 550, damping: 30, restSpeed: 10 } |
as-child? | boolean | false |
...props? | HTMLMotionProps<'button'> | - |
GitHubStarsButtonLogo, GitHubStarsButtonNumber, GitHubStarsButtonIcon, GitHubStarsButtonParticles
The parts of GitHub Stars: GithubStarsLogo, GithubStarsNumber, GithubStarsIcon and GithubStarsParticles.