import { Listbox, ListboxButton, ListboxOptions, ListboxOption, Transition, } from "@headlessui/react"; import { CheckIcon, ChevronDownIcon } from "lucide-react"; import { twMerge } from "tailwind-merge"; export type SelectValue = string | number; export type SelectOption = { label: string; value: SelectValue }; interface ListDropdownProps { options: SelectOption[]; onChange: (val: SelectValue) => void; placeholder?: string; value?: SelectValue; id?: string; className?: string; } export const Select = ({ onChange, options, placeholder, value, id, className, }: ListDropdownProps) => { const selectedOption = options.find( (option: SelectOption) => option.value === value, ) || { label: placeholder || "", value: "" }; return (
{({ open }) => ( <> {selectedOption.label} {options.map((option, itemIdx) => ( twMerge( "relative cursor-pointer select-none py-2 pl-7 pr-2 transition-colors duration-150 ease-in-out", !selected ? "text-base-fg/90" : "text-base-fg", selected && "bg-white/10", focus && "bg-white text-black", ) } value={option.value} > {({ selected }) => ( <> {option.label} {selected ? ( ) : null} )} ))} )}
); }; export default Select;