GitHub Stars Wheel
animate-ui/components-animate-github-stars-wheelFreeComponent
A scrolling wheel that displays GitHub stars count.
Install it
npx shadcn@latest add https://animate-ui.com/r/components-animate-github-stars-wheel.jsonSource
1'use client';23import * as React from 'react';4import { StarIcon } from 'lucide-react';56import {7 ScrollingNumber as ScrollingNumberPrimitive,8 ScrollingNumberContainer as ScrollingNumberContainerPrimitive,9 ScrollingNumberItems as ScrollingNumberItemsPrimitive,10 ScrollingNumberHighlight as ScrollingNumberHighlightPrimitive,11 type ScrollingNumberContainerProps as ScrollingNumberContainerPrimitiveProps,12} from '@/components/animate-ui/primitives/texts/scrolling-number';13import { cn } from '@/lib/utils';14import {15 Particles,16 ParticlesEffect,17} from '@/components/animate-ui/primitives/effects/particles';1819function percentageBetween(value: number, min: number, max: number): number {20 return ((value - min) / (max - min)) * 100;21}2223type GitHubStarsWheelProps = {24 username?: string;25 repo?: string;26 direction?: 'btt' | 'ttb';27 delay?: number;28 value?: number;29 step?: number;30} & Omit<31 ScrollingNumberContainerPrimitiveProps,32 'direction' | 'number' | 'step'33>;3435function GitHubStarsWheel({36 username,37 repo,38 direction = 'btt',39 itemsSize = 35,40 sideItemsCount = 2,41 delay = 0,42 step = 100,43 value,44 className,45 ...props46}: GitHubStarsWheelProps) {47 const [stars, setStars] = React.useState(value ?? 0);48 const [currentStars, setCurrentStars] = React.useState(0);49 const [isLoading, setIsLoading] = React.useState(true);50 const roundedStars = React.useMemo(51 () => Math.round(stars / step) * step,52 [stars, step],53 );54 const isCompleted = React.useMemo(55 () => currentStars === roundedStars,56 [currentStars, roundedStars],57 );58 const fillPercentage = React.useMemo(59 () => percentageBetween(currentStars, 0, roundedStars),60 [currentStars, roundedStars],61 );6263 React.useEffect(() => {64 if (value !== undefined && username && repo) return;6566 const timeout = setTimeout(() => {67 fetch(`https://api.github.com/repos/${username}/${repo}`)68 .then((response) => response.json())69 .then((data) => {70 if (data && typeof data.stargazers_count === 'number') {71 setStars(data.stargazers_count);72 }73 })74 .catch(console.error)75 .finally(() => setIsLoading(false));76 }, delay);7778 return () => clearTimeout(timeout);79 }, [username, repo, value, delay]);8081 return (82 !isLoading && (83 <ScrollingNumberContainerPrimitive84 key={direction}85 className={cn('w-28', className)}86 direction={direction}87 number={roundedStars}88// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from Animate UI
All 580 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Avatar Groupcomponents-animate-avatar-group | Animate UI | Components | Free | 1 dep | |
| Codecomponents-animate-code | Animate UI | Components | Free | 1 dep | |
| Code Tabscomponents-animate-code-tabs | Animate UI | Components | Free | 1 dep | |
| Cursorcomponents-animate-cursor | Animate UI | Components | Free | no deps | |
| Tabscomponents-animate-tabs | Animate UI | Components | Free | no deps | |
| Tooltipcomponents-animate-tooltip | Animate UI | Components | Free | 1 dep | |
| Bubble Backgroundcomponents-backgrounds-bubble | Animate UI | Components | Free | 1 dep | |
| Fireworks Backgroundcomponents-backgrounds-fireworks | Animate UI | Components | Free | no deps |
