Skip to content

Add ability to customize color for disabled state #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Use:
| 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 |
| speed | Number | 300 | Transition time for the animation |
| disabled | Boolean | false | Button does not react on mouse events |
| 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'}` |
| 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'}` |
| 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") <br>If `Object` - sets custom labels for both states. <br>Example: `{checked: 'Foo', unchecked: 'Bar'}` |
| 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)'}` |
Expand Down
14 changes: 10 additions & 4 deletions demo/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@

<toggle-button
:value="false"
:width="110"
:color="{unchecked: '#FF6699'}"
:labels="{unchecked: 'Disabled button'}"
:width="80"
:labels="{unchecked: 'Disabled'}"
:disabled="true"/>

<toggle-button
:value="false"
:width="140"
:color="{disabled: '#FF6699'}"
:labels="{unchecked: 'Custom disabled color'}"
:disabled="true"/>

<toggle-button :value="true"
:labels="{checked: 'Button', unchecked: 'Collor'}"
:color="{checked: '#7DCE94', unchecked: '#82C7EB'}"
Expand Down
8 changes: 7 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion dist/ssr.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion src/Button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ export default {
return {
width: px(this.width),
height: px(this.height),
backgroundColor: this.cssColors ? null : this.colorCurrent,
backgroundColor: this.cssColors
? null
: (this.disabled ? this.colorDisabled : this.colorCurrent),
borderRadius: px(Math.round(this.height / 2))
}
},
Expand Down Expand Up @@ -165,6 +167,14 @@ export default {
: constants.colorUnchecked
},

colorDisabled () {
let { color } = this

return contains(color, 'disabled')
? color.disabled
: this.colorCurrent
},

colorCurrent () {
return this.toggled
? this.colorChecked
Expand Down