import * as React from "react" import { CheckIcon, ChevronsUpDownIcon } 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 function Combobox({ values = [], defaultText = "Select value...", placeholderText = "Search...", emptyText = "No value found.", renderValue = (value) => value ? values.find((current) => current.value === value)?.label! : defaultText, }: { values?: { value: string; label: string }[] emptyText?: string placeholderText?: string defaultText?: string renderValue?: (value: string) => string }) { const [open, setOpen] = React.useState(false) const [current, setValue] = React.useState("") return ( {emptyText} {values.map(({ value, label }) => ( { setValue(currentValue === value ? "" : currentValue) setOpen(false) }} > {label} ))} ) }