import { useState, useRef, useEffect } from "react"; interface Option { value: string; label: string; } interface Props { options: Option[]; value: string; onChange: (value: string) => void; placeholder?: string; } export default function Select({ options, value, onChange, placeholder }: Props) { const [open, setOpen] = useState(false); const ref = useRef(null); useEffect(() => { function handleClickOutside(e: MouseEvent) { if (ref.current && !ref.current.contains(e.target as Node)) { setOpen(false); } } document.addEventListener("mousedown", handleClickOutside); return () => document.removeEventListener("mousedown", handleClickOutside); }, []); const selected = options.find((o) => o.value === value); return (
{open && (
{options.map((opt) => ( ))}
)}
); }