From 72655a831779142f45579132883924ce10d08416 Mon Sep 17 00:00:00 2001 From: enscribe Date: Thu, 12 Sep 2024 19:59:13 -0700 Subject: [PATCH] feat: shadcn-style mobile menu --- src/components/AuthorCard.astro | 4 +-- src/components/Header.astro | 8 +++-- src/components/ui/avatar.tsx | 4 +-- src/components/ui/mobile-menu.tsx | 60 +++++++++++++++++++++++++++++++ src/components/ui/mode-toggle.tsx | 2 +- 5 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 src/components/ui/mobile-menu.tsx diff --git a/src/components/AuthorCard.astro b/src/components/AuthorCard.astro index c576f72..923007d 100644 --- a/src/components/AuthorCard.astro +++ b/src/components/AuthorCard.astro @@ -16,7 +16,7 @@ const { name, avatar, bio, pronouns, github, twitter, linkedin, website } = ---
-
+

{name}

diff --git a/src/components/Header.astro b/src/components/Header.astro index 7eb1c38..fd63cdd 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -2,6 +2,7 @@ import { ModeToggle } from '@/components/ui/mode-toggle' import Container from '@components/Container.astro' import Link from '@components/Link.astro' +import MobileMenu from '@components/ui/mobile-menu' import { NAV_LINKS, SITE } from '@consts' import { Image } from 'astro:assets' import logo from '../../public/static/logo.svg' @@ -20,8 +21,8 @@ import logo from '../../public/static/logo.svg' Logo {SITE.TITLE} -
-
diff --git a/src/components/ui/avatar.tsx b/src/components/ui/avatar.tsx index fa44279..935b211 100644 --- a/src/components/ui/avatar.tsx +++ b/src/components/ui/avatar.tsx @@ -23,7 +23,7 @@ const AvatarImage = React.forwardRef< >(({ className, ...props }, ref) => ( )) @@ -36,7 +36,7 @@ const AvatarFallback = React.forwardRef< { + const [isOpen, setIsOpen] = useState(false) + + useEffect(() => { + const handleViewTransitionStart = () => { + setIsOpen(false) + } + + document.addEventListener('astro:before-swap', handleViewTransitionStart) + + return () => { + document.removeEventListener( + 'astro:before-swap', + handleViewTransitionStart, + ) + } + }, []) + + return ( + + + + + + {NAV_LINKS.map((item) => ( + + setIsOpen(false)} + > + {item.label} + + + ))} + + + ) +} + +export default MobileMenu diff --git a/src/components/ui/mode-toggle.tsx b/src/components/ui/mode-toggle.tsx index 0092b0f..591f617 100644 --- a/src/components/ui/mode-toggle.tsx +++ b/src/components/ui/mode-toggle.tsx @@ -40,7 +40,7 @@ export function ModeToggle() { Toggle theme - + setThemeState('theme-light')}> Light