debian-mirror-gitlab/app/assets/javascripts/vue_shared/components/loading_button.vue

83 lines
1.6 KiB
Vue
Raw Normal View History

2018-03-17 18:26:18 +05:30
<script>
2018-12-13 13:39:08 +05:30
import { GlLoadingIcon } from '@gitlab-org/gitlab-ui';
/* 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>
<button
:class="containerClass"
:disabled="loading || disabled"
2018-11-08 19:23:39 +05:30
type="button"
@click="onClick"
2018-03-17 18:26:18 +05:30
>
<transition name="fade">
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="{
'append-right-5': label
}"
2018-11-08 19:23:39 +05:30
class="js-loading-button-icon"
2018-03-17 18:26:18 +05:30
/>
</transition>
<transition name="fade">
2018-11-08 19:23:39 +05:30
<slot>
<span
v-if="label"
class="js-loading-button-label"
>
{{ label }}
</span>
</slot>
2018-03-17 18:26:18 +05:30
</transition>
</button>
</template>