import type { SelectOption } from 'types'; import * as React from 'react'; import { useNavigate } from 'react-router'; import { cn } from 'helpers/cn'; import { Check, ChevronsUpDown } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem } from '@/components/ui/command'; import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; import { Separator } from '@/components/ui/separator'; type ComboboxProps = { options: SelectOption[]; value: string | number; onChange: (value: T) => void; placeholder?: string; className?: string; }; export const Combobox = ({ options, value, onChange, placeholder = 'Select...', className, }: ComboboxProps) => { const navigate = useNavigate(); const [open, setOpen] = React.useState(false); return ( {options?.map((option) => (
{ if (option.href) { return navigate(option.href); } const newValue = options.find( (option) => option.label?.toLowerCase() === currentValue.toLowerCase(), )?.value; if (value && value !== newValue) { const setValue = typeof value === 'number' ? Number(newValue) : '' + newValue; onChange(setValue as T); } setOpen(false); }} > {option.label} {option.href && }
))}
); };