2023-08-28 14:43:23 +02:00
|
|
|
<script setup lang="ts">
|
|
|
|
const props = defineProps<{
|
|
|
|
loading: boolean | null
|
|
|
|
text?: string
|
|
|
|
loadingText?: string
|
|
|
|
icon?: string
|
|
|
|
loadingIcon?: string
|
|
|
|
}>()
|
|
|
|
|
|
|
|
const { t } = useI18n()
|
|
|
|
const baseAttrs = useAttrs()
|
|
|
|
const attrs = computed(() => {
|
|
|
|
return {
|
|
|
|
text: props.loading
|
|
|
|
? props.loadingText || t('saving')
|
|
|
|
: props.text || t('save'),
|
|
|
|
icon:
|
|
|
|
props.loading === true
|
2023-11-08 19:07:16 +01:00
|
|
|
? props.loadingIcon || 'loading'
|
2023-08-28 14:43:23 +02:00
|
|
|
: props.loading === false
|
2023-11-08 19:07:16 +01:00
|
|
|
? 'thumb-up'
|
2023-08-28 14:43:23 +02:00
|
|
|
: props.icon,
|
|
|
|
iconClass: props.loading ? 'animate-spin' : '',
|
|
|
|
...baseAttrs,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const onClick = (e: MouseEvent) => {
|
|
|
|
if (props.loading !== null) {
|
|
|
|
e.preventDefault()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<YButton
|
|
|
|
v-bind="attrs"
|
|
|
|
:aria-disabled="loading !== null"
|
|
|
|
:class="{ 'btn-disabled no-animation': loading !== null }"
|
|
|
|
type="submit"
|
|
|
|
@click="onClick"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.btn-disabled {
|
|
|
|
pointer-events: unset;
|
|
|
|
cursor: not-allowed;
|
|
|
|
}
|
|
|
|
</style>
|