import * as React from 'react'; import Cell from './Cell'; import type { DescriptionsContextProps } from './DescriptionsContext'; import DescriptionsContext from './DescriptionsContext'; import type { DescriptionsItemProps } from './Item'; interface CellConfig { component: string | [string, string]; type: string; showLabel?: boolean; showContent?: boolean; } function renderCells( items: React.ReactElement[], { colon, prefixCls, bordered }: RowProps, { component, type, showLabel, showContent, labelStyle: rootLabelStyle, contentStyle: rootContentStyle, }: CellConfig & DescriptionsContextProps, ) { return items.map( ( { props: { label, children, prefixCls: itemPrefixCls = prefixCls, className, style, labelStyle, contentStyle, span = 1, }, key, }, index, ) => { if (typeof component === 'string') { return ( ); } return [ , , ]; }, ); } export interface RowProps { prefixCls: string; vertical: boolean; row: React.ReactElement[]; bordered?: boolean; colon: boolean; index: number; children?: React.ReactNode; } const Row: React.FC = (props) => { const descContext = React.useContext(DescriptionsContext); const { prefixCls, vertical, row, index, bordered } = props; if (vertical) { return ( <> {renderCells(row, props, { component: 'th', type: 'label', showLabel: true, ...descContext, })} {renderCells(row, props, { component: 'td', type: 'content', showContent: true, ...descContext, })} ); } return ( {renderCells(row, props, { component: bordered ? ['th', 'td'] : 'td', type: 'item', showLabel: true, showContent: true, ...descContext, })} ); }; export default Row;