import { Settings2 } from 'lucide-react'; import { Button, Checkbox, Dropdown } from 'antd'; import type { MenuProps } from 'antd'; import { type ColumnDef, isGroup } from './tableTypes'; interface Props { defs: ColumnDef[]; visibleKeys: Extract[]; onChange: (keys: Extract[]) => void; } export function ColumnSettings({ defs, visibleKeys, onChange }: Props) { const toggle = (key: Extract, checked: boolean) => { onChange(checked ? [...visibleKeys, key] : visibleKeys.filter((k) => k !== key)); }; const items: MenuProps['items'] = defs.flatMap((def) => { if (isGroup(def)) return def.children.map((child) => ({ key: child.key, label: ( toggle(child.key, e.target.checked)} onClick={(e) => e.stopPropagation()}> {def.title} - {child.title} ), })); return [ { key: def.key, label: ( toggle(def.key, e.target.checked)} onClick={(e) => e.stopPropagation()}> {def.title} ), }, ]; }); return ( ); }