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+ }
0 commit comments