GitHub Stars Button
gaia/github-stars-buttonFreeComponent
A beautiful button that displays your GitHub repository's star count with real-time data fetching.
Install it
npx shadcn@latest add https://ui.heygaia.io/r/github-stars-button.jsonSource
1"use client";23import { StarFilledIcon } from "@radix-ui/react-icons";4import { useEffect, useState } from "react";5import { Github } from "@/components/icons/social-icons";6import { RaisedButton } from "@/registry/new-york/ui/raised-button";78interface GitHubRepo {9 stargazers_count: number;10 html_url: string;11 name: string;12 full_name: string;13}1415interface GitHubStarsButtonProps {16 repo: string;17 showLabel?: boolean;18 size?: "sm" | "default" | "lg";19 className?: string;20}2122export function GitHubStarsButton({23 repo,24 showLabel = true,25 size = "sm",26 className,27}: GitHubStarsButtonProps) {28 const [starCount, setStarCount] = useState<number | null>(null);29 const [isLoading, setIsLoading] = useState(true);3031 useEffect(() => {32 let isMounted = true;3334 async function fetchStars() {35 try {36 const response = await fetch(`https://api.github.com/repos/${repo}`);3738 if (!response.ok) {39 throw new Error("Failed to fetch repository data");40 }4142 const data: GitHubRepo = await response.json();4344 if (isMounted) {45 setStarCount(data.stargazers_count);46 setIsLoading(false);47 }48 } catch (error) {49 console.error("Error fetching GitHub stars:", error);50 if (isMounted) {51 setIsLoading(false);52 }53 }54 }5556 fetchStars();5758 return () => {59 isMounted = false;60 };61 }, [repo]);6263 return (64 <a65 href={`https://github.com/${repo}`}66 target="_blank"67 rel="noopener noreferrer"68 >69 <RaisedButton70 size={size}71 className={`group rounded-xl border-0! ${className || ""}`}72 color="#1c1c1c"73 >74 <div className="flex items-center">75 <Github />76 {showLabel && <span className="ml-1">GitHub</span>}77 </div>78 <div className="flex items-center gap-1 text-sm">79 <StarFilledIcon className="relative top-px size-4 text-white group-hover:text-yellow-300" />80 <span className="font-medium text-white">81 {isLoading ? "..." : starCount || "0"}82 </span>83 </div>84 </RaisedButton>85 </a>86 );87}
What it pulls in
npm packages
Other registry items
Files it writes
More from gaia
All 26 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Area Chartarea-chart | gaia | Components | Free | 1 dep | |
| Author Tooltipauthor-tooltip | gaia | Components | Free | no deps | |
| Bar Chartbar-chart | gaia | Components | Free | 1 dep | |
| Composercomposer | gaia | Components | Free | no deps | |
| Email Compose Cardemail-compose-card | gaia | Components | Free | no deps | |
| Gauge Chartgauge-chart | gaia | Components | Free | 1 dep | |
| Holo Cardholo-card | gaia | Components | Free | 1 dep · 2 files | |
| Iconsicons | gaia | Components | Free | 2 deps |
