import React, { useState } from "react"; import { usePopper } from "react-popper"; import { Combobox } from "@headlessui/react"; import { Check, ChevronDown, Search, Triangle } from "lucide-react"; // types import { Tooltip } from "@plane/ui"; import { Placement } from "@popperjs/core"; // constants import { IEstimatePoint } from "types"; type Props = { value: number | null; onChange: (value: number | null) => void; estimatePoints: IEstimatePoint[] | undefined; className?: string; buttonClassName?: string; optionsClassName?: string; placement?: Placement; hideDropdownArrow?: boolean; disabled?: boolean; }; export const EstimateSelect: React.FC = (props) => { const { value, onChange, estimatePoints, className = "", buttonClassName = "", optionsClassName = "", placement, hideDropdownArrow = false, disabled = false, } = props; const [query, setQuery] = useState(""); const [referenceElement, setReferenceElement] = useState(null); const [popperElement, setPopperElement] = useState(null); const { styles, attributes } = usePopper(referenceElement, popperElement, { placement: placement ?? "bottom-start", modifiers: [ { name: "preventOverflow", options: { padding: 12, }, }, ], }); const options: { value: number | null; query: string; content: any }[] | undefined = estimatePoints?.map( (estimate) => ({ value: estimate.key, query: estimate.value, content: (
{estimate.value}
), }) ); options?.unshift({ value: null, query: "none", content: (
None
), }); const filteredOptions = query === "" ? options : options?.filter((option) => option.query.toLowerCase().includes(query.toLowerCase())); const selectedEstimate = estimatePoints?.find((e) => e.key === value); const label = (
{selectedEstimate?.value ?? "None"}
); return ( onChange(val as number | null)} disabled={disabled} >
setQuery(e.target.value)} placeholder="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 ? "bg-custom-background-80" : "" } ${selected ? "text-custom-text-100" : "text-custom-text-200"}` } > {({ selected }) => ( <> {option.content} {selected && } )} )) ) : (

No matching results

) ) : (

Loading...

)}
); };