"use client"; import { Check, ChevronDown } from "lucide-react"; import { useEffect, useRef, useState } from "react"; import { cn } from "@/lib/utils"; export interface SelectOption { value: string; label: string; hint?: string; } export function Select({ value, onChange, options, placeholder = "Select…", className, size = "md", }: { value: string | null; onChange: (value: string) => void; options: SelectOption[]; placeholder?: string; className?: string; size?: "sm" | "md"; }) { const [open, setOpen] = useState(false); const ref = useRef(null); useEffect(() => { if (!open) return; const onDoc = (e: MouseEvent) => { if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false); }; document.addEventListener("mousedown", onDoc); return () => document.removeEventListener("mousedown", onDoc); }, [open]); const selected = options.find((o) => o.value === value); return (
{open && (
{options.length === 0 && (
No options
)} {options.map((o) => ( ))}
)}
); }