Files
baserow/web-frontend/modules/builder/components/BuilderToast.vue
716d43a9a8 Nuxt 3 migration (#4342)
Update the nuxt3 version.

Co-authored-by: Jonathan Adeline <jonathan@baserow.io>
Co-authored-by: Bram Wiepjes <bramw@protonmail.com>
Co-authored-by: Cezary <cezary@baserow.io>
Co-authored-by: Tsering Paljor <tsering@baserow.io>
Co-authored-by: Przemyslaw Kukulski <przemyslaw+gh@baserow.io>
Co-authored-by: Bram <bram2w@users.noreply.github.com>
2026-01-22 10:27:19 +01:00

113 lines
2.3 KiB
Vue

<template>
<div class="ab-toast" @mouseenter="pauseTimer" @mouseleave="resumeTimer">
<div v-if="type">
<div class="ab-toast__icon" :class="`ab-toast__icon--${type}`">
<i v-if="icon" :class="icon"></i>
</div>
</div>
<div class="ab-toast__content">
<div v-if="hasTitleSlot" class="ab-toast__title">
<slot name="title" />
</div>
<div v-if="hasContentSlot" class="ab-toast__message"><slot /></div>
<div v-if="hasActionsSlot" class="ab-toast__actions">
<slot name="actions" />
</div>
</div>
<button v-if="closeButton" class="ab-toast__close" @click="$emit('close')">
<i class="iconoir-cancel"></i>
</button>
</div>
</template>
<script>
export default {
name: 'BuilderToast',
props: {
/**
* The type of toast to display
*/
type: {
type: String,
default: 'info-primary',
validator: function (value) {
return [
'info-neutral',
'info-primary',
'warning',
'error',
'success',
].includes(value)
},
},
/**
* The icon to display in the toast.
*/
icon: {
type: String,
default: null,
},
/**
* Whether to display a close button or not.
*/
closeButton: {
required: false,
type: Boolean,
default: false,
},
},
emits: ['close'],
data() {
return {
timer: null,
remainingTime: 5000,
startTime: null,
}
},
computed: {
hasTitleSlot() {
return !!this.$slots.title
},
hasActionsSlot() {
return !!this.$slots.actions
},
hasContentSlot() {
return !!this.$slots.default
},
},
mounted() {
this.startTimer()
},
beforeUnmount() {
this.clearTimer()
},
methods: {
startTimer() {
this.startTime = Date.now()
this.timer = setTimeout(() => {
this.close()
}, this.remainingTime)
},
clearTimer() {
if (this.timer) {
clearTimeout(this.timer)
this.timer = null
}
},
pauseTimer() {
if (this.timer) {
this.clearTimer()
this.remainingTime -= Date.now() - this.startTime
}
},
resumeTimer() {
if (this.remainingTime > 0) {
this.startTimer()
}
},
close() {
this.$emit('close')
},
},
}
</script>