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; options: { value: any; query: string; content: JSX.Element; }[]; label?: string | JSX.Element; textAlignment?: "left" | "center" | "right"; height?: "sm" | "md" | "rg" | "lg"; position?: "right" | "left"; noChevron?: boolean; customButton?: JSX.Element; optionsClassName?: string; disabled?: boolean; selfPositioned?: boolean; multiple?: boolean; footerOption?: JSX.Element; }; export const CustomSearchSelect = ({ label, textAlignment, height = "md", value, onChange, options, position = "left", noChevron = false, customButton, optionsClassName = "", disabled = false, selfPositioned = false, multiple = false, footerOption, }: CustomSearchSelectProps) => { const [query, setQuery] = useState(""); const filteredOptions = query === "" ? options : options?.filter((option) => option.query.toLowerCase().includes(query.toLowerCase())); return ( <> {/* TODO: Improve this multiple logic */} {multiple ? ( {({ open }: any) => ( <> {customButton ? ( {customButton} ) : ( {label} {!noChevron && !disabled && ( )} )} 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` } > {({ active, selected }) => ( <> {option.content} > )} )) ) : ( No matching results ) ) : ( Loading... )} {footerOption} > )} ) : ( {({ open }: any) => ( <> {customButton ? ( {customButton} ) : ( {label} {!noChevron && !disabled && ( )} )} 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} > )} )} > ); };
No matching results
Loading...