pleroma-fe/src/components/progress_button/progress_button.vue

41 lines
687 B
Vue
Raw Normal View History

2019-04-04 13:26:08 -04:00
<template>
2019-07-10 20:59:10 -04:00
<button
:disabled="progress || disabled"
@click="onClick"
>
2019-04-25 12:34:46 -04:00
<template v-if="progress && $slots.progress">
2019-04-04 13:26:08 -04:00
<slot name="progress" />
</template>
<template v-else>
<slot />
</template>
</button>
</template>
<script>
export default {
props: {
disabled: {
2026-01-06 16:22:52 +02:00
type: Boolean,
2019-04-04 13:26:08 -04:00
},
2026-01-06 16:22:52 +02:00
click: {
// click event handler. Must return a promise
2019-04-04 13:26:08 -04:00
type: Function,
2026-01-06 16:22:52 +02:00
default: () => Promise.resolve(),
},
2019-04-04 13:26:08 -04:00
},
2026-01-06 16:22:52 +02:00
data() {
2019-04-04 13:26:08 -04:00
return {
2026-01-06 16:22:52 +02:00
progress: false,
2019-04-04 13:26:08 -04:00
}
},
methods: {
2026-01-06 16:22:52 +02:00
onClick() {
2019-04-04 13:26:08 -04:00
this.progress = true
2026-01-06 16:22:52 +02:00
this.click().then(() => {
this.progress = false
})
},
},
2019-04-04 13:26:08 -04:00
}
</script>