|
| 1 | +import React, { useState, useEffect } from "react"; |
| 2 | +import { Link, useLocation } from "react-router-dom"; |
| 3 | + |
| 4 | +const Header: React.FC = () => { |
| 5 | + const [isMobile, setIsMobile] = useState<boolean>(false); |
| 6 | + const [sidebarOpen, setSidebarOpen] = useState<boolean>(false); |
| 7 | + const [sidebarClosing, setSidebarClosing] = useState<boolean>(false); |
| 8 | + const location = useLocation(); |
| 9 | + |
| 10 | + const linkToMainWebsite = |
| 11 | + "https://foss-cell-gecpkd.github.io/FOSS_GECPKD_Website/"; |
| 12 | + |
| 13 | + useEffect(() => { |
| 14 | + const checkIfMobile = (): void => { |
| 15 | + setIsMobile(window.innerWidth < 768); |
| 16 | + }; |
| 17 | + |
| 18 | + // Initial check |
| 19 | + checkIfMobile(); |
| 20 | + |
| 21 | + // Add event listener for window resize |
| 22 | + window.addEventListener("resize", checkIfMobile); |
| 23 | + |
| 24 | + // Clean up |
| 25 | + return () => { |
| 26 | + window.removeEventListener("resize", checkIfMobile); |
| 27 | + }; |
| 28 | + }, []); |
| 29 | + |
| 30 | + // Handle sidebar toggling with animation |
| 31 | + const toggleSidebar = (): void => { |
| 32 | + if (sidebarOpen) { |
| 33 | + setSidebarClosing(true); |
| 34 | + |
| 35 | + setTimeout(() => { |
| 36 | + setSidebarOpen(false); |
| 37 | + setSidebarClosing(false); |
| 38 | + }, 300); // This should match your animation duration |
| 39 | + } else { |
| 40 | + setSidebarOpen(true); |
| 41 | + } |
| 42 | + }; |
| 43 | + return ( |
| 44 | + <> |
| 45 | + {/* Mobile Header */} |
| 46 | + {isMobile && ( |
| 47 | + <div className="flex justify-between items-center p-2.5"> |
| 48 | + <div |
| 49 | + className="flex items-center ml-2.5" |
| 50 | + onClick={() => window.open(linkToMainWebsite, "_blank")} |
| 51 | + > |
| 52 | + <img |
| 53 | + src="/Breakpoint/foss-icon-black.svg" |
| 54 | + alt="FOSS Club Logo" |
| 55 | + className="h-10 mr-2.5" |
| 56 | + /> |
| 57 | + <div className="flex flex-col justify-center"> |
| 58 | + <h1 className="m-0 text-base font-bold">FOSS Club</h1> |
| 59 | + <p className="m-0 text-xs opacity-80">GEC, Palakkad</p> |
| 60 | + </div> |
| 61 | + </div> |
| 62 | + <button |
| 63 | + onClick={toggleSidebar} |
| 64 | + className="border-none bg-transparent cursor-pointer mt-2.5" |
| 65 | + style={{ WebkitTapHighlightColor: "transparent" }} |
| 66 | + > |
| 67 | + <svg |
| 68 | + xmlns="http://www.w3.org/2000/svg" |
| 69 | + width="28" |
| 70 | + height="21" |
| 71 | + viewBox="0 0 28 21" |
| 72 | + fill="none" |
| 73 | + > |
| 74 | + <path |
| 75 | + d="M0.263184 2.23792H27.3803M0.263184 10.4699H27.3803M0.263184 18.2177H27.3803" |
| 76 | + stroke="#787878" |
| 77 | + strokeWidth="3.87388" |
| 78 | + /> |
| 79 | + </svg> |
| 80 | + </button> |
| 81 | + </div> |
| 82 | + )} |
| 83 | + |
| 84 | + {/* Desktop Header */} |
| 85 | + {!isMobile && ( |
| 86 | + <nav |
| 87 | + className="flex justify-between items-center px-16 pt-16 w-full max-w-full mx-auto relative z-10" |
| 88 | + onClick={() => window.open(linkToMainWebsite, "_blank")} |
| 89 | + > |
| 90 | + <div className="flex items-center"> |
| 91 | + <img |
| 92 | + src="/Breakpoint/foss-icon-black.svg" |
| 93 | + alt="FOSS Club Logo" |
| 94 | + className="w-12 h-12 mr-2.5" |
| 95 | + /> |
| 96 | + <div> |
| 97 | + <h1 className="m-0 text-lg font-bold">FOSS Club</h1> |
| 98 | + <p className="m-0 text-sm opacity-80">GEC, Palakkad</p> |
| 99 | + </div> |
| 100 | + </div> |
| 101 | + <div className="flex gap-8 font-['Poppins']"> |
| 102 | + <a |
| 103 | + href={linkToMainWebsite} |
| 104 | + className="text-black no-underline text-base opacity-80 transition-all hover:opacity-100 hover:text-[#0c81f6] font-['Poppins']" |
| 105 | + > |
| 106 | + Home |
| 107 | + </a> |
| 108 | + <Link |
| 109 | + to="/" |
| 110 | + className={`text-black no-underline text-base opacity-80 transition-all hover:opacity-100 hover:text-[#0c81f6] font-['Poppins'] ${ |
| 111 | + location.pathname === "/" |
| 112 | + ? ' opacity-100 relative after:content-[""] after:absolute after:bottom-[-5px] after:left-0 after:w-full after:rounded-3xl after:h-[3px] after:bg-[#0c81f6]' |
| 113 | + : "" |
| 114 | + }`} |
| 115 | + > |
| 116 | + Breakpoint |
| 117 | + </Link> |
| 118 | + {/* Commented out links */} |
| 119 | + {/* |
| 120 | + <Link to="/about" className={`nav-link ${location.pathname === '/about' ? 'active' : ''}`}>About</Link> |
| 121 | + <Link to="/team" className={`nav-link ${location.pathname === '/team' ? 'active' : ''}`}>Team</Link> |
| 122 | + <Link to="/gallery" className={`nav-link ${location.pathname === '/gallery' ? 'active' : ''}`}>Gallery</Link> |
| 123 | + */} |
| 124 | + </div> |
| 125 | + </nav> |
| 126 | + )} |
| 127 | + |
| 128 | + {/* Mobile Sidebar */} |
| 129 | + {sidebarOpen && ( |
| 130 | + <div |
| 131 | + className={`fixed top-0 right-0 w-64 h-full bg-opacity-60 bg-white backdrop-blur-md flex flex-col p-5 z-50 ${ |
| 132 | + sidebarClosing ? "animate-slideOutRight" : "animate-slideInRight" |
| 133 | + }`} |
| 134 | + style={{ |
| 135 | + borderLeft: "1px solid rgba(255, 255, 255, 0.1)", |
| 136 | + boxShadow: "-5px 0 15px rgba(0, 0, 0, 0.1)", |
| 137 | + WebkitBackdropFilter: "blur(10px)", |
| 138 | + }} |
| 139 | + > |
| 140 | + <button |
| 141 | + onClick={toggleSidebar} |
| 142 | + className="bg-transparent border-0 text-black text-xl cursor-pointer self-end mb-5 opacity-80 transition-opacity hover:opacity-100" |
| 143 | + style={{ WebkitTapHighlightColor: "transparent" }} |
| 144 | + > |
| 145 | + ✖ |
| 146 | + </button> |
| 147 | + <a |
| 148 | + href={linkToMainWebsite} |
| 149 | + className="py-3 px-4 text-black no-underline block text-lg mb-1 rounded-lg transition-all hover:bg-[rgba(12,129,246,0.8)] hover:text-black hover:translate-x-[-5px]" |
| 150 | + > |
| 151 | + Home |
| 152 | + </a> |
| 153 | + <Link |
| 154 | + to="/" |
| 155 | + className="py-3 px-4 text-black no-underline block text-lg mb-1 rounded-lg transition-all hover:bg-[rgba(12,129,246,0.8)] hover:text-black hover:translate-x-[-5px]" |
| 156 | + onClick={toggleSidebar} |
| 157 | + > |
| 158 | + Breakpoint |
| 159 | + </Link> |
| 160 | + {/* Commented out links */} |
| 161 | + {/* |
| 162 | + <Link to="/about" className="nav-link" onClick={toggleSidebar}>About</Link> |
| 163 | + <Link to="/team" className="nav-link" onClick={toggleSidebar}>Team</Link> |
| 164 | + <Link to="/gallery" className="nav-link" onClick={toggleSidebar}>Gallery</Link> |
| 165 | + */} |
| 166 | + </div> |
| 167 | + )} |
| 168 | + </> |
| 169 | + ); |
| 170 | +}; |
| 171 | + |
| 172 | +export default Header; |
0 commit comments