Skip to content

Commit 404ea7d

Browse files
committed
move spinner to own component
1 parent 37ba916 commit 404ea7d

File tree

2 files changed

+87
-69
lines changed

2 files changed

+87
-69
lines changed

src/components/InfiniteLoading.vue

Lines changed: 6 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<template>
22
<div class="infinite-loading-container">
33
<div v-show="isLoading">
4-
<slot name="spinner">
5-
<component :is="spinnerView"></component>
6-
</slot>
4+
<spinner :spinner="spinner" />
75
</div>
86
<div class="infinite-status-prompt" v-show="isNoResults">
97
<slot name="no-results">No results :(</slot>
@@ -15,71 +13,10 @@
1513
</template>
1614
<script>
1715
/* eslint-disable no-console */
16+
import Spinner from './Spinner';
1817
1918
const LOOP_CHECK_TIMEOUT = 1000; // the timeout for check infinite loop
2019
const LOOP_CHECK_MAX_CALLS = 10; // the maximum number of continuous calls
21-
const SPINNERS = {
22-
BUBBLES: {
23-
render(createElement) {
24-
return createElement('span', {
25-
attrs: {
26-
class: 'loading-bubbles',
27-
},
28-
}, Array.apply(Array, Array(8)).map(() => createElement('span', {
29-
attrs: {
30-
class: 'bubble-item',
31-
},
32-
})),
33-
);
34-
},
35-
},
36-
CIRCLES: {
37-
render(createElement) {
38-
return createElement('span', {
39-
attrs: {
40-
class: 'loading-circles',
41-
},
42-
}, Array.apply(Array, Array(8)).map(() => createElement('span', {
43-
attrs: {
44-
class: 'circle-item',
45-
},
46-
})),
47-
);
48-
},
49-
},
50-
DEFAULT: {
51-
render(createElement) {
52-
return createElement('i', {
53-
attrs: {
54-
class: 'loading-default',
55-
},
56-
});
57-
},
58-
},
59-
SPIRAL: {
60-
render(createElement) {
61-
return createElement('i', {
62-
attrs: {
63-
class: 'loading-spiral',
64-
},
65-
});
66-
},
67-
},
68-
WAVEDOTS: {
69-
render(createElement) {
70-
return createElement('span', {
71-
attrs: {
72-
class: 'loading-wave-dots',
73-
},
74-
}, Array.apply(Array, Array(5)).map(() => createElement('span', {
75-
attrs: {
76-
class: 'wave-item',
77-
},
78-
})),
79-
);
80-
},
81-
},
82-
};
8320
const WARNINGS = {
8421
STATE_CHANGER: [
8522
'[Vue-infinite-loading warn]: emit `loaded` and `complete` event through component instance of `$refs` may cause error, so it will be deprecated soon, please use the `$state` argument instead (`$state` just the special `$event` variable):',
@@ -134,10 +71,10 @@
13471
continuousCallTimes: 0,
13572
};
13673
},
74+
components: {
75+
Spinner,
76+
},
13777
computed: {
138-
spinnerView() {
139-
return SPINNERS[(this.spinner || '').toUpperCase()] || SPINNERS.DEFAULT;
140-
},
14178
isNoResults: {
14279
cache: false, // disable cache to fix the problem of get slot text delay
14380
get() {
@@ -342,7 +279,7 @@
342279
};
343280
</script>
344281
<style lang="less" scoped>
345-
@import '../styles/spinner';
282+
@deep: ~'>>>';
346283
347284
.infinite-loading-container {
348285
clear: both;

src/components/Spinner.vue

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<template>
2+
<component :is="spinnerView"></component>
3+
</template>
4+
<script>
5+
const SPINNERS = {
6+
BUBBLES: {
7+
render(createElement) {
8+
return createElement('span', {
9+
attrs: {
10+
class: 'loading-bubbles',
11+
},
12+
}, Array.apply(Array, Array(8)).map(() => createElement('span', {
13+
attrs: {
14+
class: 'bubble-item',
15+
},
16+
})),
17+
);
18+
},
19+
},
20+
CIRCLES: {
21+
render(createElement) {
22+
return createElement('span', {
23+
attrs: {
24+
class: 'loading-circles',
25+
},
26+
}, Array.apply(Array, Array(8)).map(() => createElement('span', {
27+
attrs: {
28+
class: 'circle-item',
29+
},
30+
})),
31+
);
32+
},
33+
},
34+
DEFAULT: {
35+
render(createElement) {
36+
return createElement('i', {
37+
attrs: {
38+
class: 'loading-default',
39+
},
40+
});
41+
},
42+
},
43+
SPIRAL: {
44+
render(createElement) {
45+
return createElement('i', {
46+
attrs: {
47+
class: 'loading-spiral',
48+
},
49+
});
50+
},
51+
},
52+
WAVEDOTS: {
53+
render(createElement) {
54+
return createElement('span', {
55+
attrs: {
56+
class: 'loading-wave-dots',
57+
},
58+
}, Array.apply(Array, Array(5)).map(() => createElement('span', {
59+
attrs: {
60+
class: 'wave-item',
61+
},
62+
})),
63+
);
64+
},
65+
},
66+
};
67+
export default {
68+
name: 'spinner',
69+
computed: {
70+
spinnerView() {
71+
return SPINNERS[(this.spinner || '').toUpperCase()] || SPINNERS.DEFAULT;
72+
},
73+
},
74+
props: {
75+
spinner: String,
76+
},
77+
};
78+
</script>
79+
<style lang="less" scoped>
80+
@import '../styles/spinner';
81+
</style>

0 commit comments

Comments
 (0)