zent
Version:
一套前端设计语言和基于React的实现
61 lines (60 loc) • 4.22 kB
JavaScript
import { __assign, __extends } from "tslib";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { PureComponent } from 'react';
import classnames from 'classnames';
import Row from './Row';
import ColGroup from './ColGroup';
import isNil from '../utils/isNil';
var Body = (function (_super) {
__extends(Body, _super);
function Body() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.onBodyMouseLeave = function () {
var _a = _this.props, onRowMouseEnter = _a.onRowMouseEnter, hasFixedColumn = _a.hasFixedColumn;
hasFixedColumn && onRowMouseEnter(-1);
};
return _this;
}
Body.prototype.getRows = function () {
var _a = this.props, prefix = _a.prefix, datasets = _a.datasets, columns = _a.columns, rowKey = _a.rowKey, rowClassName = _a.rowClassName, onRowClick = _a.onRowClick, onRowMouseEnter = _a.onRowMouseEnter, mouseOverRowIndex = _a.mouseOverRowIndex, fixed = _a.fixed, hasFixedColumn = _a.hasFixedColumn, scroll = _a.scroll, expandRowKeys = _a.expandRowKeys, expandRender = _a.expandRender, fixedColumnsBodyRowsHeight = _a.fixedColumnsBodyRowsHeight, fixedColumnsBodyExpandRowsHeight = _a.fixedColumnsBodyExpandRowsHeight, components = _a.components, rowProps = _a.rowProps, disableHoverHighlight = _a.disableHoverHighlight;
var row = [];
(datasets || []).forEach(function (data, index) {
row.push(_jsx(Row, { data: data, columns: columns, index: index, rowIndex: index, prefix: prefix, rowClassName: rowClassName, mouseOverRowIndex: mouseOverRowIndex, onRowClick: onRowClick, onRowMouseEnter: onRowMouseEnter, fixed: fixed, hasFixedColumn: hasFixedColumn, scroll: scroll, fixedColumnsBodyRowsHeight: fixedColumnsBodyRowsHeight, row: components && components.row, rowProps: rowProps, disableHoverHighlight: disableHoverHighlight }, rowKey ? data === null || data === void 0 ? void 0 : data[rowKey] : index));
if (expandRender && expandRowKeys.length > 0) {
var height = fixed && fixedColumnsBodyExpandRowsHeight[index]
? fixedColumnsBodyExpandRowsHeight[index]
: undefined;
var trProps = {
key: index + "-expand",
className: prefix + "-grid-tr__expanded",
style: { display: expandRowKeys[index] ? '' : 'none', height: height },
};
if (fixed !== 'right') {
row.push(_jsxs("tr", __assign({}, trProps, { "data-zv": '10.0.17' }, { children: [_jsx("td", { "data-zv": '10.0.17' }, void 0), _jsx("td", __assign({ colSpan: columns.length - 1, "data-zv": '10.0.17' }, { children: expandRender(data) }), void 0)] }), void 0));
}
else {
row.push(_jsx("tr", __assign({}, trProps, { "data-zv": '10.0.17' }, { children: _jsx("td", { colSpan: columns.length, "data-zv": '10.0.17' }, void 0) }), void 0));
}
}
});
return row;
};
Body.prototype.renderTbody = function () {
var _a;
var _b = this.props, prefix = _b.prefix, columns = _b.columns;
var tbodyClass = classnames(prefix + "-grid-tbody", (_a = {},
_a[prefix + "-grid-tbody-span"] = columns.some(function (item) { return !!(item.colSpan || item.rowSpan); }),
_a));
return (_jsx("tbody", __assign({ onMouseLeave: this.onBodyMouseLeave, className: tbodyClass, "data-zv": '10.0.17' }, { children: this.getRows() }), void 0));
};
Body.prototype.render = function () {
var _a = this.props, scroll = _a.scroll, fixed = _a.fixed, prefix = _a.prefix, columns = _a.columns, size = _a.size;
var bodyStyle = {};
if (!fixed && !isNil(scroll.x)) {
bodyStyle.width = scroll.x;
}
return scroll.y ? (_jsxs("table", __assign({ className: prefix + "-grid-table " + prefix + "-grid-table-" + size, style: bodyStyle, "data-zv": '10.0.17' }, { children: [_jsx(ColGroup, { columns: columns }, void 0), this.renderTbody()] }), void 0)) : (this.renderTbody());
};
return Body;
}(PureComponent));
export default Body;