ColGroup.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
  3. var _excluded = ["columnType"];
  4. import * as React from 'react';
  5. import { INTERNAL_COL_DEFINE } from "./utils/legacyUtil";
  6. import { useContext } from '@rc-component/context';
  7. import TableContext from "./context/TableContext";
  8. function ColGroup(_ref) {
  9. var colWidths = _ref.colWidths,
  10. columns = _ref.columns,
  11. columCount = _ref.columCount;
  12. var _useContext = useContext(TableContext, ['tableLayout']),
  13. tableLayout = _useContext.tableLayout;
  14. var cols = [];
  15. var len = columCount || columns.length;
  16. // Only insert col with width & additional props
  17. // Skip if rest col do not have any useful info
  18. var mustInsert = false;
  19. for (var i = len - 1; i >= 0; i -= 1) {
  20. var width = colWidths[i];
  21. var column = columns && columns[i];
  22. var additionalProps = void 0;
  23. var minWidth = void 0;
  24. if (column) {
  25. additionalProps = column[INTERNAL_COL_DEFINE];
  26. // fixed will cause layout problems
  27. if (tableLayout === 'auto') {
  28. minWidth = column.minWidth;
  29. }
  30. }
  31. if (width || minWidth || additionalProps || mustInsert) {
  32. var _ref2 = additionalProps || {},
  33. columnType = _ref2.columnType,
  34. restAdditionalProps = _objectWithoutProperties(_ref2, _excluded);
  35. cols.unshift( /*#__PURE__*/React.createElement("col", _extends({
  36. key: i,
  37. style: {
  38. width: width,
  39. minWidth: minWidth
  40. }
  41. }, restAdditionalProps)));
  42. mustInsert = true;
  43. }
  44. }
  45. return cols.length > 0 ? /*#__PURE__*/React.createElement("colgroup", null, cols) : null;
  46. }
  47. export default ColGroup;