From 32d37ec45effc633d841392ea3c60e257b7a693b Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Date: Wed, 15 Mar 2023 10:59:43 +0530 Subject: [PATCH] refactor: custom search select component (#440) --- .../components/ui/custom-search-select.tsx | 323 ++++++------------ 1 file changed, 109 insertions(+), 214 deletions(-) diff --git a/apps/app/components/ui/custom-search-select.tsx b/apps/app/components/ui/custom-search-select.tsx index 10e1091d1..a085e2e3b 100644 --- a/apps/app/components/ui/custom-search-select.tsx +++ b/apps/app/components/ui/custom-search-select.tsx @@ -1,10 +1,8 @@ import React, { useState } from "react"; - // headless ui import { Combobox, Transition } from "@headlessui/react"; // icons import { CheckIcon, ChevronDownIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline"; - type CustomSearchSelectProps = { value: any; onChange: any; @@ -25,7 +23,6 @@ type CustomSearchSelectProps = { multiple?: boolean; footerOption?: JSX.Element; }; - export const CustomSearchSelect = ({ label, textAlignment, @@ -49,221 +46,119 @@ export const CustomSearchSelect = ({ ? options : options?.filter((option) => option.query.toLowerCase().includes(query.toLowerCase())); + const props: any = { + value, + onChange, + disabled, + }; + + if (multiple) props.multiple = true; + return ( - <> - {/* TODO: Improve this multiple logic */} - {multiple ? ( - - {({ open }: any) => ( - <> - {customButton ? ( - {customButton} - ) : ( - - {label} - {!noChevron && !disabled && ( - + + {({ open }: any) => ( + <> + {customButton ? ( + {customButton} + ) : ( + + {label} + {!noChevron && !disabled && ( + )} - - ) : ( - - {({ open }: any) => ( - <> - {customButton ? ( - {customButton} - ) : ( - - {label} - {!noChevron && !disabled && ( - - )} - - + +
+ + setQuery(e.target.value)} + placeholder="Type to search..." + displayValue={(assigned: any) => assigned?.name} + /> +
+
- -
- - setQuery(e.target.value)} - placeholder="Type to search..." - displayValue={(assigned: any) => assigned?.name} - /> -
-
- {filteredOptions ? ( - filteredOptions.length > 0 ? ( - filteredOptions.map((option) => ( - - `${active || selected ? "bg-hover-gray" : ""} ${ - selected ? "font-medium" : "" - } flex cursor-pointer select-none items-center justify-between gap-2 truncate rounded px-1 py-1.5 text-gray-500` - } - > - {({ selected }) => ( - <> - {option.content} - {selected && } - - )} - - )) - ) : ( -

No matching results

- ) - ) : ( -

Loading...

- )} -
- {footerOption} -
- - - )} - + {filteredOptions ? ( + filteredOptions.length > 0 ? ( + filteredOptions.map((option) => ( + + `${active || selected ? "bg-hover-gray" : ""} ${ + selected ? "font-medium" : "" + } flex cursor-pointer select-none items-center justify-between gap-2 truncate rounded px-1 py-1.5 text-gray-500` + } + > + {({ active, selected }) => ( + <> + {option.content} +
+ +
+ + )} +
+ )) + ) : ( +

No matching results

+ ) + ) : ( +

Loading...

+ )} +
+ {footerOption} +
+
+ )} - +
); };