import * as React from 'react'; import type { DescriptionsItemType } from '.'; import Cell from './Cell'; import type { DescriptionsContextProps } from './DescriptionsContext'; import DescriptionsContext from './DescriptionsContext'; interface CellConfig { component: string | [string, string]; type: string; showLabel?: boolean; showContent?: boolean; } function renderCells( items: DescriptionsItemType[], { colon, prefixCls, bordered }: RowProps, { component, type, showLabel, showContent, labelStyle: rootLabelStyle, contentStyle: rootContentStyle, }: CellConfig & DescriptionsContextProps, ) { return items.map( ( { 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: DescriptionsItemType[]; 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;