UNPKG

@gitlab/ui

Version:
119 lines (108 loc) 3.85 kB
import { toggleLabelPosition } from '../../../utils/constants'; import GlIcon from '../icon/icon'; import GlLoadingIcon from '../loading_icon/loading_icon'; import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js'; var uuid = 0; var script = { components: { GlIcon: GlIcon, GlLoadingIcon: GlLoadingIcon }, model: { prop: 'value', event: 'change' }, props: { name: { type: String, required: false, default: null }, value: { type: Boolean, required: false, default: null }, disabled: { type: Boolean, required: false, default: false }, isLoading: { type: Boolean, required: false, default: false }, label: { type: String, required: false, default: undefined }, help: { type: String, required: false, default: undefined }, labelPosition: { type: String, required: false, default: 'top', validator: function validator(position) { return Object.values(toggleLabelPosition).includes(position); } } }, computed: { icon: function icon() { return this.value ? 'mobile-issue-close' : 'close'; }, shouldShowLabel: function shouldShowLabel() { return this.label && this.labelPosition !== 'hidden'; }, helpId: function helpId() { return this.help ? "toggle-help-".concat(this.uuid) : undefined; } }, beforeCreate: function beforeCreate() { this.uuid = uuid; uuid += 1; }, methods: { toggleFeature: function toggleFeature() { if (!this.disabled) this.$emit('change', !this.value); } } }; /* script */ const __vue_script__ = script; /* template */ var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('label',{staticClass:"gl-display-flex gl-flex-direction-column gl-mb-0 gl-w-max-content"},[_c('span',{staticClass:"gl-toggle-wrapper",class:{ 'gl-toggle-label-inline': _vm.labelPosition === 'left', 'is-disabled': _vm.disabled }},[(_vm.shouldShowLabel)?_c('span',{staticClass:"gl-toggle-label",attrs:{"data-testid":"toggle-label"}},[_vm._t("label",[_vm._v(_vm._s(_vm.label))])],2):_vm._e(),_vm._v(" "),(_vm.name)?_c('input',{attrs:{"name":_vm.name,"type":"hidden"},domProps:{"value":_vm.value}}):_vm._e(),_vm._v(" "),_c('button',{class:{ 'gl-toggle': true, 'is-checked': _vm.value, 'is-disabled': _vm.disabled, },attrs:{"role":"switch","aria-checked":_vm.value,"aria-label":_vm.label,"aria-describedby":_vm.helpId,"type":"button"},on:{"click":function($event){$event.preventDefault();return _vm.toggleFeature($event)}}},[(_vm.isLoading)?_c('gl-loading-icon',{staticClass:"toggle-loading",attrs:{"color":"light"}}):_c('span',{class:{ 'toggle-icon': true, disabled: _vm.disabled }},[_c('gl-icon',{attrs:{"name":_vm.icon,"size":16}})],1)],1)]),_vm._v(" "),(_vm.help)?_c('span',{staticClass:"gl-help-label",attrs:{"id":_vm.helpId,"data-testid":"toggle-help"}},[_vm._t("help",[_vm._v(_vm._s(_vm.help))])],2):_vm._e()])}; var __vue_staticRenderFns__ = []; /* style */ const __vue_inject_styles__ = undefined; /* scoped */ const __vue_scope_id__ = undefined; /* module identifier */ const __vue_module_identifier__ = undefined; /* functional template */ const __vue_is_functional_template__ = false; /* style inject */ /* style inject SSR */ /* style inject shadow dom */ const __vue_component__ = __vue_normalize__( { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ }, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, false, undefined, undefined, undefined ); export default __vue_component__;