2021-08-27 14:01:47 +02:00
|
|
|
<template>
|
|
|
|
<div>
|
2021-09-06 01:20:29 +02:00
|
|
|
<div class="border rounded-full border-black-100 flex items-center cursor-pointer w-12 justify-start" :class="className" @click="clickToggle">
|
|
|
|
<span class="rounded-full border w-6 h-6 border-black-50 shadow transform transition-transform duration-100" :class="switchClassName"></span>
|
2021-08-27 14:01:47 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
2021-09-05 01:02:42 +02:00
|
|
|
value: Boolean,
|
|
|
|
onColor: {
|
|
|
|
type: String,
|
|
|
|
default: 'success'
|
|
|
|
},
|
|
|
|
offColor: {
|
|
|
|
type: String,
|
|
|
|
default: 'primary'
|
2021-09-06 01:20:29 +02:00
|
|
|
},
|
|
|
|
disabled: Boolean
|
2021-08-27 14:01:47 +02:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
toggleValue: {
|
|
|
|
get() {
|
|
|
|
return this.value
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$emit('input', val)
|
|
|
|
}
|
|
|
|
},
|
2021-09-06 01:20:29 +02:00
|
|
|
className() {
|
|
|
|
if (this.disabled) return 'bg-bg cursor-not-allowed'
|
2021-09-05 01:02:42 +02:00
|
|
|
return this.toggleValue ? `bg-${this.onColor}` : `bg-${this.offColor}`
|
2021-09-06 01:20:29 +02:00
|
|
|
},
|
|
|
|
switchClassName() {
|
|
|
|
var bgColor = this.disabled ? 'bg-gray-300' : 'bg-white'
|
|
|
|
return this.toggleValue ? 'translate-x-6 ' + bgColor : bgColor
|
2021-08-27 14:01:47 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
clickToggle() {
|
2021-09-06 01:20:29 +02:00
|
|
|
if (this.disabled) return
|
2021-08-27 14:01:47 +02:00
|
|
|
this.toggleValue = !this.toggleValue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|