forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCol.jsx
84 lines (78 loc) · 2.2 KB
/
Col.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import PropTypes from '../_util/vue-types';
import { getOptionProps } from '../_util/props-util';
// eslint-disable-next-line no-unused-vars
const ColProps = {
child: PropTypes.any,
bordered: PropTypes.bool,
colon: PropTypes.bool,
type: PropTypes.oneOf(['label', 'content']),
layout: PropTypes.oneOf(['horizontal', 'vertical']),
};
const Col = (_, { attrs }) => {
// props: {
// child: PropTypes.any,
// bordered: PropTypes.bool,
// colon: PropTypes.bool,
// type: PropTypes.oneOf(['label', 'content']),
// layout: PropTypes.oneOf(['horizontal', 'vertical']),
// }
const { child, bordered, colon, type, layout } = attrs;
const { prefixCls, span = 1 } = getOptionProps(child);
const { key, children = {} } = child || {};
const label = children.label && children.label();
const defaultSlot = children.default && children.default();
const someLabelProps = {
attrs: {},
class: [
`${prefixCls}-item-label`,
{
[`${prefixCls}-item-colon`]: colon,
[`${prefixCls}-item-no-label`]: !label,
},
],
key: `${key}-label`,
};
if (layout === 'vertical') {
someLabelProps.attrs.colSpan = span * 2 - 1;
}
if (bordered) {
if (type === 'label') {
return <th {...someLabelProps}>{label}</th>;
}
return (
<td class={`${prefixCls}-item-content`} key={`${key}-content`} colSpan={span * 2 - 1}>
{defaultSlot}
</td>
);
}
if (layout === 'vertical') {
if (type === 'content') {
return (
<td colSpan={span} class={`${prefixCls}-item`}>
<span class={`${prefixCls}-item-content`} key={`${key}-content`}>
{defaultSlot}
</span>
</td>
);
}
return (
<td colSpan={span} class={`${prefixCls}-item`}>
<span
class={[`${prefixCls}-item-label`, { [`${prefixCls}-item-colon`]: colon }]}
key={`${key}-label`}
>
{label}
</span>
</td>
);
}
return (
<td colSpan={span} class={`${prefixCls}-item`}>
<span {...someLabelProps}>{label}</span>
<span class={`${prefixCls}-item-content`} key={`${key}-content`}>
{defaultSlot}
</span>
</td>
);
};
export default Col;