Skip to content

Commit 8d860d2

Browse files
committed
support btn color object
1 parent 7255f89 commit 8d860d2

File tree

3 files changed

+82
-6
lines changed

3 files changed

+82
-6
lines changed

dist/index.js

Lines changed: 25 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ssr.index.js

Lines changed: 25 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Button.vue

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const constants = {
3232
labelUnchecked: 'off',
3333
width: 50,
3434
height: 22,
35-
margin: 3
35+
margin: 3,
36+
buttonColor: '#fff'
3637
}
3738
3839
const contains = (object, title) => {
@@ -134,7 +135,7 @@ export default {
134135
transform: this.toggled
135136
? `translate3d(${this.distance}, 3px, 0px)`
136137
: null,
137-
backgroundColor: this.buttonColor ? this.buttonColor : undefined
138+
backgroundColor: this.buttonColor ? this.buttonColorCurrent : undefined
138139
}
139140
},
140141
@@ -180,7 +181,36 @@ export default {
180181
return contains(this.labels, 'unchecked')
181182
? this.labels.unchecked
182183
: constants.labelUnchecked
184+
},
185+
186+
buttonColorChecked () {
187+
let { buttonColor } = this
188+
189+
return contains(buttonColor, 'checked')
190+
? buttonColor.checked
191+
: constants.buttonColor
192+
},
193+
194+
buttonColorUnchecked () {
195+
let { buttonColor } = this
196+
197+
return contains(buttonColor, 'unchecked')
198+
? buttonColor.unchecked
199+
: constants.buttonColor
200+
},
201+
202+
buttonColorCurrent () {
203+
let { buttonColor } = this
204+
205+
if (typeof buttonColor !== 'object') {
206+
return buttonColor || constants.buttonColor
207+
}
208+
209+
return this.toggled
210+
? this.buttonColorChecked
211+
: this.buttonColorUnchecked
183212
}
213+
184214
},
185215
watch: {
186216
value (value) {

0 commit comments

Comments
 (0)