import clsx from 'clsx'; import { Menu, MenuButton, MenuList } from '@reach/menu-button'; import { ColumnInstance } from 'react-table'; import { Columns } from 'react-feather'; import { Checkbox } from '@@/form-components/Checkbox'; import { useTableContext } from './TableContainer'; interface Props { columns: ColumnInstance[]; onChange: (value: string[]) => void; value: string[]; } export function ColumnVisibilityMenu({ columns, onChange, value, }: Props) { useTableContext(); 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]); } }