UNPKG

@douyinfe/semi-ui

Version:

A modern, comprehensive, flexible design system and UI library. Connect DesignOps & DevOps. Quickly build beautiful React apps. Maintained by Douyin-fe team.

131 lines 4.36 kB
import _isNull from "lodash/isNull"; import _set from "lodash/set"; import _get from "lodash/get"; var __rest = this && this.__rest || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React, { PureComponent, isValidElement } from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import { cssClasses, strings } from '@douyinfe/semi-foundation/lib/es/table/constants'; import { arrayAdd, filterColumns } from '@douyinfe/semi-foundation/lib/es/table/utils'; import TableContext from '../table-context'; import TableRow from './BaseRow'; import { amendTableWidth } from '../utils'; /** * Render expanded row */ export default class TableExpandedRow extends PureComponent { render() { const { record, columns: propColumns = [], prefixCls, className, expanded, expandedRowRender, renderExpandIcon, index, store, components, style, virtualized, indentSize, cellWidths, displayNone } = this.props; const { tableWidth, anyColumnFixed, getCellWidths } = this.context; const cell = expandedRowRender(record, index, expanded); let children = null; const props = {}; let column = {}; if (_isNull(cell)) { return null; } else if (/*#__PURE__*/isValidElement(cell)) { children = cell; } else if (cell && Object.prototype.toString.call(cell) === '[object Object]') { const _a = cell, { children: cellChildren, fixed } = _a, restProps = __rest(_a, ["children", "fixed"]); children = cellChildren; column = Object.assign({}, restProps); } if (_get(components, 'body.cell') !== strings.DEFAULT_COMPONENTS.body.cell) { if (virtualized) { _set(props, 'style.height', '100%'); } _set(props, 'style.display', 'block'); _set(props, 'style.width', arrayAdd(cellWidths, 0, propColumns.length)); } else { // Remove the row where the scroll bar is located props.colSpan = filterColumns(propColumns).length; } const columns = [Object.assign({ render: () => ({ props, children: (/*#__PURE__*/React.createElement("div", { className: classnames(`${prefixCls}-expand-inner`), style: { width: anyColumnFixed ? amendTableWidth(tableWidth) : undefined } }, children)) }) }, column)]; const rowCls = classnames(className, `${prefixCls}-row-expand`); const baseRowCellWidths = getCellWidths(columns); return /*#__PURE__*/React.createElement(TableRow, { style: style, components: components, className: rowCls, expandedRow: true, renderExpandIcon: renderExpandIcon, rowKey: `${record.key}-expanded-row`, columns: columns, store: store, virtualized: virtualized, indentSize: indentSize, cellWidths: baseRowCellWidths, displayNone: displayNone }); } } TableExpandedRow.contextType = TableContext; TableExpandedRow.propTypes = { cellWidths: PropTypes.array.isRequired, className: PropTypes.string, columns: PropTypes.array, components: PropTypes.object, defaultExpandAllRows: PropTypes.bool, defaultExpandedRowKeys: PropTypes.array, expandIcon: PropTypes.oneOfType([PropTypes.object, PropTypes.node, PropTypes.func]), expandRowByClick: PropTypes.bool, expanded: PropTypes.bool, expandedRowKeys: PropTypes.array, expandedRowRender: PropTypes.func, indentSize: PropTypes.number, index: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), onExpand: PropTypes.func, onExpandedRowsChange: PropTypes.func, prefixCls: PropTypes.string, record: PropTypes.object, renderExpandIcon: PropTypes.func, store: PropTypes.object, style: PropTypes.object, virtualized: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]) }; TableExpandedRow.defaultProps = { record: {}, prefixCls: cssClasses.PREFIX };