1
1
<template >
2
2
<label :class =" className" >
3
- <input type =" checkbox"
4
- class =" v-switch-input"
5
- :name =" name"
6
- :checked =" value"
7
- :disabled =" disabled"
8
- @change.stop =" toggle" >
9
- <div class =" v-switch-core"
10
- :style =" coreStyle" >
11
- <div class =" v-switch-button"
12
- :style =" buttonStyle" />
3
+ <input
4
+ type =" checkbox"
5
+ class =" v-switch-input"
6
+ :name =" name"
7
+ :checked =" value"
8
+ :disabled =" disabled"
9
+ @change.stop =" toggle"
10
+ >
11
+ <div
12
+ class =" v-switch-core"
13
+ :style =" coreStyle"
14
+ >
15
+ <div
16
+ class =" v-switch-button"
17
+ :style =" buttonStyle"
18
+ />
13
19
</div >
14
20
<template v-if =" labels " >
15
- <span class =" v-switch-label v-left"
16
- :style =" labelStyle"
17
- v-if =" toggled" >
21
+ <span
22
+ class =" v-switch-label v-left"
23
+ :style =" labelStyle"
24
+ v-if =" toggled"
25
+ >
18
26
<slot name =" checked" >
19
27
<template >{{labelChecked}}</template >
20
28
</slot >
21
29
</span >
22
- <span class =" v-switch-label v-right"
23
- :style =" labelStyle"
24
- v-else >
30
+ <span
31
+ class =" v-switch-label v-right"
32
+ :style =" labelStyle"
33
+ v-else
34
+ >
25
35
<slot name =" unchecked" >
26
36
<template >{{labelUnchecked}}</template >
27
37
</slot >
@@ -42,6 +52,10 @@ const contains = (object, title) =>
42
52
43
53
const px = v => v + ' px'
44
54
55
+ const translate3d = (x , y , z = ' 0px' ) => {
56
+ return ` translate3d(${ x} , ${ y} , ${ z} )`
57
+ }
58
+
45
59
export default {
46
60
name: ' ToggleButton' ,
47
61
props: {
@@ -112,7 +126,7 @@ export default {
112
126
computed: {
113
127
className () {
114
128
let { toggled, disabled } = this
115
-
129
+
116
130
return [' vue-js-switch' , { toggled, disabled }]
117
131
},
118
132
@@ -137,10 +151,11 @@ export default {
137
151
138
152
buttonStyle () {
139
153
const transition = ` transform ${ this .speed } ms`
154
+ const margin = px (this .margin )
140
155
141
156
const transform = this .toggled
142
- ? ` translate3d(${ this .distance } , ${ px ( this . margin )} , 0px) `
143
- : ` translate3d(${ px ( this . margin ) } , ${ px ( this . margin )} , 0px) `
157
+ ? translate3d (this .distance , margin)
158
+ : translate3d (margin, margin)
144
159
145
160
const background = this .switchColor
146
161
? this .switchColorCurrent
0 commit comments