Created
August 3, 2022 21:03
-
-
Save lloydjatkinson/96e53a0c398848e678773547a4f29684 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const MobileNavigationMenu = ({ targetSelector }: { targetSelector: string }) => { | |
if (!document) { | |
// We're in SSR/SSG. Render fallback content of a menu button in the closed stated. | |
return <MenuButton isOpen={ false } />; | |
} | |
const menu = document.querySelector(targetSelector); | |
if (!menu) return null; | |
const [isOpen, setIsOpen] = useState(false); | |
useEffect(() => { | |
if (isOpen) { | |
menu.classList.remove('hidden'); | |
menu.classList.add('block'); | |
} else { | |
menu.classList.remove('block'); | |
menu.classList.add('hidden'); | |
} | |
}, [isOpen]); | |
return ( | |
<> | |
{ isOpen } | |
<MenuButton isOpen={ isOpen } onChange={ setIsOpen } /> | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment