import React, { useEffect, useState } from 'react' import useBodyScroll from '../use-body-scroll' import useTheme from '../use-theme' import Burger from './burger' import { HeaderContext } from './header-context' const Background: React.FC< React.PropsWithChildren<{ openPanel?: boolean onClick?: React.MouseEventHandler }> > = ({ children, openPanel, onClick }) => { const theme = useTheme() return (
{children}
) } const LogoWrapper: React.FC> = ({ children }) => { const theme = useTheme() return (
{children}
) } const Links: React.FC> = ({ children, open }) => { const theme = useTheme() return (
{children}
) } const Nav: React.FC> = ({ children, openPanel }) => { const theme = useTheme() return ( ) } interface Props { logo?: JSX.Element className?: string } const defaultProps = { className: '' } type NativeAttrs = Omit, keyof Props> export type HeaderProps = Props & typeof defaultProps & NativeAttrs const Header: React.FC> = ({ logo, children, ...props }) => { const [openPanel, setOpenPanel] = useState(null) const [, setHidden] = useBodyScroll(null, { scrollLayer: true }) const isPanelOpen = openPanel !== null // disable body scroll on active header state useEffect(() => { setHidden(isPanelOpen) }, [isPanelOpen]) const toggleSmallNav = () => { if (!openPanel) { setOpenPanel('root') } else { setOpenPanel(null) } } const toggleNavItem = (newPanel: any) => { if (!openPanel || (openPanel === 'root' && openPanel !== newPanel)) { setOpenPanel(newPanel) } else { setOpenPanel(openPanel === newPanel ? null : newPanel) } } const store = { openPanel: { get: openPanel, set: setOpenPanel }, toggleNavItem } return (
{openPanel && setOpenPanel(null)} />}
) } type MemoPageComponent

= React.NamedExoticComponent

& { Context: typeof HeaderContext } type ComponentProps = Partial & Omit & NativeAttrs Header.defaultProps = defaultProps export default React.memo(Header) as MemoPageComponent