2019-08-14 09:48:44 +00:00
|
|
|
<template>
|
|
|
|
<label class="switch" :class="classObject">
|
2021-12-09 01:32:00 +00:00
|
|
|
<input
|
|
|
|
:id="id"
|
|
|
|
v-model="value"
|
|
|
|
class="switch-input"
|
|
|
|
:name="name"
|
|
|
|
:disabled="disabled"
|
|
|
|
type="checkbox"
|
|
|
|
/>
|
2019-08-14 09:48:44 +00:00
|
|
|
<div class="switch-paddle" :for="name">
|
|
|
|
<span class="show-for-sr">on off</span>
|
|
|
|
</div>
|
|
|
|
</label>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
disabled: Boolean,
|
2021-12-27 08:19:31 +00:00
|
|
|
type: { type: String, default: '' },
|
|
|
|
size: { type: String, default: '' },
|
2019-08-14 09:48:44 +00:00
|
|
|
checked: Boolean,
|
2021-12-27 08:19:31 +00:00
|
|
|
name: { type: String, default: '' },
|
|
|
|
id: { type: String, default: '' },
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
value: null,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
classObject() {
|
|
|
|
const { type, size, value } = this;
|
|
|
|
return {
|
|
|
|
[`is-${type}`]: type,
|
|
|
|
[`${size}`]: size,
|
|
|
|
checked: value,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
value(val) {
|
|
|
|
this.$emit('input', val);
|
|
|
|
},
|
|
|
|
},
|
2021-12-09 01:32:00 +00:00
|
|
|
beforeMount() {
|
|
|
|
this.value = this.checked;
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.$emit('input', (this.value = !!this.checked));
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
};
|
|
|
|
</script>
|