mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-15 17:31:25 +08:00
093a458026
* feat: Support label & content style of Desc * test: Update snasphot * docs: fix desc
83 lines
1.7 KiB
TypeScript
83 lines
1.7 KiB
TypeScript
import * as React from 'react';
|
|
import classNames from 'classnames';
|
|
|
|
function notEmpty(val: any) {
|
|
return val !== undefined && val !== null;
|
|
}
|
|
|
|
export interface CellProps {
|
|
itemPrefixCls: string;
|
|
span: number;
|
|
className?: string;
|
|
component: string;
|
|
style?: React.CSSProperties;
|
|
labelStyle?: React.CSSProperties;
|
|
contentStyle?: React.CSSProperties;
|
|
bordered?: boolean;
|
|
label?: React.ReactNode;
|
|
content?: React.ReactNode;
|
|
colon?: boolean;
|
|
}
|
|
|
|
const Cell: React.FC<CellProps> = ({
|
|
itemPrefixCls,
|
|
component,
|
|
span,
|
|
className,
|
|
style,
|
|
labelStyle,
|
|
contentStyle,
|
|
bordered,
|
|
label,
|
|
content,
|
|
colon,
|
|
}) => {
|
|
const Component = component as any;
|
|
|
|
if (bordered) {
|
|
return (
|
|
<Component
|
|
className={classNames(
|
|
{
|
|
[`${itemPrefixCls}-item-label`]: notEmpty(label),
|
|
[`${itemPrefixCls}-item-content`]: notEmpty(content),
|
|
},
|
|
className,
|
|
)}
|
|
style={style}
|
|
colSpan={span}
|
|
>
|
|
{notEmpty(label) ? label : content}
|
|
</Component>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Component
|
|
className={classNames(`${itemPrefixCls}-item`, className)}
|
|
style={style}
|
|
colSpan={span}
|
|
>
|
|
<div className={`${itemPrefixCls}-item-container`}>
|
|
{label && (
|
|
<span
|
|
className={classNames(`${itemPrefixCls}-item-label`, {
|
|
[`${itemPrefixCls}-item-no-colon`]: !colon,
|
|
})}
|
|
style={labelStyle}
|
|
>
|
|
{label}
|
|
</span>
|
|
)}
|
|
{content && (
|
|
<span className={classNames(`${itemPrefixCls}-item-content`)} style={contentStyle}>
|
|
{content}
|
|
</span>
|
|
)}
|
|
</div>
|
|
</Component>
|
|
);
|
|
};
|
|
|
|
export default Cell;
|