Skip to content

Commit 68d23ce

Browse files
xaviereuvl
authored andcommitted
Add ability to customize color for disabled state (#63)
1 parent 3e87f52 commit 68d23ce

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import ToggleButton from 'vue-js-toggle-button/src/Button'
5555
| sync | Boolean | false | If set to `true`, will be watching changes in `value` property and overwrite the current state of the button whenever `value` prop changes |
5656
| speed | Number | 300 | Transition time for the animation |
5757
| disabled | Boolean | false | Button does not react on mouse events |
58-
| color | [String, Object] | `#75C791` | If `String` - color of the button when checked <br>If `Object` - colors for the button when checked/uncheked <br>Example: `{checked: '#00FF00', unchecked: '#FF0000'}` |
58+
| color | [String, Object] | `#75C791` | If `String` - color of the button when checked <br>If `Object` - colors for the button when checked/unchecked or disabled<br>Example: `{checked: '#00FF00', unchecked: '#FF0000, disabled: '#CCCCCC'}` |
5959
| cssColors | Boolean | false | If `true` - deactivates the setting of colors through inline styles in favor of using CSS styling |
6060
| labels | [Boolean, Object] | false | If `Boolean` - shows/hides default labels ("on" and "off") <br>If `Object` - sets custom labels for both states. <br>Example: `{checked: 'Foo', unchecked: 'Bar'}` |
6161
| switchColor | [String, Object] | `#BFCBD9` | If `String` - color or background property of the switch when checked <br>If `Object` - colors or background property for the switch when checked/uncheked <br>Example: `{checked: '#25EF02', unchecked: 'linear-gradient(red, yellow)'}` |

demo/src/App.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,15 @@
3131

3232
<toggle-button
3333
:value="false"
34-
:width="110"
35-
:color="{unchecked: '#FF6699'}"
36-
:labels="{unchecked: 'Disabled button'}"
34+
:width="80"
35+
:labels="{unchecked: 'Disabled'}"
36+
:disabled="true"/>
37+
38+
<toggle-button
39+
:value="false"
40+
:width="140"
41+
:color="{disabled: '#FF6699'}"
42+
:labels="{unchecked: 'Custom disabled color'}"
3743
:disabled="true"/>
3844

3945
<toggle-button :value="true"

dist/index.js

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ssr.index.js

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Button.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ export default {
118118
return {
119119
width: px(this.width),
120120
height: px(this.height),
121-
backgroundColor: this.cssColors ? null : this.colorCurrent,
121+
backgroundColor: this.cssColors
122+
? null
123+
: (this.disabled ? this.colorDisabled : this.colorCurrent),
122124
borderRadius: px(Math.round(this.height / 2))
123125
}
124126
},
@@ -169,6 +171,14 @@ export default {
169171
: constants.colorUnchecked
170172
},
171173
174+
colorDisabled () {
175+
let { color } = this
176+
177+
return contains(color, 'disabled')
178+
? color.disabled
179+
: this.colorCurrent
180+
},
181+
172182
colorCurrent () {
173183
return this.toggled
174184
? this.colorChecked

0 commit comments

Comments
 (0)