Back to PrequelUIYou are on GitHub Stars.

GitHub Stars

A repository star count that ticks up and bursts into particles.

Available inAvailable in React, Vue, Svelte, Solid, JavaScript· All five frameworks
PrequelUI

Libraries

PrequelUI

Motion

Spring + short tween

Reduced motion

Fade in place
github-stars.tsx
Play with the real component, then read the code it ships with.All components
01

Installation

Installing for React·components/prequelui/github-stars.tsx

Add the component

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/github-stars.json
npmthe default on every machine

First component? Set up your project first

Frameworks

The live preview is React. Each tab below is the file that ships for that framework, with the same durations, springs and reduced-motion rule.

5 runtimes
github-stars.tsx
"use client";

import * as React from "react";
import { AnimatePresence, motion } from "motion/react";
import { Github, Star } from "lucide-react";
import { cn } from "@/lib/utils";
import { swapTween, useReduceMotion } from "./motion";

export type GitHubStarsProps = Omit<React.ComponentProps<"a">, "href"> & {
  repo?: string;
  href?: string;
  count?: number | null;
  defaultCount?: number | null;
  label?: string;
  showLabel?: boolean;
};

function formatCount(value: number) {
  if (value < 1000) return String(value);
  return new Intl.NumberFormat("en", {
    notation: "compact",
    maximumFractionDigits: 1,
  }).format(value);
}

export function GitHubStars({
  repo,
  href,
  count,
  defaultCount = null,
  label = "GitHub",
  showLabel = true,
  className,
  ...props
}: GitHubStarsProps) {
  const reduce = useReduceMotion();
  const [live, setLive] = React.useState<number | null>(defaultCount);

  React.useEffect(() => {
    if (count !== undefined || !repo) return;
    let active = true;
    fetch(`https://api.github.com/repos/${repo}`, {
      headers: { Accept: "application/vnd.github+json" },
    })
      .then((response) => (response.ok ? response.json() : null))
      .then((data) => {
        if (active && data && typeof data.stargazers_count === "number") {
          setLive(data.stargazers_count);
        }
      })
      .catch(() => {});
    return () => {
      active = false;
    };
  }, [count, repo]);

  const value = count !== undefined ? count : live;
  const destination = href ?? (repo ? `https://github.com/${repo}` : undefined);

  return (
    <a
      data-slot="github-stars"
      href={destination}
      target="_blank"
      rel="noreferrer noopener"
      aria-label={repo ? `${label} stars on GitHub` : "GitHub"}
      className={cn(
        "group inline-flex h-8 items-center gap-1.5 rounded-full border bg-background px-2.5 text-[13px] text-muted-foreground outline-none transition-colors hover:bg-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50",
        className,
      )}
      {...props}
    >
      <Github className="size-4 shrink-0" strokeWidth={1.8} aria-hidden="true" />
      {showLabel ? <span className="truncate">{label}</span> : null}
      <span aria-hidden="true" className="h-3.5 w-px shrink-0 bg-border" />
      <span
        aria-hidden="true"
        className="inline-flex items-center transition-transform duration-300 ease-[cubic-bezier(0.34,1.56,0.64,1)] group-hover:-rotate-12 group-hover:scale-110 motion-reduce:transition-none"
      >
        <Star className="size-3.5 shrink-0 transition-colors group-hover:fill-current" />
      </span>
      <AnimatePresence mode="popLayout" initial={false}>
        <motion.span
          key={value ?? "star"}
          initial={{ opacity: 0, y: 4 }}
          animate={{ opacity: 1, y: 0 }}
          exit={{ opacity: 0, y: -4 }}
          transition={reduce ? { duration: 0 } : swapTween}
          className="tabular-nums"
        >
          {value === null || value === undefined ? "Star" : formatCount(value)}
        </motion.span>
      </AnimatePresence>
    </a>
  );
}

Install

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/github-stars.json
npmthe default on every machine

Dependencies

motion lucide-react

The registry keeps the component source, its motion tokens and the reduced-motion branch together, so the install never pulls a different animation from the preview.

02

Usage

Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.

github-stars.tsx
import { GitHubStars } from "@/components/prequelui/github-stars";

export default function Demo() {
  return (
    <GitHubStars href="https://github.com/prequelui/prequelui-animate" />
  );
}
import { GitHubStars } from "@/components/prequelui/github-stars";

export function Variant() {
  return (
    <GitHubStars tempo={1.2}>
      …
    </GitHubStars>
  );
}
03

Animation

A quiet GitHub pill: the star leans and fills under the pointer, while the count swaps with a short vertical crossfade. When no count is supplied the label stays honest and simply reads Star.

  • Star hover: -12° and 1.1 scale on a soft spring.
  • Count swap: 150 ms with the shared ease-out curve.
  • The count is never invented: it comes from props or the GitHub API.
  • Reduced motion keeps the colour change and skips the movement.
spring 500 / 50pause off-screenpointer-awareinterruptible
04

API Reference

Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.

GitHubStars

PropTypeDefault
repostring—
hrefstring—
countnumber | null—
labelstring"GitHub"
showLabelbooleantrue

Next component

Motion Grid

A dot grid that plays frame-by-frame motion as a loader or state.