2020-02-23 20:48:16 +08:00
|
|
|
import classNames from 'classnames';
|
2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
2020-02-23 20:48:16 +08:00
|
|
|
|
2020-03-05 17:54:58 +08:00
|
|
|
function notEmpty(val: any) {
|
|
|
|
return val !== undefined && val !== null;
|
|
|
|
}
|
|
|
|
|
2020-02-23 20:48:16 +08:00
|
|
|
export interface CellProps {
|
|
|
|
itemPrefixCls: string;
|
|
|
|
span: number;
|
|
|
|
className?: string;
|
|
|
|
component: string;
|
|
|
|
style?: React.CSSProperties;
|
2020-11-20 13:41:58 +08:00
|
|
|
labelStyle?: React.CSSProperties;
|
|
|
|
contentStyle?: React.CSSProperties;
|
2020-02-23 20:48:16 +08:00
|
|
|
bordered?: boolean;
|
|
|
|
label?: React.ReactNode;
|
|
|
|
content?: React.ReactNode;
|
|
|
|
colon?: boolean;
|
|
|
|
}
|
|
|
|
|
2023-07-09 13:34:59 +08:00
|
|
|
const Cell: React.FC<CellProps> = (props) => {
|
|
|
|
const {
|
|
|
|
itemPrefixCls,
|
|
|
|
component,
|
|
|
|
span,
|
|
|
|
className,
|
|
|
|
style,
|
|
|
|
labelStyle,
|
|
|
|
contentStyle,
|
|
|
|
bordered,
|
|
|
|
label,
|
|
|
|
content,
|
|
|
|
colon,
|
|
|
|
} = props;
|
2023-08-03 12:18:57 +08:00
|
|
|
|
|
|
|
const Component = component as keyof JSX.IntrinsicElements;
|
2020-02-23 20:48:16 +08:00
|
|
|
|
|
|
|
if (bordered) {
|
|
|
|
return (
|
|
|
|
<Component
|
|
|
|
className={classNames(
|
|
|
|
{
|
2020-03-05 17:54:58 +08:00
|
|
|
[`${itemPrefixCls}-item-label`]: notEmpty(label),
|
|
|
|
[`${itemPrefixCls}-item-content`]: notEmpty(content),
|
2020-02-23 20:48:16 +08:00
|
|
|
},
|
|
|
|
className,
|
|
|
|
)}
|
|
|
|
style={style}
|
|
|
|
colSpan={span}
|
|
|
|
>
|
2021-03-30 17:38:50 +08:00
|
|
|
{notEmpty(label) && <span style={labelStyle}>{label}</span>}
|
|
|
|
{notEmpty(content) && <span style={contentStyle}>{content}</span>}
|
2020-02-23 20:48:16 +08:00
|
|
|
</Component>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Component
|
|
|
|
className={classNames(`${itemPrefixCls}-item`, className)}
|
|
|
|
style={style}
|
|
|
|
colSpan={span}
|
|
|
|
>
|
2020-08-06 14:32:13 +08:00
|
|
|
<div className={`${itemPrefixCls}-item-container`}>
|
2022-03-25 09:38:55 +08:00
|
|
|
{(label || label === 0) && (
|
2020-08-06 14:32:13 +08:00
|
|
|
<span
|
|
|
|
className={classNames(`${itemPrefixCls}-item-label`, {
|
|
|
|
[`${itemPrefixCls}-item-no-colon`]: !colon,
|
|
|
|
})}
|
2020-11-20 13:41:58 +08:00
|
|
|
style={labelStyle}
|
2020-08-06 14:32:13 +08:00
|
|
|
>
|
|
|
|
{label}
|
|
|
|
</span>
|
|
|
|
)}
|
2022-03-25 09:38:55 +08:00
|
|
|
{(content || content === 0) && (
|
2020-11-20 13:41:58 +08:00
|
|
|
<span className={classNames(`${itemPrefixCls}-item-content`)} style={contentStyle}>
|
|
|
|
{content}
|
|
|
|
</span>
|
|
|
|
)}
|
2020-08-06 14:32:13 +08:00
|
|
|
</div>
|
2020-02-23 20:48:16 +08:00
|
|
|
</Component>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Cell;
|