import { useState, useEffect } from 'react'
import type { ReactNode } from 'react'
import { Button } from './Button'
interface MobileMenuProps {
children: ReactNode
'aria-label'?: string
}
function HamburgerIcon({ isOpen }: { isOpen: boolean }): React.ReactElement {
return (
)
}
export function MobileMenu({ children, 'aria-label': ariaLabel }: MobileMenuProps): React.ReactElement {
const [isOpen, setIsOpen] = useState(false)
useEffect(() => {
if (isOpen) {
document.body.style.overflow = 'hidden'
} else {
document.body.style.overflow = ''
}
return () => {
document.body.style.overflow = ''
}
}, [isOpen])
useEffect(() => {
const handleEscape = (e: KeyboardEvent): void => {
if (e.key === 'Escape' && isOpen) {
setIsOpen(false)
}
}
document.addEventListener('keydown', handleEscape)
return () => document.removeEventListener('keydown', handleEscape)
}, [isOpen])
return (
<>
setIsOpen(!isOpen)}
ariaLabel={ariaLabel ?? 'Toggle menu'}
/>
{isOpen && (
setIsOpen(false)}
ariaLabel={ariaLabel ?? 'Mobile menu'}
>
{children}
)}
>
)
}
function MobileMenuButton({
isOpen,
onClick,
ariaLabel,
}: {
isOpen: boolean
onClick: () => void
ariaLabel: string
}): React.ReactElement {
return (
)
}
function MobileMenuOverlay({ onClose }: { onClose: () => void }): React.ReactElement {
return (
)
}
function MobileMenuContent({
onClose,
ariaLabel,
children,
}: {
onClose: () => void
ariaLabel: string
children: ReactNode
}): React.ReactElement {
return (
)
}
function MobileMenuDrawer({
onClose,
ariaLabel,
children,
}: {
onClose: () => void
ariaLabel: string
children: ReactNode
}): React.ReactElement {
return (
<>
{children}
>
)
}