import React, { useState, useRef, useEffect } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import styles from './Dropdown.module.css'; interface Option { id: string; label: string; } interface DropdownProps { label: string; options: Option[]; value: string; onChange: (value: string) => void; width?: string; } export const Dropdown: React.FC = ({ label, options, value, onChange, width = '180px' }) => { const [isOpen, setIsOpen] = useState(false); const containerRef = useRef(null); const selectedOption = options.find(o => o.id === value) || options[0]; useEffect(() => { const handleClickOutside = (e: MouseEvent) => { if (containerRef.current && !containerRef.current.contains(e.target as Node)) { setIsOpen(false); } }; document.addEventListener('mousedown', handleClickOutside); return () => document.removeEventListener('mousedown', handleClickOutside); }, []); return (
setIsOpen(!isOpen)} > {selectedOption?.label} ▾
{isOpen && (
{options.map((opt) => (
{ onChange(opt.id); setIsOpen(false); }} > {opt.label} {value === opt.id && ✓}
))}
)}
); };