import React, { useState } from "react"; // headless ui import { Combobox, Transition } from "@headlessui/react"; // icons import { ChevronDownIcon } from "@heroicons/react/20/solid"; import { CheckIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline"; // types import { DropdownProps } from "./types"; export type CustomSearchSelectProps = DropdownProps & { footerOption?: JSX.Element; multiple?: boolean; value: any; onChange: any; options: | { value: any; query: string; content: JSX.Element; }[] | undefined; }; export const CustomSearchSelect = ({ buttonClassName = "", className = "", customButton, disabled = false, footerOption, input = false, label, maxHeight = "md", multiple = false, noChevron = false, onChange, options, optionsClassName = "", position = "left", selfPositioned = false, value, verticalPosition = "bottom", width = "auto", }: CustomSearchSelectProps) => { const [query, setQuery] = useState(""); const filteredOptions = query === "" ? options : options?.filter((option) => option.query.toLowerCase().includes(query.toLowerCase())); const props: any = { value, onChange, disabled, }; if (multiple) props.multiple = true; return ( {({ 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) => ( `flex items-center justify-between gap-2 cursor-pointer select-none truncate rounded px-1 py-1.5 ${ active || selected ? "bg-custom-background-80" : "" } ${selected ? "text-custom-text-100" : "text-custom-text-200"}` } > {({ active, selected }) => ( <> {option.content} {multiple ? (
) : ( )} )}
)) ) : (

No matching results

) ) : (

Loading...

)}
{footerOption}
)}
); };