import React, { FC, useState } 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: initialValue, label = '', onChange, options, className = '', position = 'right', width, maxHeight = 'auto', testId = 'dropdown-menu', }) => { const [selectedValue, setSelectedValue] = useState(initialValue); const positionClasses = { right: 'origin-bottom-left left-0', left: 'origin-bottom-right right-0', }; return (
{ setSelectedValue(newValue); onChange(newValue); }} >
{label} {options .map((o) => (typeof o === 'string' ? { value: o, display: o } : o)) .find((o) => o.value === selectedValue)?.display || selectedValue} {options.map((item, index) => ( {typeof item === 'string' ? item : (item as OptionType).display} ))}
); }; export default Dropdown;