-
-
Notifications
You must be signed in to change notification settings - Fork 619
Expand file tree
/
Copy pathHeader.tsx
More file actions
55 lines (49 loc) · 1.7 KB
/
Header.tsx
File metadata and controls
55 lines (49 loc) · 1.7 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
import { useContext } from '@rc-component/context';
import * as React from 'react';
import TableContext, { responseImmutable } from '../context/TableContext';
import devRenderTimes from '../hooks/useRenderTimes';
import type {
CellType,
ColumnsType,
ColumnType,
GetComponentProps,
StickyOffsets,
} from '../interface';
import HeaderRow from './HeaderRow';
export interface HeaderProps<RecordType> {
columns: ColumnsType<RecordType>;
headCells: CellType<RecordType>[][];
flattenColumns: readonly ColumnType<RecordType>[];
stickyOffsets: StickyOffsets;
onHeaderRow: GetComponentProps<readonly ColumnType<RecordType>[]>;
}
const Header = <RecordType extends any>(props: HeaderProps<RecordType>) => {
if (process.env.NODE_ENV !== 'production') {
devRenderTimes(props);
}
const { stickyOffsets, headCells, flattenColumns, onHeaderRow } = props;
const { prefixCls, getComponent } = useContext(TableContext, ['prefixCls', 'getComponent']);
const WrapperComponent = getComponent(['header', 'wrapper'], 'thead');
const trComponent = getComponent(['header', 'row'], 'tr');
const thComponent = getComponent(['header', 'cell'], 'th');
return (
<WrapperComponent className={`${prefixCls}-thead`}>
{headCells.map((row, rowIndex) => {
const rowNode = (
<HeaderRow
key={rowIndex}
flattenColumns={flattenColumns}
cells={row}
stickyOffsets={stickyOffsets}
rowComponent={trComponent}
cellComponent={thComponent}
onHeaderRow={onHeaderRow}
index={rowIndex}
/>
);
return rowNode;
})}
</WrapperComponent>
);
};
export default responseImmutable(Header);