forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.jsx
95 lines (83 loc) · 2.44 KB
/
index.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
85
86
87
88
89
90
91
92
93
94
95
import PropTypes from '../_util/vue-types';
import { filterEmpty, initDefaultProps } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider';
export const SpaceSizeType = PropTypes.oneOfType([
PropTypes.number,
PropTypes.oneOf(['small', 'middle', 'large']),
]);
const spaceSize = {
small: 8,
middle: 16,
large: 24,
};
export const SpaceProps = {
prefixCls: PropTypes.string,
size: SpaceSizeType,
direction: PropTypes.oneOf(['horizontal', 'vertical']),
align: PropTypes.oneOf(['start', 'end', 'center', 'baseline']),
};
const Space = {
functional: true,
name: 'ASpace',
props: initDefaultProps(SpaceProps, {
size: 'small',
direction: 'horizontal',
}),
inject: {
configProvider: { default: () => ConfigConsumerProps },
},
render(h, content) {
const {
prefixCls: customizePrefixCls,
injections: { configProvider },
children,
} = content;
const { align, size, direction } = content.props;
const getPrefixCls = configProvider.getPrefixCls;
const prefixCls = getPrefixCls('space', customizePrefixCls);
const items = filterEmpty(children);
const len = items.length;
if (len === 0) {
return null;
}
const mergedAlign = align === undefined && direction === 'horizontal' ? 'center' : align;
const someSpaceClass = [
{
[prefixCls]: true,
[`${prefixCls}-${direction}`]: true,
// [`${prefixCls}-rtl`]: directionConfig === 'rtl',
[`${prefixCls}-align-${mergedAlign}`]: mergedAlign,
},
];
if (content.data.class) {
someSpaceClass.push(content.data.class);
}
const itemClassName = `${prefixCls}-item`;
const marginDirection = 'marginRight'; // directionConfig === 'rtl' ? 'marginLeft' : 'marginRight';
return (
<div {...content.data} class={someSpaceClass}>
{items.map((child, i) => (
<div
class={itemClassName}
key={`${itemClassName}-${i}`}
style={
i === len - 1
? {}
: {
[direction === 'vertical' ? 'marginBottom' : marginDirection]:
typeof size === 'string' ? `${spaceSize[size]}px` : `${size}px`,
}
}
>
{child}
</div>
))}
</div>
);
},
};
/* istanbul ignore next */
Space.install = function(Vue) {
Vue.component(Space.name, Space);
};
export default Space;