2017-11-28 08:16:44 -05:00
|
|
|
<script>
|
2018-11-16 14:29:11 -05:00
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
2018-10-10 03:06:25 -04:00
|
|
|
import { s__ } from '../../locale';
|
|
|
|
import icon from './icon.vue';
|
2017-11-28 08:16:44 -05:00
|
|
|
|
2018-10-10 03:06:25 -04:00
|
|
|
const ICON_ON = 'status_success_borderless';
|
|
|
|
const ICON_OFF = 'status_failed_borderless';
|
|
|
|
const LABEL_ON = s__('ToggleButton|Toggle Status: ON');
|
|
|
|
const LABEL_OFF = s__('ToggleButton|Toggle Status: OFF');
|
2017-12-15 08:23:56 -05:00
|
|
|
|
2018-10-10 03:06:25 -04:00
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
icon,
|
2018-11-07 05:06:15 -05:00
|
|
|
GlLoadingIcon,
|
2018-10-10 03:06:25 -04:00
|
|
|
},
|
2018-01-04 14:07:28 -05:00
|
|
|
|
2018-10-10 03:06:25 -04:00
|
|
|
model: {
|
|
|
|
prop: 'value',
|
|
|
|
event: 'change',
|
|
|
|
},
|
2018-01-04 14:07:28 -05:00
|
|
|
|
2018-10-10 03:06:25 -04:00
|
|
|
props: {
|
|
|
|
name: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
value: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: null,
|
2017-11-28 08:16:44 -05:00
|
|
|
},
|
2018-10-10 03:06:25 -04:00
|
|
|
disabledInput: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
isLoading: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
},
|
2017-11-28 08:16:44 -05:00
|
|
|
|
2018-10-10 03:06:25 -04:00
|
|
|
computed: {
|
|
|
|
toggleIcon() {
|
|
|
|
return this.value ? ICON_ON : ICON_OFF;
|
|
|
|
},
|
|
|
|
ariaLabel() {
|
|
|
|
return this.value ? LABEL_ON : LABEL_OFF;
|
2017-12-15 08:23:56 -05:00
|
|
|
},
|
2018-10-10 03:06:25 -04:00
|
|
|
},
|
2017-12-15 08:23:56 -05:00
|
|
|
|
2018-10-10 03:06:25 -04:00
|
|
|
methods: {
|
|
|
|
toggleFeature() {
|
|
|
|
if (!this.disabledInput) this.$emit('change', !this.value);
|
2017-11-28 08:16:44 -05:00
|
|
|
},
|
2018-10-10 03:06:25 -04:00
|
|
|
},
|
|
|
|
};
|
2017-11-28 08:16:44 -05:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<label class="toggle-wrapper">
|
2018-11-16 15:07:38 -05:00
|
|
|
<input v-if="name" :name="name" :value="value" type="hidden" />
|
2017-11-28 08:16:44 -05:00
|
|
|
<button
|
2017-12-15 08:23:56 -05:00
|
|
|
:aria-label="ariaLabel"
|
2017-11-28 08:16:44 -05:00
|
|
|
:class="{
|
|
|
|
'is-checked': value,
|
|
|
|
'is-disabled': disabledInput,
|
2018-11-16 15:07:38 -05:00
|
|
|
'is-loading': isLoading,
|
2017-11-28 08:16:44 -05:00
|
|
|
}"
|
2018-06-11 05:49:47 -04:00
|
|
|
type="button"
|
|
|
|
class="project-feature-toggle"
|
2017-11-28 08:16:44 -05:00
|
|
|
@click="toggleFeature"
|
|
|
|
>
|
2018-09-11 18:19:21 -04:00
|
|
|
<gl-loading-icon class="loading-icon" />
|
2019-10-02 17:06:22 -04:00
|
|
|
<span class="toggle-icon"> <icon :name="toggleIcon" class="toggle-icon-svg" /> </span>
|
2017-11-28 08:16:44 -05:00
|
|
|
</button>
|
|
|
|
</label>
|
|
|
|
</template>
|