import { useEffect, useRef, useState } from 'react' import type { VisibilityState } from '@tanstack/react-table' import { COLUMN_MENU } from '../lib/trackColumns' interface Props { visibility: VisibilityState onChange: (v: VisibilityState) => void onReset: () => void } /** Dropdown of checkboxes to show/hide library columns, plus a layout reset. */ export function ColumnsMenu({ visibility, onChange, onReset }: Props) { const [open, setOpen] = useState(false) const ref = useRef(null) useEffect(() => { if (!open) return const onDoc = (e: MouseEvent) => { if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false) } document.addEventListener('mousedown', onDoc) return () => document.removeEventListener('mousedown', onDoc) }, [open]) const isVisible = (id: string) => visibility[id] !== false // default-visible unless explicitly false return (
{open && (
{COLUMN_MENU.map((c) => ( ))}
)}
) }