diff --git a/src/components/primary-menu.jsx b/src/components/primary-menu.jsx index cf6efad..66233a2 100644 --- a/src/components/primary-menu.jsx +++ b/src/components/primary-menu.jsx @@ -1,20 +1,15 @@ -import { Menu, MenuButton, MenuItem, MenuItems } from "@headlessui/react"; +import { Menu } from "@headlessui/react"; import { Bars3Icon, XMarkIcon } from "@heroicons/react/24/outline"; -import { useState, useCallback } from "react"; +import { createPortal } from "react-dom"; import CustomLink from "./link"; -export default function PrimaryMenu() { - const [isMenuOpen, setIsMenuOpen] = useState(false); - - // Use useCallback to memoize the toggle handler - const handleMenuToggle = useCallback(() => { - setIsMenuOpen((previous) => !previous); - }, []); - - const handleMenuItemClick = useCallback(() => { - setIsMenuOpen(false); - }, []); +// A helper that portals children to the body (or a different root). +function MenuPortal({ children }) { + if (typeof globalThis === "undefined") return; + return createPortal(children, document.body); +} +export default function PrimaryMenu() { const navItemClass = "text-gray-200 hover:text-white transition-colors duration-200"; @@ -47,59 +42,78 @@ export default function PrimaryMenu() { - - - - {isMenuOpen ? "Close menu" : "Open menu"} - - {isMenuOpen ? ( - - ) : ( - - )} - - - {isMenuOpen && ( - - - - Docs - - - - - Blog - - - - + + {({ open }) => ( + <> + - Showcase - - - - )} - + {open ? ( + + ) : ( + + )} + + + {open && ( + + +
+ + {({ active }) => ( + + Docs + + )} + + + {({ active }) => ( + + Blog + + )} + + + {({ active }) => ( + + Showcase + + )} + +
+
+
+ )} + + )} +
+ ); }