import * as React from "react"; import { Check, ChevronsUpDown } from "lucide-react"; import { cn } from "@/lib/utils"; import { Button } from "@/components/ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; export interface ComboboxOption { label: string; value: string; } interface ComboboxProps { options: ComboboxOption[]; value?: string; onValueChange?: (value: string) => void; placeholder?: string; searchPlaceholder?: string; emptyText?: string; disabled?: boolean; className?: string; loading?: boolean; } export function Combobox({ options, value, onValueChange, placeholder = "Select option...", searchPlaceholder = "Search...", emptyText = "No options found.", disabled = false, className, loading = false, }: ComboboxProps) { const [open, setOpen] = React.useState(false); const selectedOption = options.find((option) => option.value === value); return ( {loading ? "Loading..." : emptyText} {options.map((option) => ( { const newValue = currentValue === value ? "" : currentValue; onValueChange?.(newValue); setOpen(false); }} > {option.label} ))} ); }