Forked from Bane83/gist:3b5ef7a9d8bc7c8b872a9a2887b17d1f
Created
November 17, 2017 15:08
-
-
Save johonunu/7ed3f6c5bc4750f2de086ce1b0e870a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Vue.component('vue-switch', { | |
| template: '<label :class="classObject"><span class="vue-switcher__label" v-if="shouldShowLabel"><span v-if="label" v-text="label"></span><span v-if="!label && value" v-text="textEnabled"></span> <span v-if="!label && !value" v-text="textDisabled"></span> </span> <input type="checkbox" :disabled="disabled" :true-value="trueValue" :false-value="falseValue" @change="trigger" :checked="value"><div></div> </label>', | |
| props: { | |
| typeBold: { | |
| default: false | |
| }, | |
| value: { | |
| default: false | |
| }, | |
| disabled: { | |
| default: false | |
| }, | |
| label: { | |
| default: '' | |
| }, | |
| textEnabled: { | |
| default: '' | |
| }, | |
| textDisabled: { | |
| default: '' | |
| }, | |
| color: { | |
| default: 'default' | |
| }, | |
| theme: { | |
| default: 'default' | |
| }, | |
| emitOnMount: { | |
| default: true | |
| }, | |
| trueValue: { | |
| default: true | |
| }, | |
| falseValue: { | |
| default: false | |
| }, | |
| }, | |
| mounted: function mounted() { | |
| if (this.emitOnMount) { | |
| this.$emit('input', this.value); | |
| } | |
| }, | |
| methods: { | |
| trigger: function trigger(e) { | |
| this.$emit('input', e.target.checked); | |
| } | |
| }, | |
| computed: { | |
| classObject: function classObject() { | |
| var _ref; | |
| var color = this.color, | |
| value = this.value, | |
| theme = this.theme, | |
| typeBold = this.typeBold, | |
| disabled = this.disabled; | |
| return _ref = { | |
| 'vue-switcher': true | |
| }, _defineProperty(_ref, 'vue-switcher--unchecked', !value), _defineProperty(_ref, 'vue-switcher--disabled', disabled), _defineProperty(_ref, 'vue-switcher--bold', typeBold), _defineProperty(_ref, 'vue-switcher--bold--unchecked', typeBold && !value), _defineProperty(_ref, 'vue-switcher-theme--' + theme, color), _defineProperty(_ref, 'vue-switcher-color--' + color, color), _ref; | |
| }, | |
| shouldShowLabel: function shouldShowLabel() { | |
| return this.label !== '' || this.textEnabled !== '' || this.textDisabled !== ''; | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment