import * as React from 'react'; import { cn } from '../../lib/utils'; import { Badge } from './badge'; export type SelectItem = { value: string; label?: string; hex?: string; disabled?: boolean; badge?: string; }; export function SelectMenu({ value, onChange, items = [], className, }: { value: string; onChange: (next: string) => void; items?: SelectItem[]; className?: string; }) { const [open, setOpen] = React.useState(false); const ref = React.useRef(null); React.useEffect(() => { function onDoc(e: MouseEvent) { if (!ref.current) return; if (!ref.current.contains(e.target as Node)) setOpen(false); } document.addEventListener('mousedown', onDoc); return () => document.removeEventListener('mousedown', onDoc); }, []); const current = items.find((i) => i.value === value); return (
{open && (
{items.map((it) => ( ))}
)}
); }