11<template >
2- <section class =" wrapper" v-bind:class =" {dark: darkTheme}" :title =" title" >
3- <input :id =" id" :name =" name" v-model =" toggled" class =" toggle" type =" checkbox" @click =" toggled = !toggled" />
4- <label :for =" id" class =" toggler" />
5- <span class =" title" v-text =" title" @click =" toggled = !toggled" />
2+ <section class =" wrapper" :class =" {dark: darkTheme}" :title =" title" >
3+ <input
4+ :id =" id"
5+ :name =" name"
6+ v-model =" toggleState"
7+ class =" toggle"
8+ type =" checkbox"
9+ @click =" toggleState = !toggleState"
10+ />
11+ <label :for =" id" class =" toggler" :style =" [toggleState && {'background': activeColor}]" />
12+ <span class =" title" v-text =" title" @click =" toggleState = !toggleState" />
613 </section >
714</template >
815
@@ -11,11 +18,18 @@ export default {
1118 name: ' VueToggle' ,
1219
1320 props: {
21+ activeColor: {type: String , default: ' #9FD6AE' },
22+ darkTheme: {type: Boolean , default: false },
1423 id: {type: String , required: true },
1524 name: {type: [String , Boolean ], default: false },
1625 title: {type: String , required: true },
1726 toggled: {type: Boolean , default: false },
18- darkTheme: {type: Boolean , default: false }
27+ },
28+
29+ data () {
30+ return {
31+ toggleState: this .toggled
32+ }
1933 },
2034}
2135 </script >
@@ -93,8 +107,6 @@ export default {
93107
94108 & :checked {
95109 & + .toggler {
96- background : #9FD6AE ;
97-
98110 & :after {
99111 left : 50% ;
100112 }
0 commit comments