summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared/components/loading_button.vue
blob: fd6871c81c97b09fa70e3c5cdd840f4b55649b43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<script>

/* This is a re-usable vue component for rendering a button
   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="..."
  />

*/

import loadingIcon from './loading_icon.vue';

export default {
  props: {
    loading: {
      type: Boolean,
      required: false,
      default: false,
    },
    label: {
      type: String,
      required: false,
    },
  },
  components: {
    loadingIcon,
  },
  methods: {
    onClick(e) {
      this.$emit('click', e);
    },
  },
};
</script>

<template>
  <button
    class="btn btn-align-content"
    @click="onClick"
    type="button"
    :disabled="loading"
  >
      <transition name="expand-fade-sm">
        <loading-icon
          v-if="loading"
          :inline="true"
          class="js-loading-button-icon"
        />
      </transition>
      <transition name="expand-fade-sm">
        <span
          v-if="loading && label"
          class="append-right-5 js-loading-button-spacer"
        >
        </span>
      </transition>
      <transition name="expand-fade-md">
        <span
          v-if="label"
          class="js-loading-button-label"
        >
          {{ label }}
        </span>
      </transition>
  </button>
</template>