'use client'; import { useEffect, useRef, useState } from 'react'; export interface SelectOption { value: string; label: string; disabled?: boolean; } interface Props { options: SelectOption[]; placeholder: string; onChange: (value: string) => void; } export default function CustomSelect({ options, placeholder, onChange }: Props) { const [open, setOpen] = useState(false); const ref = useRef(null); useEffect(() => { function handleOutside(e: MouseEvent) { if (ref.current && !ref.current.contains(e.target as Node)) { setOpen(false); } } if (open) document.addEventListener('mousedown', handleOutside); return () => document.removeEventListener('mousedown', handleOutside); }, [open]); function select(value: string) { setOpen(false); onChange(value); } return (
{open && (
{options.map((opt) => ( ))}
)}
); }