import React, { FC } from 'react'; import { Listbox } from '@headlessui/react'; import { cn } from '~/utils/'; type OptionType = { value: string; display?: string; }; type DropdownPosition = 'left' | 'right'; interface DropdownProps { value: string; label?: string; onChange: (value: string) => void; options: (string | OptionType)[]; className?: string; position?: DropdownPosition; width?: number; maxHeight?: string; testId?: string; } const Dropdown: FC = ({ value, label = '', onChange, options, className = '', position = 'right', width, maxHeight = 'auto', testId = 'dropdown-menu', }) => { const positionClasses = { right: 'origin-bottom-left left-0', left: 'origin-bottom-right right-0', }; return (
{ onChange(newValue); }} >
{label} {options .map((o) => (typeof o === 'string' ? { value: o, display: o } : o)) .find((o) => o.value === value)?.display || value} {options.map((item, index) => ( {typeof item === 'string' ? item : (item as OptionType).display} ))}
); }; export default Dropdown;