File size: 5,954 Bytes
8b105ad c049d8c 8b105ad c049d8c 8b105ad c049d8c 8b105ad c049d8c 8b105ad c049d8c 8b105ad c049d8c 8b105ad c049d8c 8b105ad c049d8c 8b105ad c049d8c 8b105ad c049d8c 8b105ad c049d8c 8b105ad c049d8c 8b105ad c049d8c 8b105ad c049d8c 8b105ad |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
import React, { useState, useEffect, useRef } from "react";
import { Link, useLocation } from "react-router-dom";
import { Logo } from "../utils";
import styled from "styled-components";
// Styled Components
const HeaderContainer = styled.header`
z-index: 500;
background: rgba(0, 0, 0, 0.8);
font-family: "SF Pro", sans-serif;
font-weight: 800;
font-size: 15px;
position: sticky;
top: 0;
width: 100%;
margin: 0;
padding: 0;
`;
const NavWrapper = styled.div`
display: flex;
justify-content: center;
align-items: center;
padding: 0.5rem 1rem;
width: 100%;
margin: 0;
@media (max-width: 768px) {
justify-content: space-between;
}
`;
const SLogo = styled(Link)`
display: flex;
align-items: center;
font-weight: bold;
color: white;
text-decoration: none;
img {
height: 50px;
margin-right: 0.5rem;
}
`;
const DesktopMenu = styled.nav`
display: none;
@media (min-width: 768px) {
display: flex;
gap: 1rem;
position: relative;
}
`;
const MenuLink = styled(Link)`
color: ${(props) => (props.$active ? "transparent" : "white")};
padding: 0.5rem 2rem;
text-decoration: none;
position: relative;
cursor: pointer;
@media (min-width: 992px) {
padding: 0.5rem 4rem;
}
&:hover,
&:active {
color: #3267B9;
background-clip: text;
-webkit-background-clip: text;
}
${(props) =>
props.$active &&
`
color: #3267B9;
background-clip: text;
-webkit-background-clip: text;
`}
`;
// Dropdown Menu
const DropdownMenu = styled.div`
position: absolute;
background: rgba(0, 0, 0, 0.9);
border-radius: 5px;
top: 100%;
left: 0;
min-width: 150px;
display: ${(props) => (props.$isOpen ? "block" : "none")};
z-index: 1000;
a {
display: block;
padding: 0.5rem;
color: white;
text-decoration: none;
&:hover {
background: #333;
}
}
`;
const ContactWrapper = styled.div`
position: relative;
cursor: pointer;
`;
// Mobile Menu
const MobileMenuButton = styled.button`
display: block;
background: none;
border: none;
color: white;
font-size: 2.5rem;
cursor: pointer;
transition: transform 0.2s ease;
&:hover {
color: #0ea8b6;
}
&:active {
transform: scale(0.9);
}
@media (min-width: 768px) {
display: none;
}
`;
const MobileMenu = styled.nav`
background: rgba(0, 0, 0, 0.9);
position: absolute;
top: 100%;
left: 0;
width: 100%;
max-height: ${(props) => (props.$isOpen ? "400px" : "0")};
overflow: hidden;
opacity: ${(props) => (props.$isOpen ? 1 : 0)};
transform: ${(props) => (props.$isOpen ? "translateY(0)" : "translateY(-10px)")};
transition: max-height 0.3s ease, opacity 0.3s ease, transform 0.3s ease;
a {
display: block;
padding: 0.5rem 1rem;
color: white;
text-decoration: none;
&:hover {
background: #333;
}
}
`;
const Header = () => {
const [isMenuOpen, setIsMenuOpen] = useState(false);
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
const location = useLocation();
const menuRef = useRef(null);
const buttonRef = useRef(null);
const dropdownRef = useRef(null);
const toggleMenu = () => setIsMenuOpen(prev => !prev);
const toggleDropdown = () => setIsDropdownOpen(prev => !prev);
// Close menu if clicking outside
useEffect(() => {
const handleClickOutside = (event) => {
if (
menuRef.current &&
!menuRef.current.contains(event.target) &&
buttonRef.current &&
!buttonRef.current.contains(event.target)
) {
setIsMenuOpen(false);
}
if (
dropdownRef.current &&
!dropdownRef.current.contains(event.target)
) {
setIsDropdownOpen(false);
}
};
document.addEventListener("mousedown", handleClickOutside);
return () => {
document.removeEventListener("mousedown", handleClickOutside);
};
}, []);
// Close menu and dropdown on navigation
useEffect(() => {
setIsMenuOpen(false);
setIsDropdownOpen(false);
}, [location.pathname]);
return (
<HeaderContainer>
<NavWrapper>
<SLogo to="/">
<img src={Logo} alt="Logo" />
</SLogo>
<DesktopMenu>
{["/vardig", "/about", "/blogs", "/jobs"].map((path, i) => (
<MenuLink key={i} to={path} $active={location.pathname === path}>
{path === "/vardig"
? "VarDiG"
: path.replace("/", "").charAt(0).toUpperCase() +
path.replace("/", "").slice(1)}
</MenuLink>
))}
{/* Contact with Dropdown */}
<ContactWrapper ref={dropdownRef}>
<MenuLink as="div" onClick={toggleDropdown}>
Contact ▾
</MenuLink>
<DropdownMenu $isOpen={isDropdownOpen}>
<Link to="/contact">Contact</Link>
<Link to="/privacy-policy">Privacy Policy</Link>
</DropdownMenu>
</ContactWrapper>
</DesktopMenu>
<MobileMenuButton
onClick={toggleMenu}
aria-expanded={isMenuOpen}
ref={buttonRef}
>
☰
</MobileMenuButton>
</NavWrapper>
<MobileMenu $isOpen={isMenuOpen} ref={menuRef}>
{["/", "/vardig", "/about", "/blogs", "/jobs"].map((path, i) => (
<Link key={i} to={path} onClick={() => setIsMenuOpen(false)}>
{path === "/" ? "Home" : path.replace("/", "").charAt(0).toUpperCase() + path.slice(2)}
</Link>
))}
{/* Mobile Contact Dropdown */}
<div>
<Link to="/contact" onClick={() => setIsMenuOpen(false)}>Contact</Link>
<Link to="/privacy-policy" onClick={() => setIsMenuOpen(false)} style={{ paddingLeft: "20px" }}>
Privacy Policy
</Link>
</div>
</MobileMenu>
</HeaderContainer>
);
};
export default Header; |