-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathColumns.tsx
More file actions
78 lines (70 loc) · 2.03 KB
/
Columns.tsx
File metadata and controls
78 lines (70 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { useHeaderRowSelection, useRowSelection } from './hooks';
import type {
Column,
RenderCellContentProps,
RenderGroupCellContentProps,
RenderHeaderCellContentProps
} from './types';
import { SelectCheckbox } from './cellRenderers';
export const SELECT_COLUMN_KEY = 'rdg-select-column';
function SelectAllCell({ tabIndex }: RenderHeaderCellContentProps<unknown>) {
const { isIndeterminate, isRowSelected, onRowSelectionChange } = useHeaderRowSelection();
return (
<SelectCheckbox
aria-label="Select All"
tabIndex={tabIndex}
indeterminate={isIndeterminate}
value={isRowSelected}
onChange={(checked) => {
onRowSelectionChange({ checked: isIndeterminate ? false : checked });
}}
/>
);
}
function RowSelectCell({ row, tabIndex }: RenderCellContentProps<unknown>) {
const { isRowSelectionDisabled, isRowSelected, onRowSelectionChange } = useRowSelection();
return (
<SelectCheckbox
aria-label="Select"
tabIndex={tabIndex}
disabled={isRowSelectionDisabled}
value={isRowSelected}
onChange={(checked, isShiftClick) => {
onRowSelectionChange({ row, checked, isShiftClick });
}}
/>
);
}
function GroupSelectCell({ row, tabIndex }: RenderGroupCellContentProps<unknown>) {
const { isRowSelected, onRowSelectionChange } = useRowSelection();
return (
<SelectCheckbox
aria-label="Select Group"
tabIndex={tabIndex}
value={isRowSelected}
onChange={(checked) => {
onRowSelectionChange({ row, checked, isShiftClick: false });
}}
/>
);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const SelectColumn: Column<any, any> = {
key: SELECT_COLUMN_KEY,
name: '',
width: 35,
minWidth: 35,
maxWidth: 35,
resizable: false,
sortable: false,
frozen: true,
renderHeaderCell(props) {
return <SelectAllCell {...props} />;
},
renderCell(props) {
return <RowSelectCell {...props} />;
},
renderGroupCell(props) {
return <GroupSelectCell {...props} />;
}
};