import React, { useState } from 'react' import ArrowDownIcon from '../icons/ArrowDownIcon'; export interface DropdownOption { id: string; title: string; } type Props = { title: string; options: Array; expanded?: boolean; selectedId: string; onSelectionChange: (e: React.MouseEvent, index: number) => void, } & React.HTMLAttributes function MultiOption({ title, options, expanded, selectedId, onSelectionChange, ...props }: Props) { const [expand, setExpand] = useState(expanded); const toggleExpand = () => { setExpand((state) => !state); } return (
{options.filter(x => x.id === selectedId)[0]?.title ?? ''}
{expand &&
{options.map((v, i) => { return (
{setExpand(() => false); onSelectionChange(e, i) }} key={v.id} data-selected={v.id === selectedId} className='flex items-center justify-end px-3 py-3 cursor-pointer hover:bg-gray-50 first:rounded-t-xl last:rounded-b-xl' tabIndex={0} role='option' aria-selected> {v.title}
) })}
}
) } export default MultiOption