A repository's GitHub stars, counted up with a filling star and a burst of particles.
Installation
Usage
import {
GithubStars,
GithubStarsIcon,
GithubStarsLogo,
GithubStarsNumber,
GithubStarsParticles,
} from '@animate-ui/react/primitives/github-stars';
export function Stars() {
return (
<GithubStars
username="imskyleen"
repo="animate-ui"
className="flex items-center gap-2"
>
<GithubStarsLogo className="size-6" />
<GithubStarsNumber />
<GithubStarsParticles>
<GithubStarsIcon icon={StarIcon} className="size-4" color="gold" />
</GithubStarsParticles>
</GithubStars>
);
}The count is fetched from the GitHub API (api.github.com/repos/<username>/<repo>), unauthenticated. To avoid the request (rate limits, server-side data), pass the count with value.
Animation
- Once the count is loaded, the number counts up from 0 with rolling digits (Sliding Number).
- The star fills from the bottom as the number climbs, and bursts into particles when the count is reached.
- Nothing is rendered until the count is loaded (with
asChild, the child is there but hidden); the container is markedaria-busymeanwhile. - With
inView, the request waits for the element to be on screen. - Under reduced motion, the digits change without rolling and the burst is skipped.
API Reference
GithubStars
| Prop | Type | Default |
|---|---|---|
asChild? | boolean | false |
username? | string | - |
repo? | string | - |
value? | number | - |
delay? | number | 0 |
children | React.ReactNode | - |
inView? | boolean | false |
inViewOnce? | boolean | true |
inViewMargin? | string | '0px' |
...props? | HTMLMotionProps<'div'> | - |
GithubStarsNumber
The count, as a Sliding Number.
| Prop | Type | Default |
|---|---|---|
padStart? | boolean | true |
...props? | Omit<SlidingNumberProps, 'number' | 'fromNumber'> | - |
GithubStarsIcon
Renders the icon twice: empty, and filled as the count climbs.
| Prop | Type | Default |
|---|---|---|
icon | React.ElementType | - |
color? | string | 'currentColor' |
activeClassName? | string | - |
...props? | React.ComponentProps<T> | - |
GithubStarsParticles
Bursts when the count is reached. Takes the ParticlesEffect props.
| Prop | Type | Default |
|---|---|---|
children | React.ReactElement | - |
size? | number | 4 |
...props? | ParticlesEffectProps | - |
GithubStarsLogo
The GitHub mark, labelled for screen readers. Takes svg props.
useGithubStars
Returns stars, currentStars (the displayed value), isLoading and isCompleted.