import { ChevronDown } from "lucide-react"; import type { FocusEvent } from "react"; import { useMemo, useState } from "react"; export type SelectOption = { value: string; label: string; }; type SelectFieldProps = { label?: string; value: string; options: SelectOption[]; placeholder?: string; onChange: (value: string) => void; }; export function SelectField({ label, value, options, placeholder = "Select", onChange }: SelectFieldProps) { const [open, setOpen] = useState(false); const selectedOption = useMemo(() => options.find((option) => option.value === value), [options, value]); const closeOnOutsideBlur = (event: FocusEvent) => { const nextTarget = event.relatedTarget; if (!(nextTarget instanceof Node) || !event.currentTarget.contains(nextTarget)) { setOpen(false); } }; const control = (
{open && (
{options.map((option) => ( ))}
)}
); if (!label) return control; return ( ); }