2020-02-23 20:48:16 +08:00
|
|
|
import * as React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
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;
|
|
|
|
bordered?: boolean;
|
|
|
|
label?: React.ReactNode;
|
|
|
|
content?: React.ReactNode;
|
|
|
|
colon?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Cell: React.FC<CellProps> = ({
|
|
|
|
itemPrefixCls,
|
|
|
|
component,
|
|
|
|
span,
|
|
|
|
className,
|
|
|
|
style,
|
|
|
|
bordered,
|
|
|
|
label,
|
|
|
|
content,
|
|
|
|
colon,
|
|
|
|
}) => {
|
|
|
|
const Component = component as any;
|
|
|
|
|
|
|
|
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}
|
|
|
|
>
|
2020-03-05 17:54:58 +08:00
|
|
|
{notEmpty(label) ? label : content}
|
2020-02-23 20:48:16 +08:00
|
|
|
</Component>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Component
|
|
|
|
className={classNames(`${itemPrefixCls}-item`, className)}
|
|
|
|
style={style}
|
|
|
|
colSpan={span}
|
|
|
|
>
|
|
|
|
{label && (
|
|
|
|
<span
|
|
|
|
className={classNames(`${itemPrefixCls}-item-label`, {
|
2020-02-24 16:57:39 +08:00
|
|
|
[`${itemPrefixCls}-item-colon`]: colon,
|
2020-02-23 20:48:16 +08:00
|
|
|
})}
|
|
|
|
>
|
|
|
|
{label}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
{content && <span className={classNames(`${itemPrefixCls}-item-content`)}>{content}</span>}
|
|
|
|
</Component>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Cell;
|