11'use client' ;
22
33import classnames from 'classnames' ;
4- import { MenuIcon } from 'lucide-react' ;
54import Link from 'next/link' ;
65import { usePathname } from 'next/navigation' ;
76import * as React from 'react' ;
@@ -16,6 +15,16 @@ interface MenuItemProps {
1615
1716const GITHUB_URL = 'https://github.com/resend/react-email' ;
1817
18+ async function getRepoStarCount ( ) {
19+ const res = await fetch ( 'https://api.github.com/repos/resend/react-email' ) ;
20+ const data = await res . json ( ) ;
21+ const starCount = data . stargazers_count ;
22+ if ( starCount > 999 ) {
23+ return `${ ( starCount / 1000 ) . toFixed ( 1 ) } K` ;
24+ }
25+ return starCount ;
26+ }
27+
1928function MenuItem ( { className, children, href, onClick } : MenuItemProps ) {
2029 const pathname = usePathname ( ) ;
2130 const [ , activeItem ] = pathname ?. split ( '/' ) ?? [ ] ;
@@ -67,10 +76,26 @@ function MenuItems({ onItemClick }: { onItemClick: () => void }) {
6776 ) ;
6877}
6978
79+ function MenuIcon ( ) {
80+ return (
81+ < div className = "flex flex-col gap-2" >
82+ { Array . from ( { length : 2 } ) . map ( ( _ , index ) => (
83+ < div key = { index } className = "w-5 h-px rounded-full bg-slate-11" />
84+ ) ) }
85+ </ div >
86+ ) ;
87+ }
88+
7089function SocialIcons ( { onItemClick } : { onItemClick : ( ) => void } ) {
90+ const [ starCount , setStarCount ] = React . useState < string | number > ( '' ) ;
91+
92+ React . useEffect ( ( ) => {
93+ getRepoStarCount ( ) . then ( setStarCount ) ;
94+ } , [ ] ) ;
95+
7196 return (
7297 < MenuItem
73- className = "w-8 justify-center"
98+ className = "w-fit gap-1.5 justify-center px-2 "
7499 href = { GITHUB_URL }
75100 onClick = { onItemClick }
76101 >
@@ -85,6 +110,7 @@ function SocialIcons({ onItemClick }: { onItemClick: () => void }) {
85110 fill = "currentColor"
86111 />
87112 </ svg >
113+ { starCount && < span > { starCount } </ span > }
88114 </ MenuItem >
89115 ) ;
90116}
@@ -110,7 +136,8 @@ export function Menu() {
110136 < SocialIcons onItemClick = { handleItemClick } />
111137 </ ul >
112138 </ nav >
113- < nav className = "relative flex items-center gap-2 md:hidden" >
139+ < nav className = "relative flex items-center gap-1 md:hidden" >
140+ < SocialIcons onItemClick = { handleItemClick } />
114141 < ul className = "flex gap-2" >
115142 < Drawer . Root
116143 onOpenChange = { setDrawerOpen }
@@ -121,14 +148,12 @@ export function Menu() {
121148 < MenuIcon />
122149 </ Drawer . Trigger >
123150 < Drawer . Portal >
124- < Drawer . Overlay className = "-translate-x-1/2 -translate-y-1/2 fixed top-1/2 left-1/2 z-[2] h-[200dvh] w-[200dvw] bg-slate-800/50" />
125- < Drawer . Content className = "fixed right-0 bottom-0 left-0 z-50 flex h-fit flex-col gap-8 rounded-t-xl bg-black p-8 pt-10" >
151+ < Drawer . Overlay className = "-translate-x-1/2 -translate-y-1/2 fixed top-1/2 left-1/2 z-50 h-[200dvh] w-[200dvw] bg-black/80" />
152+ < Drawer . Content className = "fixed right-0 bottom-0 left-0 z-[51] flex h-fit flex-col gap-8 rounded-t-xl bg-black border-t border-slate-5 p-8 pt-10" >
153+ < Drawer . Title className = "sr-only" > Menu</ Drawer . Title >
126154 < ul className = "flex w-full flex-col items-start gap-4" >
127155 < MenuItems onItemClick = { handleItemClick } />
128156 </ ul >
129- < ul className = "flex w-fit gap-2" >
130- < SocialIcons onItemClick = { handleItemClick } />
131- </ ul >
132157 </ Drawer . Content >
133158 </ Drawer . Portal >
134159 </ Drawer . Root >
0 commit comments