2020-02-23 20:48:16 +08:00
|
|
|
import * as React from 'react';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { DescriptionsContextProps } from '.';
|
|
|
|
import { DescriptionsContext } from '.';
|
2022-06-22 14:57:09 +08:00
|
|
|
import Cell from './Cell';
|
|
|
|
import type { DescriptionsItemProps } from './Item';
|
2020-02-23 20:48:16 +08:00
|
|
|
|
|
|
|
interface CellConfig {
|
|
|
|
component: string | [string, string];
|
|
|
|
type: string;
|
|
|
|
showLabel?: boolean;
|
|
|
|
showContent?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderCells(
|
|
|
|
items: React.ReactElement<DescriptionsItemProps>[],
|
|
|
|
{ colon, prefixCls, bordered }: RowProps,
|
2020-12-30 17:08:43 +08:00
|
|
|
{
|
|
|
|
component,
|
|
|
|
type,
|
|
|
|
showLabel,
|
|
|
|
showContent,
|
|
|
|
labelStyle: rootLabelStyle,
|
|
|
|
contentStyle: rootContentStyle,
|
|
|
|
}: CellConfig & DescriptionsContextProps,
|
2020-02-23 20:48:16 +08:00
|
|
|
) {
|
|
|
|
return items.map(
|
|
|
|
(
|
|
|
|
{
|
|
|
|
props: {
|
|
|
|
label,
|
|
|
|
children,
|
|
|
|
prefixCls: itemPrefixCls = prefixCls,
|
|
|
|
className,
|
|
|
|
style,
|
2020-11-20 13:41:58 +08:00
|
|
|
labelStyle,
|
|
|
|
contentStyle,
|
2020-02-23 20:48:16 +08:00
|
|
|
span = 1,
|
|
|
|
},
|
|
|
|
key,
|
|
|
|
},
|
|
|
|
index,
|
|
|
|
) => {
|
|
|
|
if (typeof component === 'string') {
|
|
|
|
return (
|
|
|
|
<Cell
|
|
|
|
key={`${type}-${key || index}`}
|
|
|
|
className={className}
|
|
|
|
style={style}
|
2020-12-30 17:08:43 +08:00
|
|
|
labelStyle={{ ...rootLabelStyle, ...labelStyle }}
|
|
|
|
contentStyle={{ ...rootContentStyle, ...contentStyle }}
|
2020-02-23 20:48:16 +08:00
|
|
|
span={span}
|
|
|
|
colon={colon}
|
|
|
|
component={component}
|
|
|
|
itemPrefixCls={itemPrefixCls}
|
|
|
|
bordered={bordered}
|
|
|
|
label={showLabel ? label : null}
|
|
|
|
content={showContent ? children : null}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-02-28 21:47:29 +08:00
|
|
|
return [
|
|
|
|
<Cell
|
|
|
|
key={`label-${key || index}`}
|
|
|
|
className={className}
|
2020-12-30 17:08:43 +08:00
|
|
|
style={{ ...rootLabelStyle, ...style, ...labelStyle }}
|
2020-02-28 21:47:29 +08:00
|
|
|
span={1}
|
|
|
|
colon={colon}
|
|
|
|
component={component[0]}
|
|
|
|
itemPrefixCls={itemPrefixCls}
|
|
|
|
bordered={bordered}
|
|
|
|
label={label}
|
|
|
|
/>,
|
|
|
|
<Cell
|
|
|
|
key={`content-${key || index}`}
|
|
|
|
className={className}
|
2020-12-30 17:08:43 +08:00
|
|
|
style={{ ...rootContentStyle, ...style, ...contentStyle }}
|
2020-02-28 21:47:29 +08:00
|
|
|
span={span * 2 - 1}
|
|
|
|
component={component[1]}
|
|
|
|
itemPrefixCls={itemPrefixCls}
|
|
|
|
bordered={bordered}
|
|
|
|
content={children}
|
|
|
|
/>,
|
|
|
|
];
|
2020-02-23 20:48:16 +08:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RowProps {
|
|
|
|
prefixCls: string;
|
|
|
|
vertical: boolean;
|
2020-02-28 21:47:29 +08:00
|
|
|
row: React.ReactElement<DescriptionsItemProps>[];
|
2020-02-23 20:48:16 +08:00
|
|
|
bordered?: boolean;
|
|
|
|
colon: boolean;
|
|
|
|
index: number;
|
2022-04-18 18:39:23 +08:00
|
|
|
children?: React.ReactNode;
|
2020-02-23 20:48:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const Row: React.FC<RowProps> = props => {
|
2020-12-30 17:08:43 +08:00
|
|
|
const descContext = React.useContext(DescriptionsContext);
|
|
|
|
|
2020-02-28 21:47:29 +08:00
|
|
|
const { prefixCls, vertical, row, index, bordered } = props;
|
2020-02-23 20:48:16 +08:00
|
|
|
if (vertical) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<tr key={`label-${index}`} className={`${prefixCls}-row`}>
|
2020-12-30 17:08:43 +08:00
|
|
|
{renderCells(row, props, {
|
|
|
|
component: 'th',
|
|
|
|
type: 'label',
|
|
|
|
showLabel: true,
|
|
|
|
...descContext,
|
|
|
|
})}
|
2020-02-23 20:48:16 +08:00
|
|
|
</tr>
|
|
|
|
<tr key={`content-${index}`} className={`${prefixCls}-row`}>
|
2020-02-28 21:47:29 +08:00
|
|
|
{renderCells(row, props, {
|
2020-02-23 20:48:16 +08:00
|
|
|
component: 'td',
|
|
|
|
type: 'content',
|
|
|
|
showContent: true,
|
2020-12-30 17:08:43 +08:00
|
|
|
...descContext,
|
2020-02-23 20:48:16 +08:00
|
|
|
})}
|
|
|
|
</tr>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<tr key={index} className={`${prefixCls}-row`}>
|
2020-02-28 21:47:29 +08:00
|
|
|
{renderCells(row, props, {
|
2020-02-23 20:48:16 +08:00
|
|
|
component: bordered ? ['th', 'td'] : 'td',
|
|
|
|
type: 'item',
|
|
|
|
showLabel: true,
|
|
|
|
showContent: true,
|
2020-12-30 17:08:43 +08:00
|
|
|
...descContext,
|
2020-02-23 20:48:16 +08:00
|
|
|
})}
|
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Row;
|