import * as React from 'react'; import { DescriptionsItemProps } from './Item'; import Cell from './Cell'; 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 }: CellConfig, ) { 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; } const Row: React.FC = props => { const { prefixCls, vertical, row, index, bordered } = props; if (vertical) { return ( <> {renderCells(row, props, { component: 'th', type: 'label', showLabel: true })} {renderCells(row, props, { component: 'td', type: 'content', showContent: true, })} ); } return ( {renderCells(row, props, { component: bordered ? ['th', 'td'] : 'td', type: 'item', showLabel: true, showContent: true, })} ); }; export default Row;