-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathColumns.tsx
More file actions
73 lines (65 loc) · 1.96 KB
/
Columns.tsx
File metadata and controls
73 lines (65 loc) · 1.96 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
import { useRowSelection } from './hooks/useRowSelection';
import { stopPropagation } from './utils';
import type { Column, RenderCellProps, RenderGroupCellProps, RenderHeaderCellProps } from './types';
import { SelectCellFormatter } from './cellRenderers';
export const SELECT_COLUMN_KEY = 'select-row';
function HeaderRenderer(props: RenderHeaderCellProps<unknown>) {
const [isRowSelected, onRowSelectionChange] = useRowSelection();
return (
<SelectCellFormatter
aria-label="Select All"
tabIndex={props.tabIndex}
value={isRowSelected}
onChange={(checked) => {
onRowSelectionChange({ type: 'HEADER', checked });
}}
/>
);
}
function SelectFormatter(props: RenderCellProps<unknown>) {
const [isRowSelected, onRowSelectionChange] = useRowSelection();
return (
<SelectCellFormatter
aria-label="Select"
tabIndex={props.tabIndex}
value={isRowSelected}
onChange={(checked, isShiftClick) => {
onRowSelectionChange({ type: 'ROW', row: props.row, checked, isShiftClick });
}}
/>
);
}
function SelectGroupFormatter(props: RenderGroupCellProps<unknown>) {
const [isRowSelected, onRowSelectionChange] = useRowSelection();
return (
<SelectCellFormatter
aria-label="Select Group"
tabIndex={props.tabIndex}
value={isRowSelected}
onClick={stopPropagation}
onChange={(checked) => {
onRowSelectionChange({ type: 'ROW', row: props.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 <HeaderRenderer {...props} />;
},
renderCell(props) {
return <SelectFormatter {...props} />;
},
renderGroupCell(props) {
return <SelectGroupFormatter {...props} />;
}
};