index.js
3.21 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import * as React from 'react';
import BodyRow from './BodyRow';
import TableContext from '../context/TableContext';
import ExpandedRow from './ExpandedRow';
import BodyContext from '../context/BodyContext';
import { getColumnsKey } from '../utils/valueUtil';
import ResizeContext from '../context/ResizeContext';
import MeasureCell from './MeasureCell';
function Body(_ref) {
var data = _ref.data,
getRowKey = _ref.getRowKey,
measureColumnWidth = _ref.measureColumnWidth,
expandedKeys = _ref.expandedKeys,
onRow = _ref.onRow,
rowExpandable = _ref.rowExpandable,
emptyNode = _ref.emptyNode,
childrenColumnName = _ref.childrenColumnName;
var _React$useContext = React.useContext(ResizeContext),
onColumnResize = _React$useContext.onColumnResize;
var _React$useContext2 = React.useContext(TableContext),
prefixCls = _React$useContext2.prefixCls,
getComponent = _React$useContext2.getComponent;
var _React$useContext3 = React.useContext(BodyContext),
fixHeader = _React$useContext3.fixHeader,
horizonScroll = _React$useContext3.horizonScroll,
flattenColumns = _React$useContext3.flattenColumns,
componentWidth = _React$useContext3.componentWidth;
return React.useMemo(function () {
var WrapperComponent = getComponent(['body', 'wrapper'], 'tbody');
var trComponent = getComponent(['body', 'row'], 'tr');
var tdComponent = getComponent(['body', 'cell'], 'td');
var rows;
if (data.length) {
rows = data.map(function (record, index) {
var key = getRowKey(record, index);
return React.createElement(BodyRow, {
key: key,
rowKey: key,
record: record,
recordKey: key,
index: index,
rowComponent: trComponent,
cellComponent: tdComponent,
expandedKeys: expandedKeys,
onRow: onRow,
getRowKey: getRowKey,
rowExpandable: rowExpandable,
childrenColumnName: childrenColumnName
});
});
} else {
rows = React.createElement(ExpandedRow, {
expanded: true,
className: "".concat(prefixCls, "-placeholder"),
prefixCls: prefixCls,
fixHeader: fixHeader,
fixColumn: horizonScroll,
horizonScroll: horizonScroll,
component: trComponent,
componentWidth: componentWidth,
cellComponent: tdComponent,
colSpan: flattenColumns.length
}, emptyNode);
}
var columnsKey = getColumnsKey(flattenColumns);
return React.createElement(WrapperComponent, {
className: "".concat(prefixCls, "-tbody")
}, measureColumnWidth && React.createElement("tr", {
"aria-hidden": "true",
className: "".concat(prefixCls, "-measure-row"),
style: {
height: 0,
fontSize: 0
}
}, columnsKey.map(function (columnKey) {
return React.createElement(MeasureCell, {
key: columnKey,
columnKey: columnKey,
onColumnResize: onColumnResize
});
})), rows);
}, [data, prefixCls, onRow, measureColumnWidth, expandedKeys, getRowKey, getComponent, componentWidth, emptyNode, flattenColumns]);
}
var MemoBody = React.memo(Body);
MemoBody.displayName = 'Body';
export default MemoBody;