2021-06-26 01:35:40 +00:00
|
|
|
import type { VNodeTypes, HTMLAttributes, FunctionalComponent, CSSProperties } from 'vue';
|
2020-11-02 08:53:56 +00:00
|
|
|
|
|
|
|
function notEmpty(val: any) {
|
|
|
|
return val !== undefined && val !== null;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface CellProps extends HTMLAttributes {
|
|
|
|
itemPrefixCls: string;
|
|
|
|
span: number;
|
|
|
|
component: string;
|
2021-06-18 09:45:29 +00:00
|
|
|
labelStyle?: CSSProperties;
|
|
|
|
contentStyle?: CSSProperties;
|
2020-11-02 08:53:56 +00:00
|
|
|
bordered?: boolean;
|
|
|
|
label?: VNodeTypes;
|
|
|
|
content?: VNodeTypes;
|
|
|
|
colon?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Cell: FunctionalComponent<CellProps> = props => {
|
2021-06-18 09:45:29 +00:00
|
|
|
const {
|
|
|
|
itemPrefixCls,
|
|
|
|
component,
|
|
|
|
span,
|
|
|
|
labelStyle,
|
|
|
|
contentStyle,
|
|
|
|
bordered,
|
|
|
|
label,
|
|
|
|
content,
|
|
|
|
colon,
|
|
|
|
} = props;
|
2020-11-02 08:53:56 +00:00
|
|
|
const Component = component as any;
|
|
|
|
if (bordered) {
|
|
|
|
return (
|
|
|
|
<Component
|
|
|
|
class={[
|
|
|
|
{
|
|
|
|
[`${itemPrefixCls}-item-label`]: notEmpty(label),
|
|
|
|
[`${itemPrefixCls}-item-content`]: notEmpty(content),
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
colSpan={span}
|
|
|
|
>
|
2021-06-18 09:45:29 +00:00
|
|
|
{notEmpty(label) && <span style={labelStyle}>{label}</span>}
|
|
|
|
{notEmpty(content) && <span style={contentStyle}>{content}</span>}
|
2020-11-02 08:53:56 +00:00
|
|
|
</Component>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Component class={[`${itemPrefixCls}-item`]} colSpan={span}>
|
2021-06-18 09:45:29 +00:00
|
|
|
<div class={`${itemPrefixCls}-item-container`}>
|
|
|
|
{label && (
|
|
|
|
<span
|
|
|
|
class={[
|
|
|
|
`${itemPrefixCls}-item-label`,
|
|
|
|
{
|
|
|
|
[`${itemPrefixCls}-item-no-colon`]: !colon,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
style={labelStyle}
|
|
|
|
>
|
|
|
|
{label}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
{content && (
|
|
|
|
<span class={`${itemPrefixCls}-item-content`} style={contentStyle}>
|
|
|
|
{content}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</div>
|
2020-11-02 08:53:56 +00:00
|
|
|
</Component>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Cell;
|