import * as React from "react" import { Check, ChevronsUpDown, Search } from "lucide-react" import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover" import { ScrollArea } from "@/components/ui/scroll-area" import { SettingInput } from "./settings-ui" import { Label } from "./label" import { cn } from "@/lib/utils" interface Option { label: string value: string icon?: React.ReactNode } interface SearchableSelectProps { options: Option[] value: string onChange: (value: string) => void placeholder?: string className?: string onSearch?: (query: string) => void searchPlaceholder?: string label?: string } export function SearchableSelect({ options, value, onChange, placeholder = "Select an option...", className, onSearch, searchPlaceholder = "Search...", label, }: SearchableSelectProps) { const [open, setOpen] = React.useState(false) const [search, setSearch] = React.useState("") const handleSearchChange = (val: string) => { setSearch(val) if (onSearch) { onSearch(val) } } const filteredOptions = onSearch ? options : options.filter((option) => (option.label || "").toLowerCase().includes(search.toLowerCase()) ) const handleSelect = (val: string) => { onChange(val) setOpen(false) } const selectedOption = options.find(o => o.value === value) const isFlex1 = className?.includes('flex-1') return (
{label && }
e.stopPropagation()} onClick={() => setOpen(!open)} >
{selectedOption?.icon && {selectedOption.icon}} {selectedOption ? selectedOption.label : placeholder}
{filteredOptions.length === 0 ? (
No results found.
) : (
{filteredOptions.map((option) => (
handleSelect(option.value)} >
{option.icon && {option.icon}} {option.label}
{value === option.value && ( )}
))}
)}
) }