2018-03-17 18:26:18 +05:30
|
|
|
<script>
|
2019-02-15 15:39:39 +05:30
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
2018-12-13 13:39:08 +05:30
|
|
|
/* eslint-disable vue/require-default-prop */
|
|
|
|
/* This is a re-usable vue component for rendering a button
|
2018-03-17 18:26:18 +05:30
|
|
|
that will probably be sending off ajax requests and need
|
|
|
|
to show the loading status by setting the `loading` option.
|
|
|
|
This can also be used for initial page load when you don't
|
|
|
|
know the action of the button yet by setting
|
|
|
|
`loading: true, label: undefined`.
|
|
|
|
|
|
|
|
Sample configuration:
|
|
|
|
|
|
|
|
<loading-button
|
|
|
|
:loading="true"
|
|
|
|
:label="Hello"
|
|
|
|
@click="..."
|
|
|
|
/>
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
GlLoadingIcon,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
loading: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
label: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
},
|
|
|
|
containerClass: {
|
|
|
|
type: [String, Array, Object],
|
|
|
|
required: false,
|
|
|
|
default: 'btn btn-align-content',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onClick(e) {
|
|
|
|
this.$emit('click', e);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2018-03-17 18:26:18 +05:30
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2019-02-15 15:39:39 +05:30
|
|
|
<button :class="containerClass" :disabled="loading || disabled" type="button" @click="onClick">
|
2019-05-18 00:54:41 +05:30
|
|
|
<transition name="fade-in">
|
2018-12-05 23:21:45 +05:30
|
|
|
<gl-loading-icon
|
2018-03-17 18:26:18 +05:30
|
|
|
v-if="loading"
|
|
|
|
:inline="true"
|
|
|
|
:class="{
|
2019-02-15 15:39:39 +05:30
|
|
|
'append-right-5': label,
|
2018-03-17 18:26:18 +05:30
|
|
|
}"
|
2018-11-08 19:23:39 +05:30
|
|
|
class="js-loading-button-icon"
|
2018-03-17 18:26:18 +05:30
|
|
|
/>
|
|
|
|
</transition>
|
2019-05-18 00:54:41 +05:30
|
|
|
<transition name="fade-in">
|
2018-11-08 19:23:39 +05:30
|
|
|
<slot>
|
2019-02-15 15:39:39 +05:30
|
|
|
<span v-if="label" class="js-loading-button-label"> {{ label }} </span>
|
2018-11-08 19:23:39 +05:30
|
|
|
</slot>
|
2018-03-17 18:26:18 +05:30
|
|
|
</transition>
|
|
|
|
</button>
|
|
|
|
</template>
|