-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathMainHeader.jsx
More file actions
322 lines (300 loc) · 10.6 KB
/
MainHeader.jsx
File metadata and controls
322 lines (300 loc) · 10.6 KB
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
import React, { useState, useRef } from 'react';
import { Link } from 'react-router-dom';
import {
Menu,
X,
ChevronDown,
Search,
Heart,
User,
ShoppingCart,
} from 'lucide-react';
import SearchBox from '../Search/SearchBox';
import TopHeader from "../TopHeader/TopHeader";
import ShopMenu from '../ShopMenu';
export default function Header() {
const [mobileOpen, setMobileOpen] = useState(false);
const [shopOpen, setShopOpen] = useState(false);
const [search, setSearch] = useState(false);
const mobileMenuRef = useRef(null);
// Handle shop button click
const handleShopClick = () => {
setShopOpen(!shopOpen);
};
// Handle shop button keyboard events
const handleShopButtonKeyDown = (event) => {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
handleShopClick();
}
};
return (
<>
<TopHeader />
{/* Main Header */}
<header className="bg-white shadow-md w-full fixed top-10 left-0 z-50">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex justify-between items-center h-16">
{/* Logo */}
<div className="flex-shrink-0">
<Link to="/">
<img
src="/images/official-logo-core-x.svg"
alt="CoreX Logo"
className="h-8 w-auto"
/>
</Link>
</div>
{/* Center: Desktop Navigation */}
<nav className="hidden md:flex space-x-8 items-center">
<div className="relative">
<ShopMenu
shopOpen={shopOpen}
setShopOpen={setShopOpen}
onShopClick={handleShopClick}
onShopKeyDown={handleShopButtonKeyDown}
/>
</div>
<Link to="/garage-sale" className="text-gray-700 hover:text-black font-medium">
GARAGE SALE
</Link>
<Link to="/products" className="text-gray-700 hover:text-black font-medium">
ALL PRODUCTS
</Link>
<Link to="/about-corex" className="text-gray-700 hover:text-black font-medium">
ABOUT COREX
</Link>
</nav>
{/* Right: Icons (desktop) + Mobile Hamburger */}
<div className="flex items-center space-x-6">
{/* Desktop Icons */}
<div className="hidden md:flex items-center space-x-6 text-gray-700">
<button
aria-label="Search"
onClick={() => setSearch(true)}
className="transform transition-transform duration-200 hover:scale-110 hover:text-black cursor-pointer"
>
<Search className="h-5 w-5" />
</button>
<a
href="#"
aria-label="Wishlist"
className="transform transition-transform duration-200 hover:scale-110 hover:text-black"
>
<Heart className="h-5 w-5" />
</a>
<Link
to="/login"
aria-label="User Account"
className="transform transition-transform duration-200 hover:scale-110 hover:text-black"
>
<User className="h-5 w-5" />
</Link>
<a
href="#"
aria-label="Shopping Cart"
className="transform transition-transform duration-200 hover:scale-110 hover:text-black"
>
<ShoppingCart className="h-5 w-5" />
</a>
</div>
{/* Mobile Icons */}
<div className="md:hidden flex items-center space-x-4">
<button
onClick={() => setSearch(true)}
className="text-gray-700 hover:text-black"
aria-label="Search"
>
<Search className="h-5 w-5" />
</button>
<button
onClick={() => setMobileOpen(!mobileOpen)}
className="text-gray-700 hover:text-black"
aria-label={mobileOpen ? "Close menu" : "Open menu"}
>
{mobileOpen ? (
<X className="h-6 w-6" />
) : (
<Menu className="h-6 w-6" />
)}
</button>
</div>
</div>
</div>
</div>
{/* Mobile Menu */}
{mobileOpen && (
<div className="md:hidden bg-white shadow-md animate-fadeIn">
<nav className="flex flex-col space-y-2 p-4">
<button
onClick={() => setShopOpen(!shopOpen)}
className="flex items-center justify-between text-gray-700 hover:text-black transition"
>
<span>Shop</span>
<ChevronDown
className={`h-4 w-4 transition-transform duration-300 ${
shopOpen ? 'rotate-180' : 'rotate-0'
}`}
/>
</button>
{shopOpen && (
<div className="flex flex-col space-y-2 pl-4">
{['Category 1', 'Category 2', 'Category 3'].map((cat) => (
<a
key={cat}
href="#"
className="text-gray-600 hover:text-black transition"
>
{cat}
</a>
))}
</div>
)}
<Link
to="/garage-sale"
className="text-gray-700 hover:text-black transition"
>
Garage Sale
</Link>
<Link
to="/products"
className="text-gray-700 hover:text-black transition"
>
All Products
</Link>
<Link
to="/about-corex"
className="text-gray-700 hover:text-black transition"
>
About CoreX
</Link>
</nav>
</div>
)}
</header>
{/* Overlay for Mobile Menu */}
<div
className={`fixed inset-0 bg-black/30 backdrop-blur-sm transition-opacity duration-300 ${
mobileOpen ? "opacity-100 pointer-events-auto" : "opacity-0 pointer-events-none"
} z-[998]`}
/>
{/* Mobile Menu Drawer */}
<div
ref={mobileMenuRef}
className={`fixed top-0 right-0 w-full sm:w-[280px] h-full bg-white shadow-2xl border-l border-gray-200 z-[999] transform transition-all duration-300 ease-in-out ${
mobileOpen ? "translate-x-0 scale-100" : "translate-x-full scale-95"
} flex flex-col`}
>
{/* Mobile Menu Header */}
<div className="flex justify-between items-center px-6 py-4 border-b border-gray-200">
<h2 className="font-bold text-lg text-[#023E8A] tracking-wide">MENU</h2>
<button
onClick={() => setMobileOpen(false)}
className="p-2 rounded-full hover:bg-gray-100 transition-colors duration-200 cursor-pointer"
aria-label="Close menu"
>
<X className="w-5 h-5 text-gray-600" />
</button>
</div>
{/* Mobile Menu Items */}
<nav className="flex-1 px-6 py-4 flex flex-col space-y-4">
<div>
<button
onClick={() => setShopOpen(!shopOpen)}
className="flex items-center justify-between w-full text-gray-700 hover:text-black font-medium"
>
Shop
<ChevronDown
className={`h-4 w-4 transition-transform duration-200 ${
shopOpen ? "rotate-180" : ""
}`}
/>
</button>
{shopOpen && (
<div className="mt-2 pl-4 space-y-2">
<Link
to="/category1"
className="block text-gray-600 hover:text-black"
onClick={() => setMobileOpen(false)}
>
Category 1
</Link>
<Link
to="/category2"
className="block text-gray-600 hover:text-black"
onClick={() => setMobileOpen(false)}
>
Category 2
</Link>
<Link
to="/category3"
className="block text-gray-600 hover:text-black"
onClick={() => setMobileOpen(false)}
>
Category 3
</Link>
</div>
)}
</div>
<Link
to="/garage-sale"
className="text-gray-700 hover:text-black font-medium"
onClick={() => setMobileOpen(false)}
>
Garage Sale
</Link>
<Link
to="/products"
className="text-gray-700 hover:text-black font-medium"
onClick={() => setMobileOpen(false)}
>
All Products
</Link>
<Link
to="/about-corex"
className="text-gray-700 hover:text-black font-medium"
onClick={() => setMobileOpen(false)}
>
About CoreX
</Link>
</nav>
{/* Mobile Menu Icons */}
<div className="px-6 py-4 border-t border-gray-200">
<div className="flex flex-col space-y-4">
<a
href="#"
className="flex items-center space-x-2 text-gray-700 hover:text-black"
onClick={() => setMobileOpen(false)}
>
<Heart className="h-5 w-5" />
<span>Wishlist</span>
</a>
<a
href="#"
className="flex items-center space-x-2 text-gray-700 hover:text-black"
onClick={() => setMobileOpen(false)}
>
<User className="h-5 w-5" />
<span>Account</span>
</a>
<a
href="#"
className="flex items-center space-x-2 text-gray-700 hover:text-black"
onClick={() => setMobileOpen(false)}
>
<ShoppingCart className="h-5 w-5" />
<span>Cart</span>
</a>
</div>
</div>
</div>
{/* Search Drawer */}
{search && (
<SearchBox
isOpen={search}
onClose={() => setSearch(false)}
/>
)}
</>
);
}