diff --git a/src/components/Header/Header.jsx b/src/components/Header/Header.jsx index c320cd1..5aa76f8 100644 --- a/src/components/Header/Header.jsx +++ b/src/components/Header/Header.jsx @@ -25,6 +25,18 @@ function Header({notice }) { .catch((error) => console.error("Error fetching GitHub stars:", error)); }, []); + // Handle window resize to close mobile menu when switching to desktop + useEffect(() => { + const handleResize = () => { + if (window.innerWidth >= 768 && open) { // 768px is md breakpoint + setOpen(false); + } + }; + + window.addEventListener('resize', handleResize); + return () => window.removeEventListener('resize', handleResize); + }, [open]); + const navLink = [ { name: "Home", @@ -46,17 +58,39 @@ function Header({notice }) { link: "/resources", icon: , }, - { - name: "Github", - link: "https://github.com/devvsakib/github-error-solve", - icon: , - isExternalURL: true, - }, ]; + const githubLink = { + name: "Github", + link: "https://github.com/devvsakib/github-error-solve", + icon: , + isExternalURL: true, + }; + + // Dynamic styles for cleaner code + const mobileMenuClasses = ` + md:flex md:items-center md:gap-6 md:static md:opacity-100 md:visible md:bg-transparent md:flex-row md:justify-end md:h-auto md:w-auto + ${open ? + 'fixed inset-0 w-full h-screen flex flex-col items-center justify-center gap-8 z-40 backdrop-blur-md opacity-100 visible' : + 'fixed inset-0 w-full h-screen flex flex-col items-center justify-center gap-8 z-40 opacity-0 invisible pointer-events-none' + } + transition-opacity duration-500 ease-in-out + md:pointer-events-auto md:relative md:inset-auto + `; + + const mobileMenuStyle = { + backgroundColor: open ? (theme === "dark" ? "rgba(2, 0, 14, 0.95)" : "rgba(209, 203, 244, 0.95)") : "transparent", + backgroundImage: open ? (theme === "dark" + ? "radial-gradient(rgba(133, 138, 227, 0.1) 2px, transparent 0)" + : "radial-gradient(rgba(25, 25, 31, 0.1) 2px, transparent 0)" + ) : "none", + backgroundSize: "30px 30px", + backgroundPosition: "-5px -5px" + }; + return ( -
-
+
+
{/* Logo */} - {/* Menu icon */} -
setOpen((val) => !val)} - className="cursor-pointer md:hidden" - > - {open ? : } + {/* GitHub, theme toggle and menu icon for mobile */} +
+ +
+ + {githubLink.icon} + + { + countStar && ( +
+ {countStar} +
+ ) + } +
+
+
+ + +
+
setOpen((val) => !val)} + className="cursor-pointer relative z-50 p-2" + > + {open ? : } +
{/* Nav link items */} -
- {navLink.map((link, index) => { - return ( -
- {link?.isExternalURL ? ( - -
- - {link.icon} - - { - countStar && ( -
- {countStar} -
- ) - } -
-
- ) : ( - - {/* {link.icon} */} - {link.name} - +
+ {navLink.map((link, index) => ( +
+ setOpen(false)} + > + {link.name} +
+ +
+ ))} + + {/* GitHub link for desktop */} +
+ +
+ {githubLink.icon} + {countStar && ( +
{countStar}
)}
- ); - })} -
+ +
+ + {/* Theme toggle for desktop */} +
diff --git a/src/components/Layout/Layout.jsx b/src/components/Layout/Layout.jsx index 6694e67..00a6cc6 100644 --- a/src/components/Layout/Layout.jsx +++ b/src/components/Layout/Layout.jsx @@ -15,7 +15,7 @@ const Layout = ({ stars, children }) => {
-
+
{children}