2020-10-14 09:57:38 +00:00
|
|
|
import { SetupContext, VNode } from 'vue';
|
2020-06-11 14:35:09 +00:00
|
|
|
import { getOptionProps } from '../_util/props-util';
|
2020-03-07 11:45:13 +00:00
|
|
|
|
2020-10-14 09:57:38 +00:00
|
|
|
interface ColProps {
|
|
|
|
child: VNode;
|
|
|
|
bordered: boolean;
|
|
|
|
colon: boolean;
|
|
|
|
type?: 'label' | 'content';
|
|
|
|
layout?: 'horizontal' | 'vertical';
|
2020-10-19 08:43:10 +00:00
|
|
|
colKey?: string;
|
2020-10-14 09:57:38 +00:00
|
|
|
}
|
|
|
|
const Col = (_props: ColProps, { attrs }: SetupContext) => {
|
2020-10-19 08:43:10 +00:00
|
|
|
const {
|
|
|
|
child = {} as VNode,
|
|
|
|
bordered,
|
|
|
|
colon,
|
|
|
|
type,
|
|
|
|
layout,
|
|
|
|
colKey: key,
|
|
|
|
} = (attrs as unknown) as ColProps;
|
2020-06-11 14:35:09 +00:00
|
|
|
const { prefixCls, span = 1 } = getOptionProps(child);
|
2020-10-14 09:57:38 +00:00
|
|
|
const { children = {} as any, props = {} } = child;
|
2020-07-29 09:05:59 +00:00
|
|
|
const label = props.label || (children.label && children.label());
|
2020-06-11 14:35:09 +00:00
|
|
|
const defaultSlot = children.default && children.default();
|
2020-03-07 11:45:13 +00:00
|
|
|
|
2020-10-14 09:57:38 +00:00
|
|
|
const labelProps: any = {
|
2020-06-11 14:35:09 +00:00
|
|
|
class: [
|
|
|
|
`${prefixCls}-item-label`,
|
|
|
|
{
|
|
|
|
[`${prefixCls}-item-colon`]: colon,
|
|
|
|
[`${prefixCls}-item-no-label`]: !label,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
key: `${key}-label`,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (layout === 'vertical') {
|
2020-07-29 09:05:59 +00:00
|
|
|
labelProps.colspan = span * 2 - 1;
|
2020-06-11 14:35:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bordered) {
|
|
|
|
if (type === 'label') {
|
2020-06-11 15:07:48 +00:00
|
|
|
return <th {...labelProps}>{label}</th>;
|
2020-03-07 11:45:13 +00:00
|
|
|
}
|
2020-06-11 14:35:09 +00:00
|
|
|
return (
|
2020-07-29 09:05:59 +00:00
|
|
|
<td class={`${prefixCls}-item-content`} key={`${key}-content`} colspan={span * 2 - 1}>
|
2020-06-11 14:35:09 +00:00
|
|
|
{defaultSlot}
|
|
|
|
</td>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (layout === 'vertical') {
|
|
|
|
if (type === 'content') {
|
2020-03-07 11:45:13 +00:00
|
|
|
return (
|
2020-07-29 09:05:59 +00:00
|
|
|
<td colspan={span} class={`${prefixCls}-item`}>
|
2020-06-11 14:35:09 +00:00
|
|
|
<span class={`${prefixCls}-item-content`} key={`${key}-content`}>
|
|
|
|
{defaultSlot}
|
2020-03-07 11:45:13 +00:00
|
|
|
</span>
|
|
|
|
</td>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return (
|
2020-07-29 09:05:59 +00:00
|
|
|
<td colspan={span} class={`${prefixCls}-item`}>
|
2020-06-11 14:35:09 +00:00
|
|
|
<span
|
|
|
|
class={[`${prefixCls}-item-label`, { [`${prefixCls}-item-colon`]: colon }]}
|
|
|
|
key={`${key}-label`}
|
|
|
|
>
|
|
|
|
{label}
|
2020-03-07 11:45:13 +00:00
|
|
|
</span>
|
|
|
|
</td>
|
|
|
|
);
|
2020-06-11 14:35:09 +00:00
|
|
|
}
|
|
|
|
return (
|
2020-07-29 09:05:59 +00:00
|
|
|
<td colspan={span} class={`${prefixCls}-item`}>
|
2020-06-11 15:07:48 +00:00
|
|
|
<span {...labelProps}>{label}</span>
|
2020-06-11 14:35:09 +00:00
|
|
|
<span class={`${prefixCls}-item-content`} key={`${key}-content`}>
|
|
|
|
{defaultSlot}
|
|
|
|
</span>
|
|
|
|
</td>
|
|
|
|
);
|
2020-03-07 11:45:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Col;
|