Skip to content

Commit a8fb2f5

Browse files
committed
feat: support configure spinner as a pure text via plugin API
1 parent b75442a commit a8fb2f5

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/components/Spinner.vue

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,33 @@ export default {
6969
name: 'Spinner',
7070
computed: {
7171
spinnerView() {
72-
const spinner = this.$attrs.spinner || config.props.spinner;
73-
7472
return (
75-
typeof spinner === 'string'
76-
? (SPINNERS[spinner.toUpperCase()] || SPINNERS.DEFAULT)
77-
: spinner
73+
typeof this.$attrs.spinner === 'string'
74+
? SPINNERS[this.$attrs.spinner.toUpperCase()]
75+
: this.spinnerInConfig // fallback to spinner of config
7876
);
7977
},
78+
spinnerInConfig() {
79+
let result;
80+
81+
if (config.slots.spinner && typeof config.slots.spinner === 'string') {
82+
// as spinner slot config a pure text spinner
83+
result = {
84+
render() {
85+
return this._v(config.slots.spinner); // eslint-disable-line no-underscore-dangle
86+
},
87+
};
88+
} else if (typeof config.slots.spinner === 'object') {
89+
// as spinner slot config a Vue component
90+
result = config.slots.spinner;
91+
} else {
92+
// fallback to spinner property config
93+
/* istanbul ignore next */
94+
result = SPINNERS[config.props.spinner.toUpperCase()] || SPINNERS.DEFAULT;
95+
}
96+
97+
return result;
98+
},
8099
},
81100
};
82101
</script>

src/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const slots = {
3636
noMore: 'No more data :)',
3737
error: 'Opps, something went wrong :(',
3838
errorBtnText: 'Retry',
39+
spinner: '',
3940
};
4041

4142
/**

0 commit comments

Comments
 (0)