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 07:06:25 +00:00
/* eslint-disable vue/require-default-prop */
/* This is a re-usable vue component for rendering a button
2018-01-05 00:18:35 +00: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-05 00:18:35 +00:00
Sample configuration:
2018-01-05 00:18:35 +00:00
<loading-button
:loading="true"
:label="Hello"
@click="..."
/>
2018-01-05 00:18:35 +00:00
*/
2018-10-10 07:06:25 +00:00
export default {
props: {
loading: {
type: Boolean,
required: false,
default: false,
},
2018-10-10 07:06:25 +00:00
disabled: {
type: Boolean,
required: false,
default: false,
2017-11-15 23:13:20 +00:00
},
2018-10-10 07:06:25 +00: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 23:13:20 +00:00
:class="containerClass"
:disabled="loading || disabled"
2018-06-11 09:49:47 +00:00
type="button"
@click="onClick"
>
2018-01-05 00:18:35 +00:00
<transition name="fade">
2018-09-11 22:19:21 +00:00
<gl-loading-icon
2018-01-05 00:18:35 +00:00
v-if="loading"
:inline="true"
:class="{
'append-right-5': label
}"
2018-06-11 09:49:47 +00:00
class="js-loading-button-icon"
2018-01-05 00:18:35 +00:00
/>
</transition>
<transition name="fade">
<slot>
<span
v-if="label"
class="js-loading-button-label"
>
{{ label }}
</span>
</slot>
2018-01-05 00:18:35 +00:00
</transition>
</button>
</template>