import React, { useRef, useEffect, useState } from 'react'; import { animated, useSpring } from '@react-spring/web'; import clsx from 'clsx'; interface MCDropdownProps { id: string; options: { [key: string]: string }; onSelect: (value: string) => void; selectedValue?: string; className?: string; width: number; isOpen: boolean; onToggle: (id: string) => void; } const MCDropdown: React.FC = ({ id, options, onSelect, selectedValue, className = "relative", width, isOpen, onToggle, }) => { const contentRef = useRef(null); const [contentHeight, setContentHeight] = useState(0); useEffect(() => { if (contentRef.current) { setContentHeight(contentRef.current.scrollHeight); } }, [options]); const springProps = useSpring({ height: isOpen ? contentHeight : 0, opacity: isOpen ? 1 : 0, config: { tension: 300, friction: 30 } }); return (
{Object.entries(options).sort((a, b) => a[0].localeCompare(b[0])).map(([key, value]) => (
{ onSelect(value); onToggle(id); }} className="p-4 hover:bg-mti-purple-ultralight cursor-pointer whitespace-nowrap" > {value}
))}
); }; export default MCDropdown;