import React, { FC, useContext, useState } from 'react'; import { Listbox } from '@headlessui/react'; import { cn } from '~/utils/'; type OptionType = { value: string; display?: string; }; interface DropdownProps { value: string; label?: string; onChange: (value: string) => void; options: (string | OptionType)[]; className?: string; width?: number; testId?: string; } const Dropdown: FC = ({ value: initialValue, label = '', onChange, options, className = '', width, testId = 'dropdown-menu', }) => { const [selectedValue, setSelectedValue] = useState(initialValue); 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;