-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysavedwork.js
185 lines (172 loc) · 6.54 KB
/
mysavedwork.js
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
/** @format */
"use client";
import Image from "next/image";
import { Fragment, useState } from "react";
import { Combobox, Transition } from "@headlessui/react";
import { manufacturers } from "@/constants";
import { SearchManuFacturerProps } from "@/types";
// import { SearchManufacturerProps } from '@/types'
// console.log(manufacturers)
const SearchManufacturer = ({
manufacturer,
setManuFacturer,
}: SearchManuFacturerProps) => {
const [query, setQuery] = useState("");
// const filteredManufacturers =
// query === ""
// ? manufacturers
// : manufacturers.filter((item) =>
// item
// .toLowerCase()
// .replace(/\s+/g, "")
// .includes(query.toLowerCase().replace(/\s+/g, ""))
// );
const filteredManufacturers =
query === ""
? manufacturers
: manufacturers.filter((item) =>
item
.toLowerCase()
.replace(/\s+/g, "")
.includes(query.toLowerCase().replace(/\s+/g, ""))
);
// return (
// <div className='search-manufacturer'>
// <Combobox value={manufacturer} onChange={setManuFacturer}>
// <div className='relative w-full'>
// {/* Button for the combobox. Click on the icon to see the complete dropdown */}
// <Combobox.Button className='absolute top-[14px]'>
// <Image
// src='/car-logo.svg'
// width={20}
// height={20}
// className='ml-4'
// alt='car logo'
// />
// </Combobox.Button>
// {/* Input field for searching */}
// <Combobox.Input
// className='search-manufacturer__input'
// displayValue={(item: string) => item}
// onChange={(event) => setQuery(event.target.value)} // Update the search query when the input changes
// placeholder='Volkswagen...'
// />
// {/* Transition for displaying the options */}
// <Transition
// as={Fragment} // group multiple elements without introducing an additional DOM node i.e., <></>
// leave='transition ease-in duration-100'
// leaveFrom='opacity-100'
// leaveTo='opacity-0'
// afterLeave={() => setQuery("")} // Reset the search query after the transition completes
// >
// <Combobox.Options
// className='absolute mt-1 max-h-60 w-full overflow-auto rounded-md bg-white py-1 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm'
// static
// >
// {filteredManufacturers.length === 0 && query !== "" ? (
// <Combobox.Option
// value={query}
// className='search-manufacturer__option'
// >
// Create "{query}"
// </Combobox.Option>
// ) : (
// filteredManufacturers.map((item) => (
// <Combobox.Option
// key={item}
// className={({ active }) =>
// `relative search-manufacturer__option ${
// active ? "bg-primary-blue text-white" : "text-gray-900"
// }`
// }
// value={item}
// >
// {({ selected, active }) => (
// <>
// <span className={`block truncate ${selected ? "font-medium" : "font-normal"}`}>
// {item}
// </span>
// {/* Show an active blue background color if the option is selected */}
// {selected ? (
// <span className={`absolute inset-y-0 left-0 flex items-center pl-3 ${active? "text-white": "text-pribg-primary-purple"}`}
// ></span>
// ) : null}
// </>
// )}
// </Combobox.Option>
// ))
// )}
// </Combobox.Options>
// </Transition>
// </div>
// </Combobox>
// </div>
// );
// };
// export default SearchManufacturer;
return (
<div className="search-manufacturer">
<Combobox value={manufacturer} onChange={setManuFacturer}>
<div className="relative w-full">
{/* Button for the combobox. Click on the icon to see the complete dropdown */}
<Combobox.Button className="absolute top-[14px]">
<Image
src="/car-logo.svg"
width={20}
height={20}
className="ml-4"
alt="car logo"
/>
</Combobox.Button>
{/* Input field for searching */}
<Combobox.Input
className="search-manufacturer__input"
displayValue={(item: string) => item}
onChange={(event) => setQuery(event.target.value)} // Update the search query when the input changes
placeholder="Volkswagen..."
/>
{/* Transition for displaying the options */}
<Transition
as={Fragment} // group multiple elements without introducing an additional DOM node i.e., <></>
leave="transition ease-in duration-100"
leaveFrom="opacity-100"
leaveTo="opacity-0"
afterLeave={() => setQuery("")} // Reset the search query after the transition completes
>
<Combobox.Options
className="absolute mt-1 max-h-60 w-full overflow-auto rounded-md bg-white py-1 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm"
static>
{filteredManufacturers.map((item) => (
<Combobox.Option
key={item}
className={({ active }) =>
`relative search-manufacturer__option ${
active ? "bg-primary-blue text-white" : "text-gray-900"
}`
}
value={item}>
{({ selected, active }) => (
<div
className={`block truncate ${
selected ? "font-medium" : "font-normal"
}`}>
{item}
{/* Show an active blue background color if the option is selected */}
{selected ? (
<span
className={`absolute inset-y-0 left-0 flex items-center pl-3 ${
active ? "text-white" : "text-pribg-primary-purple"
}`}></span>
) : null}
</div>
)}
</Combobox.Option>
))}
</Combobox.Options>
</Transition>
</div>
</Combobox>
</div>
);
};
export default SearchManufacturer;