Skip to content

Commit 364b473

Browse files
authored
Merge pull request #131 from Sushil010/feature/shop-menu-expand
feat: expand shop menu for improved UX
2 parents 68f440f + 709e062 commit 364b473

3 files changed

Lines changed: 418 additions & 81 deletions

File tree

src/components/Header/MainHeader.jsx

Lines changed: 31 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React, { useState, useEffect, useRef } from "react";
2-
import { Link } from "react-router-dom";
1+
import React, { useState, useRef } from 'react';
2+
import { Link } from 'react-router-dom';
33
import {
44
Menu,
55
X,
@@ -8,41 +8,29 @@ import {
88
Heart,
99
User,
1010
ShoppingCart,
11-
} from "lucide-react";
12-
import SearchBox from "../Search/SearchBox";
11+
} from 'lucide-react';
12+
import SearchBox from '../Search/SearchBox';
1313
import TopHeader from "../TopHeader/TopHeader";
14+
import ShopMenu from '../ShopMenu';
1415

1516
export default function Header() {
1617
const [mobileOpen, setMobileOpen] = useState(false);
1718
const [shopOpen, setShopOpen] = useState(false);
1819
const [search, setSearch] = useState(false);
1920
const mobileMenuRef = useRef(null);
2021

21-
// Close mobile menu on outside click
22-
useEffect(() => {
23-
const handleClickOutside = (e) => {
24-
if (mobileMenuRef.current && !mobileMenuRef.current.contains(e.target)) {
25-
setMobileOpen(false);
26-
}
27-
};
28-
document.addEventListener("mousedown", handleClickOutside);
29-
return () => {
30-
document.removeEventListener("mousedown", handleClickOutside);
31-
};
32-
}, []);
22+
// Handle shop button click
23+
const handleShopClick = () => {
24+
setShopOpen(!shopOpen);
25+
};
3326

34-
// Close mobile menu on Escape key
35-
useEffect(() => {
36-
const handleEscape = (e) => {
37-
if (e.key === "Escape") {
38-
setMobileOpen(false);
39-
}
40-
};
41-
document.addEventListener("keydown", handleEscape);
42-
return () => {
43-
document.removeEventListener("keydown", handleEscape);
44-
};
45-
}, []);
27+
// Handle shop button keyboard events
28+
const handleShopButtonKeyDown = (event) => {
29+
if (event.key === 'Enter' || event.key === ' ') {
30+
event.preventDefault();
31+
handleShopClick();
32+
}
33+
};
4634

4735
return (
4836
<>
@@ -63,63 +51,25 @@ export default function Header() {
6351
</Link>
6452
</div>
6553

66-
{/* Desktop Navigation */}
67-
<nav className="hidden md:flex space-x-8">
68-
{/* Shop Dropdown */}
54+
{/* Center: Desktop Navigation */}
55+
<nav className="hidden md:flex space-x-8 items-center">
6956
<div className="relative">
70-
<button
71-
onClick={() => setShopOpen(!shopOpen)}
72-
className="group flex items-center gap-1 text-gray-700 hover:text-black transition"
73-
>
74-
<span className="relative after:absolute after:left-0 after:-bottom-1 after:h-[2px] after:w-0 after:bg-black after:transition-all group-hover:after:w-full">
75-
Shop
76-
</span>
77-
<ChevronDown
78-
className={`h-4 w-4 transition-transform duration-300 ${
79-
shopOpen ? 'rotate-180' : 'rotate-0'
80-
}`}
81-
/>
82-
</button>
83-
84-
{shopOpen && (
85-
<div className="absolute left-0 top-full mt-2 w-screen max-w-4xl bg-white shadow-lg p-6 animate-fadeIn">
86-
<div className="grid grid-cols-3 gap-4">
87-
<div className="p-4 bg-gray-100 rounded hover:bg-gray-200 transition">
88-
Category 1
89-
</div>
90-
<div className="p-4 bg-gray-100 rounded hover:bg-gray-200 transition">
91-
Category 2
92-
</div>
93-
<div className="p-4 bg-gray-100 rounded hover:bg-gray-200 transition">
94-
Category 3
95-
</div>
96-
</div>
97-
</div>
98-
)}
57+
<ShopMenu
58+
shopOpen={shopOpen}
59+
setShopOpen={setShopOpen}
60+
onShopClick={handleShopClick}
61+
onShopKeyDown={handleShopButtonKeyDown}
62+
/>
9963
</div>
100-
101-
<Link
102-
to="/garage-sale"
103-
className="relative text-gray-700 hover:text-black transition group"
104-
>
105-
Garage Sale
106-
<span className="absolute left-0 -bottom-1 w-0 h-[2px] bg-black transition-all duration-300 group-hover:w-full"></span>
107-
</Link>
10864

109-
<Link
110-
to="/products"
111-
className="relative text-gray-700 hover:text-black transition group"
112-
>
113-
All Products
114-
<span className="absolute left-0 -bottom-1 w-0 h-[2px] bg-black transition-all duration-300 group-hover:w-full"></span>
65+
<Link to="/garage-sale" className="text-gray-700 hover:text-black font-medium">
66+
GARAGE SALE
11567
</Link>
116-
117-
<Link
118-
to="/about-corex"
119-
className="relative text-gray-700 hover:text-black transition group"
120-
>
121-
About CoreX
122-
<span className="absolute left-0 -bottom-1 w-0 h-[2px] bg-black transition-all duration-300 group-hover:w-full"></span>
68+
<Link to="/products" className="text-gray-700 hover:text-black font-medium">
69+
ALL PRODUCTS
70+
</Link>
71+
<Link to="/about-corex" className="text-gray-700 hover:text-black font-medium">
72+
ABOUT COREX
12373
</Link>
12474
</nav>
12575

0 commit comments

Comments
 (0)