import clsx from 'clsx'; import { Menu, MenuButton, MenuList } from '@reach/menu-button'; import { Columns } from 'lucide-react'; import { Column } from '@tanstack/react-table'; import { Checkbox } from '@@/form-components/Checkbox'; interface Props { columns: Column[]; onChange: (value: string[]) => void; value: string[]; } export function ColumnVisibilityMenu({ columns, onChange, value, }: Props) { return ( {({ isExpanded }) => ( <>
Show / Hide Columns
{columns.map((column) => (
handleChangeColumnVisibility( column.id, e.target.checked ) } />
))}
)}
); function handleChangeColumnVisibility(colId: string, visible: boolean) { if (visible) { onChange(value.filter((id) => id !== colId)); return; } onChange([...value, colId]); } }