Skip to content

Commit 536780a

Browse files
authored
Merge pull request #85 from krgaurav7/feature/search-box
Search Menu Features
2 parents 821e13f + 18d089f commit 536780a

File tree

3 files changed

+117
-1
lines changed

3 files changed

+117
-1
lines changed

src/components/Header/MainHeader.jsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ import {
99
User,
1010
ShoppingCart,
1111
} from 'lucide-react';
12+
import SearchBox from '../Search/SearchBox';
1213

1314
export default function Header() {
1415
const [mobileOpen, setMobileOpen] = useState(false);
1516
const [shopOpen, setShopOpen] = useState(false);
17+
const [search, setSearch] = useState(false);
18+
1619

1720
return (
1821
<header className="bg-white shadow-md w-full fixed top-8 left-0 z-50">
@@ -65,8 +68,31 @@ export default function Header() {
6568
<div className="flex items-center space-x-6">
6669
{/* Desktop Icons */}
6770
<div className="hidden md:flex items-center space-x-6 text-gray-700">
68-
<a href="#" aria-label="Search">
71+
{/* search box logic */}
72+
<a aria-label="Search"
73+
onClick={() => setSearch(!search)}
74+
className="cursor-pointer ">
6975
<Search className="h-5 w-5 hover:text-black" />
76+
{(search) &&
77+
<div className='fixed h-full w-1/2 top-0 right-0 z-5'>
78+
<div className='flex items-center w-full justify-between mt-2 h-15 px-2 bg-gray-100'>
79+
<div className='font-bold text-lg mr-4'>
80+
<p>SEARCH</p>
81+
</div>
82+
<div className='font-bold text-lg mr-4'>
83+
<button
84+
className='cursor-pointer'
85+
onClick={() =>{
86+
setSearch(!search);
87+
} }
88+
>x</button>
89+
</div>
90+
</div>
91+
<SearchBox
92+
className=""
93+
/>
94+
</div>
95+
}
7096
</a>
7197
<a href="#" aria-label="Wishlist">
7298
<Heart className="h-5 w-5 hover:text-black" />
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import React, { useState } from 'react';
2+
3+
export default function SearchBox(){
4+
const [searchQuery, setSearchQuery] = useState('');
5+
6+
// dummy product data
7+
const products = [
8+
{
9+
id: 1,
10+
brand: 'CoreX',
11+
name: '100% Whey Protein - Vanilla',
12+
price: 84.99,
13+
image: '/api/placeholder/60/60'
14+
},
15+
{
16+
id: 2,
17+
brand: 'CoreX',
18+
name: '100% Nova Whey - Vanilla Ice Cream',
19+
price: 74.99,
20+
image: '/api/placeholder/60/60'
21+
},
22+
{
23+
id: 3,
24+
brand: 'CoreX',
25+
name: '100% Nova Whey - Vanilla Ice Cream',
26+
price: 74.99,
27+
image: '/api/placeholder/60/60'
28+
},
29+
{
30+
id: 4,
31+
brand: 'CoreX',
32+
name: '100% Nova Whey - Vanilla Ice Cream',
33+
price: 78.99,
34+
image: '/api/placeholder/60/60'
35+
},
36+
{
37+
id: 5,
38+
brand: 'CoreX',
39+
name: '100% Nova Whey - Vanilla Ice Cream',
40+
price: 73.99,
41+
image: '/api/placeholder/60/60'
42+
}
43+
];
44+
45+
const filteredProducts = products.filter(product =>
46+
product.name.toLowerCase().includes(searchQuery.toLowerCase()) ||
47+
product.brand.toLowerCase().includes(searchQuery.toLowerCase())
48+
);
49+
50+
return (
51+
<div className='md:max-w-100vh sm:w-full max-h-full flex-grid bg-gray-100 gap-4 p-4'>
52+
<hr className="border-t border-gray-300 mt-4" />
53+
<div className="relative w-full mt-4">
54+
<input
55+
type="text"
56+
value={searchQuery}
57+
onChange={(e) => setSearchQuery(e.target.value)}
58+
placeholder="Search products..."
59+
className="w-full px-4 py-3 pr-20 bg-[#89949f] border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
60+
/>
61+
<button
62+
onClick={() => setSearchQuery('')}
63+
className="absolute right-3 top-1/2 -translate-y-1/2 px-3 py-1 text-xs font-medium text-[#042650] hover:text-gray-900 transition-colors"
64+
>
65+
clear
66+
</button>
67+
</div>
68+
<hr className="border-t border-gray-300 my-4" />
69+
<div className='font-bold text-lg mr-4 mt-4 mb-4'>
70+
<p>Products</p>
71+
</div>
72+
73+
<div className='space-y-4'>
74+
{filteredProducts.map((product) => (
75+
<div className='flex items-center justify-start space-x-4 p-2 bg-white rounded-lg shadow hover:shadow-lg hover:scale-[1.02] transition-transform cursor-pointer'>
76+
<div className="w-16 h-16 object-cover rounded">
77+
<img src={product.image} alt="Product_Image" />
78+
</div>
79+
<div>
80+
<h4 className='text-sm'>{product.brand}</h4>
81+
<h2 className="text-sm font-medium text-gray-900">{product.name}</h2>
82+
<p className="text-sm text-gray-500">{product.price}</p>
83+
</div>
84+
</div>
85+
))}
86+
</div>
87+
</div>
88+
)
89+
}

src/components/Search/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from "./SearchBox";

0 commit comments

Comments
 (0)