-
Notifications
You must be signed in to change notification settings - Fork 573
/
HeaderRow.tsx
82 lines (73 loc) · 2.07 KB
/
HeaderRow.tsx
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
79
80
81
82
import * as React from 'react';
import Cell from '../Cell';
import {
CellType,
StickyOffsets,
ColumnType,
CustomizeComponent,
GetComponentProps,
} from '../interface';
import TableContext from '../context/TableContext';
import { getCellFixedInfo } from '../utils/fixUtil';
import { getColumnsKey } from '../utils/valueUtil';
export interface RowProps<RecordType> {
cells: readonly CellType<RecordType>[];
stickyOffsets: StickyOffsets;
flattenColumns: readonly ColumnType<RecordType>[];
rowComponent: CustomizeComponent;
cellComponent: CustomizeComponent;
onHeaderRow: GetComponentProps<readonly ColumnType<RecordType>[]>;
index: number;
}
function HeaderRow<RecordType>({
cells,
stickyOffsets,
flattenColumns,
rowComponent: RowComponent,
cellComponent: CellComponent,
onHeaderRow,
index,
}: RowProps<RecordType>) {
const { prefixCls, direction } = React.useContext(TableContext);
let rowProps: React.HTMLAttributes<HTMLElement>;
if (onHeaderRow) {
rowProps = onHeaderRow(
cells.map(cell => cell.column),
index,
);
}
const columnsKey = getColumnsKey(cells.map(cell => cell.column));
return (
<RowComponent {...rowProps}>
{cells.map((cell: CellType<RecordType>, cellIndex) => {
const { column } = cell;
const fixedInfo = getCellFixedInfo(
cell.colStart,
cell.colEnd,
flattenColumns,
stickyOffsets,
direction,
);
let additionalProps: React.HTMLAttributes<HTMLElement>;
if (column && column.onHeaderCell) {
additionalProps = cell.column.onHeaderCell(column);
}
return (
<Cell
{...cell}
ellipsis={column.ellipsis}
align={column.align}
component={CellComponent}
prefixCls={prefixCls}
key={columnsKey[cellIndex]}
{...fixedInfo}
additionalProps={additionalProps}
rowType="header"
/>
);
})}
</RowComponent>
);
}
HeaderRow.displayName = 'HeaderRow';
export default HeaderRow;