diff --git a/README.md b/README.md index 0d49d74..78e465d 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ Use: | color | [String, Object] | `#75C791` | If `String` - color of the button when checked
If `Object` - colors for the button when checked/uncheked
Example: `{checked: '#00FF00', unchecked: '#FF0000'}` | | cssColors | Boolean | false | If `true` - deactivates the setting of colors through inline styles in favor of using CSS styling | | labels | [Boolean, Object] | false | If `Boolean` - shows/hides default labels ("on" and "off")
If `Object` - sets custom labels for both states.
Example: `{checked: 'Foo', unchecked: 'Bar'}` | +| switchColor | [String, Object] | `#BFCBD9` | If `String` - color or background property of the switch when checked
If `Object` - colors or background property for the switch when checked/uncheked
Example: `{checked: '#25EF02', unchecked: 'linear-gradient(red, yellow)'}` | | width | Number | 50 | Width of the button, default is 50 | | height | Number | 22 | Height of the button, default is 22 | diff --git a/demo/src/App.vue b/demo/src/App.vue index 7eac1b5..11739fb 100644 --- a/demo/src/App.vue +++ b/demo/src/App.vue @@ -34,6 +34,12 @@ :color="{unchecked: '#FF6699'}" :labels="{unchecked: 'Disabled button'}" :disabled="true"/> + +
{ @@ -68,6 +69,14 @@ export default { : typeof value === 'string' } }, + switchColor: { + type: [String, Object], + validator (value) { + return typeof value === 'object' + ? (value.checked || value.unchecked) + : typeof value === 'string' + } + }, cssColors: { type: Boolean, default: false @@ -125,7 +134,8 @@ export default { transition: `transform ${this.speed}ms`, transform: this.toggled ? `translate3d(${this.distance}, 3px, 0px)` - : null + : null, + background: this.switchColor ? this.switchColorCurrent : undefined } }, @@ -171,7 +181,36 @@ export default { return contains(this.labels, 'unchecked') ? this.labels.unchecked : constants.labelUnchecked + }, + + switchColorChecked () { + let { switchColor } = this + + return contains(switchColor, 'checked') + ? switchColor.checked + : constants.switchColor + }, + + switchColorUnchecked () { + let { switchColor } = this + + return contains(switchColor, 'unchecked') + ? switchColor.unchecked + : constants.switchColor + }, + + switchColorCurrent () { + let { switchColor } = this + + if (typeof switchColor !== 'object') { + return switchColor || constants.switchColor + } + + return this.toggled + ? this.switchColorChecked + : this.switchColorUnchecked } + }, watch: { value (value) {