import React, { useState } from 'react'; import * as Select from '@ariakit/react/select'; import type { Option } from '~/common'; import { cn } from '~/utils/'; interface DropdownProps { value: string; label?: string; onChange: (value: string) => void; options: string[] | Option[]; className?: string; sizeClasses?: string; testId?: string; } const Dropdown: React.FC = ({ value: initialValue, label = '', onChange, options, className = '', sizeClasses, testId = 'dropdown-menu', }) => { const [selectedValue, setSelectedValue] = useState(initialValue); const handleChange = (value: string) => { setSelectedValue(value); onChange(value); }; const selectProps = Select.useSelectStore({ value: selectedValue, setValue: handleChange, }); return (
{label} {options .map((o) => (typeof o === 'string' ? { value: o, label: o } : o)) .find((o) => o.value === selectedValue)?.label ?? selectedValue}
{options.map((item, index) => (
{typeof item === 'string' ? item : (item as Option).label} {selectedValue === (typeof item === 'string' ? item : item.value) && ( )}
))}
); }; export default Dropdown;