"use client"; import React, { useEffect, useRef, useState } from "react"; import { ChevronDown } from "lucide-react"; import { cn } from "@/lib/utils"; export interface Option { value: T; label: React.ReactNode; description?: string; } export function Dropdown({ options, value, onChange, placeholder = "Select...", className, label, size = "md", tone = "secondary", icon, empty = "No options", }: { options: Option[]; value?: T; onChange: (v: T) => void; placeholder?: string; className?: string; label?: string; size?: "sm" | "md"; tone?: "secondary" | "ghost"; icon?: React.ReactNode; empty?: string; }) { const [open, setOpen] = useState(false); const ref = useRef(null); useEffect(() => { function h(e: MouseEvent) { if (!ref.current) return; if (!ref.current.contains(e.target as Node)) setOpen(false); } document.addEventListener("mousedown", h); return () => document.removeEventListener("mousedown", h); }, []); const current = options.find((o) => o.value === value); const btnClass = cn( "inline-flex items-center gap-2 border rounded-lg transition-colors", size === "sm" ? "text-xs px-2.5 py-1.5" : "text-sm px-3 py-2", tone === "secondary" ? "bg-white border-slate-200 text-slate-700 hover:bg-slate-50" : "bg-transparent border-transparent text-slate-700 hover:bg-slate-100", ); return (
{label &&
{label}
} {open && (
{options.length === 0 ? (
{empty}
) : (
    {options.map((o) => (
  • ))}
)}
)}
); }