aboutsummaryrefslogtreecommitdiff
path: root/src/components/progress_button/progress_button.vue
blob: 283a51af58a7d676ae27d2444f922da22858609c (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
<template>
  <button
    :disabled="progress || disabled"
    @click="onClick"
  >
    <template v-if="progress && $slots.progress">
      <slot name="progress" />
    </template>
    <template v-else>
      <slot />
    </template>
  </button>
</template>

<script>
export default {
  props: {
    disabled: {
      type: Boolean
    },
    click: { // click event handler. Must return a promise
      type: Function,
      default: () => Promise.resolve()
    }
  },
  data () {
    return {
      progress: false
    }
  },
  methods: {
    onClick () {
      this.progress = true
      this.click().then(() => { this.progress = false })
    }
  }
}
</script>