forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadingIcon.tsx
69 lines (69 loc) · 1.79 KB
/
LoadingIcon.tsx
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
import { defineComponent, nextTick } from 'vue';
import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined';
import Transition from '../_util/transition';
const getCollapsedWidth = (node: HTMLSpanElement) => {
if (node) {
node.style.width = '0px';
node.style.opacity = '0';
node.style.transform = 'scale(0)';
}
};
const getRealWidth = (node: HTMLSpanElement) => {
nextTick(() => {
if (node) {
node.style.width = `${node.scrollWidth}px`;
node.style.opacity = '1';
node.style.transform = 'scale(1)';
}
});
};
const resetStyle = (node: HTMLSpanElement) => {
if (node && node.style) {
node.style.width = null;
node.style.opacity = null;
node.style.transform = null;
}
};
export default defineComponent({
compatConfig: { MODE: 3 },
name: 'LoadingIcon',
props: {
prefixCls: String,
loading: [Boolean, Object],
existIcon: Boolean,
},
setup(props) {
return () => {
const { existIcon, prefixCls, loading } = props;
if (existIcon) {
return (
<span class={`${prefixCls}-loading-icon`}>
<LoadingOutlined />
</span>
);
}
const visible = !!loading;
return (
<Transition
name={`${prefixCls}-loading-icon-motion`}
onBeforeEnter={getCollapsedWidth}
onEnter={getRealWidth}
onAfterEnter={resetStyle}
onBeforeLeave={getRealWidth}
onLeave={(node: HTMLSpanElement) => {
setTimeout(() => {
getCollapsedWidth(node);
});
}}
onAfterLeave={resetStyle}
>
{visible ? (
<span class={`${prefixCls}-loading-icon`}>
<LoadingOutlined />
</span>
) : null}
</Transition>
);
};
},
});