'use client'; import { useEffect, useId, useRef, useState } from 'react'; import { ChevronDown } from 'lucide-react'; export interface CustomSelectOption { value: string; label: string; } interface CustomSelectProps { value: string; onChange: (value: string) => void; options: CustomSelectOption[]; placeholder?: string; className?: string; disabled?: boolean; size?: 'md' | 'sm'; 'aria-label'?: string; } export function CustomSelect({ value, onChange, options, placeholder = 'Select', className = '', disabled = false, size = 'md', 'aria-label': ariaLabel, }: CustomSelectProps) { const [open, setOpen] = useState(false); const rootRef = useRef(null); const listId = useId(); const selected = options.find((option) => option.value === value); const compact = size === 'sm'; useEffect(() => { if (!open) return; const onPointerDown = (event: MouseEvent) => { if (!rootRef.current?.contains(event.target as Node)) setOpen(false); }; const onKeyDown = (event: KeyboardEvent) => { if (event.key === 'Escape') setOpen(false); }; document.addEventListener('mousedown', onPointerDown); window.addEventListener('keydown', onKeyDown); return () => { document.removeEventListener('mousedown', onPointerDown); window.removeEventListener('keydown', onKeyDown); }; }, [open]); return (
{open && ( )}
); }