import { useContext } from '@rc-component/context'; import { clsx } from 'clsx'; import * as React from 'react'; import Cell from '../Cell'; import TableContext, { responseImmutable } from '../context/TableContext'; import type { FlattenData } from '../hooks/useFlattenRecords'; import useRowInfo from '../hooks/useRowInfo'; import VirtualCell from './VirtualCell'; import { StaticContext } from './context'; import { computedExpandedClassName } from '../utils/expandUtil'; export interface BodyLineProps { data: FlattenData; index: number; className?: string; style?: React.CSSProperties; rowKey: React.Key; /** Render cell only when it has `rowSpan > 1` */ extra?: boolean; getHeight?: (rowSpan: number) => number; } const BodyLine = React.forwardRef((props, ref) => { const { data, index, className, rowKey, style, extra, getHeight, ...restProps } = props; const { record, indent, index: renderIndex } = data; const { scrollX, flattenColumns, prefixCls, fixColumn, componentWidth, classNames, styles } = useContext(TableContext, [ 'prefixCls', 'flattenColumns', 'fixColumn', 'componentWidth', 'scrollX', 'classNames', 'styles', ]); const { getComponent } = useContext(StaticContext, ['getComponent']); const rowInfo = useRowInfo(record, rowKey, index, indent); const RowComponent = getComponent(['body', 'row'], 'div'); const cellComponent = getComponent(['body', 'cell'], 'div'); // ========================== Expand ========================== const { rowSupportExpand, expanded, rowProps, expandedRowRender, expandedRowClassName, forceRender, } = rowInfo; const expandedClsName = computedExpandedClassName(expandedRowClassName, record, index, indent); let expandRowNode: React.ReactElement; if (!extra && rowSupportExpand && (forceRender || expanded)) { const expandContent = expandedRowRender(record, index, indent + 1, expanded); let additionalProps: React.TdHTMLAttributes = {}; if (fixColumn) { additionalProps = { style: { ['--virtual-width' as any]: `${componentWidth}px`, }, }; } const rowCellCls = `${prefixCls}-expanded-row-cell`; expandRowNode = ( {expandContent} ); } // ========================== Render ========================== const rowStyle: React.CSSProperties = { ...style, width: scrollX as number, }; if (extra) { rowStyle.position = 'absolute'; rowStyle.pointerEvents = 'none'; } const rowNode = ( = 1, [`${prefixCls}-row-extra`]: extra, })} style={{ ...rowStyle, ...rowProps?.style, ...styles?.body?.row }} > {flattenColumns.map((column, colIndex) => { return ( ); })} ); if (rowSupportExpand) { return (
{rowNode} {expandRowNode}
); } return rowNode; }); const ResponseBodyLine = responseImmutable(BodyLine); if (process.env.NODE_ENV !== 'production') { ResponseBodyLine.displayName = 'BodyLine'; } export default ResponseBodyLine;