gitlab-org--gitlab-foss/app/assets/javascripts/vue_shared/components/loading_button.vue

79 lines
1.5 KiB
Vue
Raw Normal View History

<script>
2018-10-10 03:06:25 -04:00
/* eslint-disable vue/require-default-prop */
/* This is a re-usable vue component for rendering a button
2018-01-04 19:18:35 -05:00
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`.
2018-01-04 19:18:35 -05:00
Sample configuration:
2018-01-04 19:18:35 -05:00
<loading-button
:loading="true"
:label="Hello"
@click="..."
/>
2018-01-04 19:18:35 -05:00
*/
2018-10-10 03:06:25 -04:00
export default {
props: {
loading: {
type: Boolean,
required: false,
default: false,
},
2018-10-10 03:06:25 -04:00
disabled: {
type: Boolean,
required: false,
default: false,
2017-11-15 18:13:20 -05:00
},
2018-10-10 03:06:25 -04:00
label: {
type: String,
required: false,
},
containerClass: {
type: [String, Array, Object],
required: false,
default: 'btn btn-align-content',
},
},
methods: {
onClick(e) {
this.$emit('click', e);
},
},
};
</script>
<template>
<button
2017-11-15 18:13:20 -05:00
:class="containerClass"
:disabled="loading || disabled"
2018-06-11 05:49:47 -04:00
type="button"
@click="onClick"
>
2018-01-04 19:18:35 -05:00
<transition name="fade">
2018-09-11 18:19:21 -04:00
<gl-loading-icon
2018-01-04 19:18:35 -05:00
v-if="loading"
:inline="true"
:class="{
'append-right-5': label
}"
2018-06-11 05:49:47 -04:00
class="js-loading-button-icon"
2018-01-04 19:18:35 -05:00
/>
</transition>
<transition name="fade">
<slot>
<span
v-if="label"
class="js-loading-button-label"
>
{{ label }}
</span>
</slot>
2018-01-04 19:18:35 -05:00
</transition>
</button>
</template>