HeaderRow.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import * as React from 'react';
  3. import Cell from "../Cell";
  4. import TableContext from "../context/TableContext";
  5. import { useContext } from '@rc-component/context';
  6. import { getCellFixedInfo } from "../utils/fixUtil";
  7. import { getColumnsKey } from "../utils/valueUtil";
  8. var HeaderRow = function HeaderRow(props) {
  9. var cells = props.cells,
  10. stickyOffsets = props.stickyOffsets,
  11. flattenColumns = props.flattenColumns,
  12. RowComponent = props.rowComponent,
  13. CellComponent = props.cellComponent,
  14. onHeaderRow = props.onHeaderRow,
  15. index = props.index;
  16. var _useContext = useContext(TableContext, ['prefixCls', 'direction']),
  17. prefixCls = _useContext.prefixCls,
  18. direction = _useContext.direction;
  19. var rowProps;
  20. if (onHeaderRow) {
  21. rowProps = onHeaderRow(cells.map(function (cell) {
  22. return cell.column;
  23. }), index);
  24. }
  25. var columnsKey = getColumnsKey(cells.map(function (cell) {
  26. return cell.column;
  27. }));
  28. return /*#__PURE__*/React.createElement(RowComponent, rowProps, cells.map(function (cell, cellIndex) {
  29. var column = cell.column;
  30. var fixedInfo = getCellFixedInfo(cell.colStart, cell.colEnd, flattenColumns, stickyOffsets, direction);
  31. var additionalProps;
  32. if (column && column.onHeaderCell) {
  33. additionalProps = cell.column.onHeaderCell(column);
  34. }
  35. return /*#__PURE__*/React.createElement(Cell, _extends({}, cell, {
  36. scope: column.title ? cell.colSpan > 1 ? 'colgroup' : 'col' : null,
  37. ellipsis: column.ellipsis,
  38. align: column.align,
  39. component: CellComponent,
  40. prefixCls: prefixCls,
  41. key: columnsKey[cellIndex]
  42. }, fixedInfo, {
  43. additionalProps: additionalProps,
  44. rowType: "header"
  45. }));
  46. }));
  47. };
  48. if (process.env.NODE_ENV !== 'production') {
  49. HeaderRow.displayName = 'HeaderRow';
  50. }
  51. export default HeaderRow;