94 lines
5.6 KiB
JavaScript
94 lines
5.6 KiB
JavaScript
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
|
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
|
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
|
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
|
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
|
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
|
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
|
|
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
|
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
|
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
|
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
|
|
import * as React from 'react';
|
|
import Header from './Header';
|
|
import ColGroup from '../ColGroup';
|
|
import TableContext from '../context/TableContext';
|
|
|
|
function FixedHeader(_ref) {
|
|
var columns = _ref.columns,
|
|
flattenColumns = _ref.flattenColumns,
|
|
colWidths = _ref.colWidths,
|
|
columCount = _ref.columCount,
|
|
stickyOffsets = _ref.stickyOffsets,
|
|
direction = _ref.direction,
|
|
props = _objectWithoutProperties(_ref, ["columns", "flattenColumns", "colWidths", "columCount", "stickyOffsets", "direction"]);
|
|
|
|
var _React$useContext = React.useContext(TableContext),
|
|
prefixCls = _React$useContext.prefixCls,
|
|
scrollbarSize = _React$useContext.scrollbarSize; // Add scrollbar column
|
|
|
|
|
|
var lastColumn = flattenColumns[flattenColumns.length - 1];
|
|
var ScrollBarColumn = {
|
|
fixed: lastColumn ? lastColumn.fixed : null,
|
|
onHeaderCell: function onHeaderCell() {
|
|
return {
|
|
className: "".concat(prefixCls, "-cell-scrollbar")
|
|
};
|
|
}
|
|
};
|
|
var columnsWithScrollbar = React.useMemo(function () {
|
|
return scrollbarSize ? [].concat(_toConsumableArray(columns), [ScrollBarColumn]) : columns;
|
|
}, [scrollbarSize, columns]);
|
|
var flattenColumnsWithScrollbar = React.useMemo(function () {
|
|
return scrollbarSize ? [].concat(_toConsumableArray(flattenColumns), [ScrollBarColumn]) : flattenColumns;
|
|
}, [scrollbarSize, flattenColumns]); // Calculate the sticky offsets
|
|
|
|
var headerStickyOffsets = React.useMemo(function () {
|
|
var right = stickyOffsets.right,
|
|
left = stickyOffsets.left;
|
|
return _objectSpread({}, stickyOffsets, {
|
|
left: direction === 'rtl' ? [].concat(_toConsumableArray(left.map(function (width) {
|
|
return width + scrollbarSize;
|
|
})), [0]) : left,
|
|
right: direction === 'rtl' ? right : [].concat(_toConsumableArray(right.map(function (width) {
|
|
return width + scrollbarSize;
|
|
})), [0])
|
|
});
|
|
}, [scrollbarSize, stickyOffsets]);
|
|
var cloneWidths = [];
|
|
|
|
for (var i = 0; i < columCount; i += 1) {
|
|
cloneWidths[i] = colWidths[i];
|
|
}
|
|
|
|
var columnWidthsReady = !colWidths.every(function (width) {
|
|
return !width;
|
|
});
|
|
return React.createElement("table", {
|
|
style: {
|
|
tableLayout: 'fixed',
|
|
visibility: columnWidthsReady ? null : 'hidden'
|
|
}
|
|
}, React.createElement(ColGroup, {
|
|
colWidths: [].concat(_toConsumableArray(colWidths), [scrollbarSize]),
|
|
columCount: columCount + 1
|
|
}), React.createElement(Header, Object.assign({}, props, {
|
|
stickyOffsets: headerStickyOffsets,
|
|
columns: columnsWithScrollbar,
|
|
flattenColumns: flattenColumnsWithScrollbar
|
|
})));
|
|
}
|
|
|
|
export default FixedHeader; |