2018-03-17 18:26:18 +05:30
|
|
|
<script>
|
|
|
|
import { s__ } from '../../locale';
|
|
|
|
import icon from './icon.vue';
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
icon,
|
|
|
|
},
|
|
|
|
|
|
|
|
model: {
|
|
|
|
prop: 'value',
|
|
|
|
event: 'change',
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
name: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
value: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
disabledInput: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
isLoading: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
toggleIcon() {
|
|
|
|
return this.value ? ICON_ON : ICON_OFF;
|
|
|
|
},
|
|
|
|
ariaLabel() {
|
|
|
|
return this.value ? LABEL_ON : LABEL_OFF;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
toggleFeature() {
|
|
|
|
if (!this.disabledInput) this.$emit('change', !this.value);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<label class="toggle-wrapper">
|
|
|
|
<input
|
|
|
|
v-if="name"
|
|
|
|
:name="name"
|
|
|
|
:value="value"
|
2018-11-08 19:23:39 +05:30
|
|
|
type="hidden"
|
2018-03-17 18:26:18 +05:30
|
|
|
/>
|
|
|
|
<button
|
|
|
|
:aria-label="ariaLabel"
|
|
|
|
:class="{
|
|
|
|
'is-checked': value,
|
|
|
|
'is-disabled': disabledInput,
|
|
|
|
'is-loading': isLoading
|
|
|
|
}"
|
2018-11-08 19:23:39 +05:30
|
|
|
type="button"
|
|
|
|
class="project-feature-toggle"
|
2018-03-17 18:26:18 +05:30
|
|
|
@click="toggleFeature"
|
|
|
|
>
|
2018-12-05 23:21:45 +05:30
|
|
|
<gl-loading-icon class="loading-icon" />
|
2018-03-17 18:26:18 +05:30
|
|
|
<span class="toggle-icon">
|
|
|
|
<icon
|
2018-11-08 19:23:39 +05:30
|
|
|
:name="toggleIcon"
|
|
|
|
css-classes="toggle-icon-svg"/>
|
2018-03-17 18:26:18 +05:30
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
</label>
|
|
|
|
</template>
|