[Improvement] Switch: support custom size (#723)

This commit is contained in:
neverland
2018-03-19 13:44:12 +08:00
committed by GitHub
parent 1489efd9f9
commit c6a3896ce7
9 changed files with 62 additions and 63 deletions

View File

@@ -1,9 +1,16 @@
<template>
<div class="van-switch" :class="[`van-switch--${value ? 'on' : 'off'}`, { 'van-switch--disabled': disabled }]" @click="toggleState">
<div class="van-switch__node van-hairline-surround">
<div
class="van-switch"
:class="[{
'van-switch--on': value,
'van-switch--disabled': disabled
}]"
:style="style"
@click="onClick"
>
<div class="van-switch__node">
<loading v-if="loading" class="van-switch__loading" />
</div>
<div class="van-switch__bg" />
</div>
</template>
@@ -16,11 +23,23 @@ export default create({
props: {
value: Boolean,
loading: Boolean,
disabled: Boolean
disabled: Boolean,
size: {
type: String,
default: '30px'
}
},
computed: {
style() {
return {
fontSize: this.size
};
}
},
methods: {
toggleState() {
onClick() {
if (!this.disabled && !this.loading) {
this.$emit('input', !this.value);
this.$emit('change', !this.value);