diff --git a/app/components/navbar.tsx b/app/components/navbar.tsx index b731d7e..19d830d 100644 --- a/app/components/navbar.tsx +++ b/app/components/navbar.tsx @@ -2,26 +2,49 @@ import React, { ReactNode } from 'react'; import Link from 'next/link'; +import { MdArrowDropDown, MdArrowDropUp, MdMenu, MdClose } from 'react-icons/md'; const NavbarItem = ({ href, label, children }: { href: string, label: string, children?: ReactNode }) => { - const [dropdownHidden, setDropdownHidden] = React.useState(true); - const [dropdownOnHover, setDropdownOnHover] = React.useState(false); + const isHovered = React.useRef(false); + const [dropdownHidden, setDropdownHidden] = React.useState(true); // state for desktop layout (using hover) + const [mobileDropdownHidden, setMobileDropdownHidden] = React.useState(true); // state for mobile layout (using click) return (
setTimeout(() => setDropdownHidden(false), 300) : undefined} - onMouseLeave={children ? () => setTimeout(() => setDropdownHidden(true), 300) : undefined} + className="relative flex flex-col" + onMouseEnter={children ? () => { + isHovered.current = true; + setTimeout(() => {setDropdownHidden(!isHovered.current)}, 250); + } : undefined} + onMouseLeave={children ? () => { + isHovered.current = false + setTimeout(() => {setDropdownHidden(!isHovered.current)}, 250); + } : undefined} > - - {label} - +
+ + + {label} + + + {children && ( +
{setMobileDropdownHidden(!mobileDropdownHidden)}} + > + {mobileDropdownHidden ? : } +
+ )} +
+ {children && ( -
setDropdownOnHover(true)} - onMouseLeave={() => setDropdownOnHover(false)} - > +
{children}
)} @@ -32,7 +55,11 @@ const NavbarItem = ({ href, label, children }: { href: string, label: string, ch const NavbarDropdownItem = ({ href, children }: { href: string, children: ReactNode }) => { return ( -
+
{children}
@@ -40,27 +67,41 @@ const NavbarDropdownItem = ({ href, children }: { href: string, children: ReactN } const Navbar = () => { - const [aboutUsHidden, setAboutUsHidden] = React.useState(true); - const [aboutUsOnHover, setAboutUsOnHover] = React.useState(false); + const [mobileMenuHidden, setMobileMenuHidden] = React.useState(true); return ( -