'use client'; import React, { ReactNode, useEffect, useRef, useState } from 'react'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import { NAV_ITEMS } from '@/components/nav'; import { NavItem } from '@/components/types'; import { Icon } from '@iconify/react'; import { motion, useCycle } from 'framer-motion'; type MenuItemWithSubMenuProps = { item: NavItem; toggleOpen: () => void; }; const sidebar = { open: (height = 1000) => ({ clipPath: `circle(${height * 2 + 200}px at 100% 0)`, transition: { type: 'spring', stiffness: 20, restDelta: 2, }, }), closed: { clipPath: 'circle(0px at 100% 0)', transition: { type: 'spring', stiffness: 400, damping: 40, }, }, }; const HeaderMobile = () => { const pathname = usePathname(); const containerRef = useRef(null); const { height } = useDimensions(containerRef); const [isOpen, toggleOpen] = useCycle(false, true); return ( {NAV_ITEMS.map((item, idx) => { const isLastItem = idx === NAV_ITEMS.length - 1; // Check if it's the last item return (
{item.submenu ? ( ) : ( toggleOpen()} className={`flex w-full text-2xl ${ item.path === pathname ? 'font-bold' : '' }`} > {item.title} )} {!isLastItem && ( )}
); })}
); }; export default HeaderMobile; const MenuToggle = ({ toggle }: { toggle: any }) => ( ); const Path = (props: any) => ( ); const MenuItem = ({ className, children, }: { className?: string; children?: ReactNode; }) => { return ( {children} ); }; const MenuItemWithSubMenu: React.FC = ({ item, toggleOpen, }) => { const pathname = usePathname(); const [subMenuOpen, setSubMenuOpen] = useState(false); return ( <>
{subMenuOpen && ( <> {item.subMenuItems?.map((subItem, subIdx) => { return ( toggleOpen()} className={` ${ subItem.path === pathname ? 'font-bold' : '' }`} > {subItem.title} ); })} )}
); }; const MenuItemVariants = { open: { y: 0, opacity: 1, transition: { y: { stiffness: 1000, velocity: -100 }, }, }, closed: { y: 50, opacity: 0, transition: { y: { stiffness: 1000 }, duration: 0.02, }, }, }; const variants = { open: { transition: { staggerChildren: 0.02, delayChildren: 0.15 }, }, closed: { transition: { staggerChildren: 0.01, staggerDirection: -1 }, }, }; const useDimensions = (ref: any) => { const dimensions = useRef({ width: 0, height: 0 }); useEffect(() => { if (ref.current) { dimensions.current.width = ref.current.offsetWidth; dimensions.current.height = ref.current.offsetHeight; } // eslint-disable-next-line react-hooks/exhaustive-deps }, [ref]); return dimensions.current; };