choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
96 lines (82 loc) • 2.78 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
var _excluded = ["column"];
import React from 'react';
import { connect } from 'mini-store';
import isStickySupport from '../../_util/isStickySupport';
function TableHeaderRow(_ref) {
var prefixCls = _ref.prefixCls,
fixed = _ref.fixed,
row = _ref.row,
index = _ref.index,
height = _ref.height,
components = _ref.components,
onHeaderRow = _ref.onHeaderRow,
placeholder = _ref.placeholder,
rows = _ref.rows;
var HeaderRow = components.header.row;
var HeaderCell = components.header.cell;
var rowProps = onHeaderRow(row.map(function (cell) {
return cell.column;
}), index);
var customStyle = rowProps ? rowProps.style : {};
var style = _objectSpread({
height: height
}, customStyle);
return /*#__PURE__*/React.createElement(HeaderRow, _extends({}, rowProps, {
style: style
}), row.map(function (cell, i) {
var column = cell.column,
cellProps = _objectWithoutProperties(cell, _excluded);
var customProps = column.onHeaderCell ? column.onHeaderCell(column) : {};
if (column.width) {
var addStyle = {
minWidth: column.width,
width: column.width,
maxWidth: column.width
};
customProps.style = _objectSpread(_objectSpread({}, customProps.style), addStyle);
}
if (column.align) {
customProps.style = _objectSpread(_objectSpread({}, customProps.style), {}, {
textAlign: column.align
});
}
return /*#__PURE__*/React.createElement(HeaderCell, _extends({}, cellProps, customProps, {
style: _objectSpread(_objectSpread({}, column.style), customProps.style),
key: column.key || column.dataIndex || i
}));
}), placeholder && /*#__PURE__*/React.createElement("th", {
className: fixed || !isStickySupport() ? undefined : "".concat(prefixCls, "-sticky-column"),
rowSpan: rows.length,
style: {
fontSize: 0,
padding: 0,
right: 0
}
}, "\xA0"));
}
function getRowHeight(state, props) {
var fixedColumnsHeadRowsHeight = state.fixedColumnsHeadRowsHeight;
var columns = props.columns,
rows = props.rows,
fixed = props.fixed;
var headerHeight = fixedColumnsHeadRowsHeight[0];
if (!fixed) {
return null;
}
if (headerHeight && columns) {
if (headerHeight === 'auto') {
return 'auto';
}
return headerHeight / rows.length;
}
return null;
}
export default connect(function (state, props) {
return {
height: getRowHeight(state, props)
};
})(TableHeaderRow);
//# sourceMappingURL=TableHeaderRow.js.map