[Improvement] Loading: add size prop (#620)

This commit is contained in:
neverland 2018-02-07 17:28:59 +08:00 committed by GitHub
parent e53f543639
commit 2a3c75bc2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 1 deletions

View File

@ -43,3 +43,4 @@ Vue.use(Loading);
|-----------|-----------|-----------|-------------|-------------| |-----------|-----------|-----------|-------------|-------------|
| color | Color | `String` | `black` | `black` `white` | | color | Color | `String` | `black` | `black` `white` |
| type | Type | `String` | `gradient-circle` | `spinner` `circle` | | type | Type | `String` | `gradient-circle` | `spinner` `circle` |
| size | Size | `String` | `30px` | - |

View File

@ -43,3 +43,4 @@ Vue.use(Loading);
|-----------|-----------|-----------|-------------|-------------| |-----------|-----------|-----------|-------------|-------------|
| color | 颜色 | `String` | `black` | `black` `white` | | color | 颜色 | `String` | `black` | `black` `white` |
| type | 类型 | `String` | `gradient-circle` | `spinner` `circle` | | type | 类型 | `String` | `gradient-circle` | `spinner` `circle` |
| size | 大小 | `String` | `30px` | - |

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="van-loading" :class="['van-loading--' + type, 'van-loading--' + color]"> <div class="van-loading" :class="['van-loading--' + type, 'van-loading--' + color]" :style="style">
<span class="van-loading__spinner" :class="'van-loading__spinner--' + type"> <span class="van-loading__spinner" :class="'van-loading__spinner--' + type">
<i v-for="item in (type === 'spinner' ? 12 : 0)" /> <i v-for="item in (type === 'spinner' ? 12 : 0)" />
<svg v-if="type === 'circular'" class="van-loading__circular" viewBox="25 25 50 50"> <svg v-if="type === 'circular'" class="van-loading__circular" viewBox="25 25 50 50">
@ -14,8 +14,11 @@ import install from '../utils/install';
export default { export default {
install, install,
name: 'van-loading', name: 'van-loading',
props: { props: {
size: String,
type: { type: {
type: String, type: String,
default: 'gradient-circle' default: 'gradient-circle'
@ -24,6 +27,15 @@ export default {
type: String, type: String,
default: 'black' default: 'black'
} }
},
computed: {
style() {
return this.size ? {
width: this.size,
height: this.size
} : {};
}
} }
}; };
</script> </script>

View File

@ -60,4 +60,14 @@ describe('Loading', () => {
expect(spinner.hasClass('van-loading__spinner--circle')).to.be.true; expect(spinner.hasClass('van-loading__spinner--circle')).to.be.true;
}); });
it('loading size', () => {
wrapper = mount(Loading, {
propsData: {
size: '100px'
}
});
expect(wrapper.vm.$el.style.width).to.equal('100px');
expect(wrapper.vm.$el.style.height).to.equal('100px');
});
}); });