Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: github star button #1851

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions site/src/components/GitHubStars.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useState, useEffect } from 'react';
import { Icon, faGithub } from '@rivet-gg/icons';
import { cn } from '@rivet-gg/components';

interface GitHubStarsProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
repo?: string;
}

function formatNumber(num: number): string {
if (num >= 1000) {
return `${(num / 1000).toFixed(1)}k`;
}
return num.toString();
}

export async function GitHubStars({ repo = 'rivet-gg/rivet', className, ...props }: GitHubStarsProps) {
try {
const response = await fetch(`https://api.github.com/repos/${repo}`);
const data = await response.json();
const { stargazers_count: stars } = data;

return (
<a
href={`https://github.com/${repo}`}
target='_blank'
rel='noreferrer'
className={cn(
"md:bg-white/10 rounded-md px-4 h-10 flex items-center gap-2 md:hover:bg-white/20 transition-colors",
className
)}
{...props}>
<Icon icon={faGithub} /> <span className="hidden md:inline">{stars ? `${formatNumber(stars)} Stars` : 'GitHub'}</span>
</a>
);
} catch (err) {
console.error('Failed to fetch stars', err);
return null;
}
}
15 changes: 7 additions & 8 deletions site/src/components/v2/FancyHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { faDiscord, faGithub, Icon } from '@rivet-gg/icons';
import { AnimatePresence, motion } from 'unframer';
import { HeaderPopupProductMenu } from '../HeaderPopupProductMenu';
import { HeaderPopupSolutionsMenu } from '../HeaderPopupSolutionsMenu';
import { GitHubStars } from '@/components/GitHubStars';

type Subnav = false | 'product' | 'solutions';

Expand All @@ -19,7 +20,7 @@ interface FancyHeaderProps {
mobileBreadcrumbs?: ReactNode;
}

export function FancyHeader({ active, subnav }: FancyHeaderProps) {
export function FancyHeader({ active, subnav, mobileBreadcrumbs }: FancyHeaderProps) {
const [isSubnavOpen, setIsSubnavOpen] = useState<Subnav>(false);
const prev = useRef<Subnav>(false);

Expand Down Expand Up @@ -72,24 +73,22 @@ export function FancyHeader({ active, subnav }: FancyHeaderProps) {
</div>
}
links={
<>
<RivetHeader.NavItem asChild className='-m-2 p-2'>
<div className="flex flex-row items-center">
<RivetHeader.NavItem asChild className='p-2 mr-4'>
<Link href='/discord' className='text-white/90'>
<Icon icon={faDiscord} className='drop-shadow-md' />
</Link>
</RivetHeader.NavItem>
<RivetHeader.NavItem asChild className='p-2'>
<Link href='https://github.com/rivet-gg/rivet' target='_blank' className='text-white/90'>
<Icon icon={faGithub} className='drop-shadow-md' />
</Link>
<RivetHeader.NavItem asChild className='flex mr-2'>
<GitHubStars className='text-white/90 hover:text-white transition-colors w-full' />
</RivetHeader.NavItem>
<Button
variant='secondary'
asChild
className='font-v2 subpixel-antialiased hover:border-white/20'>
<Link href='https://hub.rivet.gg'>Sign In</Link>
</Button>
</>
</div>
}
mobileBreadcrumbs={<DocsMobileNavigation />}
breadcrumbs={
Expand Down
Loading