import { Box, BoxProps, Center, CloseButton, Flex, Grid, GridItem, HStack, IconButton, IconButtonProps, useBreakpointValue, useColorModeValue, useUpdateEffect, } from '@chakra-ui/react' import { AnimatePresence, motion, useElementScroll } from 'framer-motion' import NextLink from 'next/link' import { useRouter } from 'next/router' import { forwardRef, ReactNode, Ref, useEffect, useRef, useState } from 'react' import { AiOutlineMenu } from 'react-icons/ai' import { RemoveScroll } from 'react-remove-scroll' import Logo from './logo' import { mainNavLinks, SidebarContent } from './sidebar/sidebar' import SponsorButton from './sponsor-button' import useRouteChanged from 'hooks/use-route-changed' import { getRoutes } from 'layouts/mdx' type NavLinkProps = { href: string children: ReactNode } function NavLink({ href, children }: NavLinkProps) { const router = useRouter() const bgActiveHoverColor = useColorModeValue('gray.100', 'whiteAlpha.100') const isActive = router.asPath.startsWith(href) return (
{children}
) } interface MobileNavContentProps { isOpen?: boolean onClose?: () => void } export function MobileNavContent(props: MobileNavContentProps) { const { isOpen, onClose } = props const closeBtnRef = useRef() const { pathname, asPath } = useRouter() const bgColor = useColorModeValue('white', 'gray.800') useRouteChanged(onClose) /** * Scenario: Menu is open on mobile, and user resizes to desktop/tablet viewport. * Result: We'll close the menu */ const showOnBreakpoint = useBreakpointValue({ base: true, lg: false }) useEffect(() => { if (showOnBreakpoint == false) { onClose() } }, [showOnBreakpoint, onClose]) useUpdateEffect(() => { if (isOpen) { requestAnimationFrame(() => { closeBtnRef.current?.focus() }) } }, [isOpen]) const [shadow, setShadow] = useState() return ( {isOpen && ( {mainNavLinks.map((item) => ( {item.label} ))} { setShadow(scrolled ? 'md' : undefined) }} > )} ) } // eslint-disable-next-line @typescript-eslint/no-explicit-any const ScrollView = (props: BoxProps & { onScroll?: any }) => { const { onScroll, ...rest } = props const [y, setY] = useState(0) // eslint-disable-next-line @typescript-eslint/no-explicit-any const elRef = useRef() const { scrollY } = useElementScroll(elRef) useEffect(() => { return scrollY.onChange(() => setY(scrollY.get())) }, [scrollY]) useUpdateEffect(() => { onScroll?.(y > 5 ? true : false) }, [y]) return ( ) } export const MobileNavButton = forwardRef( (props: IconButtonProps, ref: Ref) => { return ( } {...props} /> ) }, )