import { Check, ChevronsUpDown } from "lucide-react"; import * as React from "react"; 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"; import { cn } from "~/lib/clsx"; export interface ComboboxItem { value: string; label: string; } interface ComboboxProps { items: ComboboxItem[]; placeholder?: string; searchPlaceholder?: string; buttonClassName?: string; onValueChange?: (value: string) => void; defaultValue?: string; } export function Combobox({ items, placeholder = "Pilih salah satu...", searchPlaceholder = "Cari opsi...", buttonClassName = "w-[200px]", onValueChange, defaultValue = "", }: ComboboxProps) { const [open, setOpen] = React.useState(false); const [value, setValue] = React.useState(defaultValue); const handleSelect = (currentValue: string) => { setValue(currentValue === value ? "" : currentValue); setOpen(false); if (onValueChange) { onValueChange(currentValue === value ? "" : currentValue); } }; return ( Tidak ada item yang ditemukan. {items.map((item) => ( handleSelect(item.value)} > {item.label} ))} ); }