import { useState, useEffect, useRef } from 'react' import { cn } from '@/lib/utils' import { ArrowsDownUp, Check } from '@phosphor-icons/react' import { type SortOption, SORT_OPTIONS } from '../utils/noteListHelpers' export function SortDropdown({ groupLabel, current, onChange }: { groupLabel: string current: SortOption onChange: (groupLabel: string, option: SortOption) => void }) { const [open, setOpen] = useState(false) const ref = useRef(null) useEffect(() => { if (!open) return function handleClick(e: MouseEvent) { if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false) } document.addEventListener('mousedown', handleClick) return () => document.removeEventListener('mousedown', handleClick) }, [open]) const handleSelect = (opt: SortOption) => { onChange(groupLabel, opt) setOpen(false) } return (
{open && (
{SORT_OPTIONS.map((opt) => ( ))}
)}
) }