|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import Image from "next/image"; |
| 4 | +import Link from "next/link"; |
| 5 | +import { usePathname } from "next/navigation"; |
| 6 | +import { useEffect, useState } from "react"; |
| 7 | + |
| 8 | +type MenuItem = { |
| 9 | + name: string; |
| 10 | + href: string; |
| 11 | + external?: boolean; |
| 12 | +}; |
| 13 | + |
| 14 | +const menuItems: MenuItem[] = [ |
| 15 | + { |
| 16 | + name: "Good First Issues", |
| 17 | + href: "https://github.com/issues?q=is%3Aopen%20is%3Aissue%20org%3Ahiero-ledger%20archived%3Afalse%20no%3Aassignee%20(label%3A%22good%20first%20issue%22%20OR%20label%3A%22skill%3A%20good%20first%20issue%22)%20(repo%3Ahiero-ledger%2Fhiero-sdk-cpp%20OR%20repo%3Ahiero-ledger%2Fhiero-sdk-swift%20OR%20repo%3Ahiero-ledger%2Fhiero-sdk-python%20OR%20repo%3Ahiero-ledger%2Fhiero-sdk-js%20OR%20repo%3Ahiero-ledger%2Fhiero-website)", |
| 18 | + external: true, |
| 19 | + }, |
| 20 | + { name: "Connect", href: "/#connect" }, |
| 21 | + { name: "Blog", href: "/blog" }, |
| 22 | + { |
| 23 | + name: "Calendar", |
| 24 | + href: "https://zoom-lfx.platform.linuxfoundation.org/meetings/hiero?view=week", |
| 25 | + external: true, |
| 26 | + }, |
| 27 | +]; |
| 28 | + |
| 29 | +export default function Menu() { |
| 30 | + const pathname = usePathname(); |
| 31 | + const [isOpen, setIsOpen] = useState(false); |
| 32 | + |
| 33 | + useEffect(() => { |
| 34 | + document.body.style.overflow = isOpen ? "hidden" : ""; |
| 35 | + return () => { |
| 36 | + document.body.style.overflow = ""; |
| 37 | + }; |
| 38 | + }, [isOpen]); |
| 39 | + |
| 40 | + const isActive = (href: string): boolean => { |
| 41 | + if (href.startsWith("http")) return false; |
| 42 | + if (href.startsWith("/#")) return pathname === "/"; |
| 43 | + if (href === "/blog") return pathname === "/blog" || pathname.startsWith("/blog/"); |
| 44 | + return pathname === href; |
| 45 | + }; |
| 46 | + |
| 47 | + return ( |
| 48 | + <> |
| 49 | + <button |
| 50 | + type="button" |
| 51 | + className="sm:hidden" |
| 52 | + onClick={() => setIsOpen(true)} |
| 53 | + aria-label="Open menu" |
| 54 | + aria-expanded={isOpen} |
| 55 | + > |
| 56 | + <Image src="/images/Hiero-Icon-Nav-Menu.svg" alt="Open menu" className="w-5 h-5" width={20} height={20} /> |
| 57 | + </button> |
| 58 | + |
| 59 | + <nav |
| 60 | + id="navigation" |
| 61 | + className={`${isOpen ? "active-navigation" : "hidden"} absolute items-center justify-center w-full h-screen bg-black top-0 left-0 text-white sm:relative sm:h-auto sm:top-auto sm:bg-transparent sm:left-auto sm:w-9/12 sm:max-w-xl sm:block`} |
| 62 | + aria-hidden={!isOpen && pathname !== undefined} |
| 63 | + > |
| 64 | + <div className="absolute top-[27px] sm:hidden"> |
| 65 | + <Image src="/images/Hiero-Icon-wLogo-white-text.svg" alt="Hiero logo" className="h-[40px] w-[128px]" width={128} height={40} /> |
| 66 | + </div> |
| 67 | + |
| 68 | + <button |
| 69 | + type="button" |
| 70 | + className="absolute text-white top-[35px] right-[25px] sm:hidden" |
| 71 | + onClick={() => setIsOpen(false)} |
| 72 | + aria-label="Close menu" |
| 73 | + > |
| 74 | + <Image src="/images/Hiero-Icon-ModalClose.svg" alt="Close menu" className="w-5 h-5" width={20} height={20} /> |
| 75 | + </button> |
| 76 | + |
| 77 | + <ul id="menu" className="flex flex-col sm:flex-row justify-between"> |
| 78 | + {menuItems.map((item) => ( |
| 79 | + <li |
| 80 | + key={item.name} |
| 81 | + className={`text-center sm:text-left ${item.name === "Connect" ? "sm:hidden" : ""}`.trim()} |
| 82 | + > |
| 83 | + {item.external ? ( |
| 84 | + <a |
| 85 | + href={item.href} |
| 86 | + target="_blank" |
| 87 | + rel="noopener noreferrer" |
| 88 | + onClick={() => setIsOpen(false)} |
| 89 | + > |
| 90 | + {item.name} |
| 91 | + </a> |
| 92 | + ) : ( |
| 93 | + <Link href={item.href} className={isActive(item.href) ? "active" : ""} onClick={() => setIsOpen(false)}> |
| 94 | + {item.name} |
| 95 | + </Link> |
| 96 | + )} |
| 97 | + </li> |
| 98 | + ))} |
| 99 | + |
| 100 | + <li className="self-center"> |
| 101 | + <a href="https://github.com/hiero-ledger/" target="_blank" rel="noopener noreferrer" className="flex"> |
| 102 | + <Image src="/images/Hiero-Icon-Github.svg" alt="GitHub" className="h-[35px] w-[35px] sm:h-[17px] sm:w-[17px]" width={35} height={35} /> |
| 103 | + </a> |
| 104 | + </li> |
| 105 | + </ul> |
| 106 | + </nav> |
| 107 | + </> |
| 108 | + ); |
| 109 | +} |
0 commit comments