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" import { Dispatch, SetStateAction, useDeferredValue, useMemo, useState } from "react" import { VList } from "virtua" type Props = { title?: string options: { value: any, label: any }[] value: any setValue: Dispatch> onSelectItem?: (item: any) => any className?: string disabled?: boolean }; export function Combobox({ value, setValue, onSelectItem, options, title, className, disabled }: Props) { const [open, setOpen] = useState(false) const [search, setSearch] = useState("") // Deferred state for the heavy filtering const deferredSearch = useDeferredValue(search) const filteredOptions = useMemo(() => { return options.filter((item) => item.label.toLowerCase().includes(deferredSearch.toLowerCase()) ) }, [deferredSearch, options]) return ( setSearch(val)} /> {/* MANUAL SEARCH */} {filteredOptions.length === 0 ? ( Data tidak ditemukan. ) : ( {filteredOptions.map((item) => ( { setValue(item.value === value ? "" : item.value); if (onSelectItem) onSelectItem(item) setOpen(false) setSearch('') }} // className="h-10" // Fixed height for each item > {item.label} ))} )} ) } export function ComboboxWithoutVirtua({ value, setValue, onSelectItem, options, title, className, disabled }: Props) { const [open, setOpen] = useState(false) const [search, setSearch] = useState("") const deferredSearch = useDeferredValue(search) const filteredOptions = useMemo(() => { return options.filter((item) => item.label.toLowerCase().includes(deferredSearch.toLowerCase()) ) }, [deferredSearch, options]) return ( setSearch(val)} /> {/* MANUAL SEARCH */} {filteredOptions.length === 0 ? ( Data tidak ditemukan. ) : ( {filteredOptions.map((item) => ( { setValue(item.value === value ? "" : item.value); if (onSelectItem) onSelectItem(item) setOpen(false) setSearch('') }} > {item.label} ))} )} ) }