corrad-bp/components/RsAlert.vue
2025-04-09 11:16:18 +08:00

61 lines
1.1 KiB
Vue

<script setup>
const props = defineProps({
variant: {
type: String,
default: "primary",
},
dismissible: {
type: Boolean,
default: false,
},
show: {
type: Boolean,
default: true,
},
autoDismiss: {
type: Boolean,
default: false,
},
timer: {
type: Number,
default: 1000,
},
});
const showComponent = ref(props.show);
const autoDismiss = () => {
setTimeout(() => {
showComponent.value = false;
}, props.timer);
};
onMounted(() => {
if (props.autoDismiss) {
autoDismiss();
}
});
</script>
<template>
<Transition name="fade-up">
<div
v-if="showComponent"
class="alert"
:class="{
'alert-primary': variant === 'primary',
'alert-secondary': variant === 'secondary',
'alert-info': variant === 'info',
'alert-success': variant === 'success',
'alert-warning': variant === 'warning',
'alert-danger': variant === 'danger',
}"
>
<slot />
<button @click="showComponent = false">
<Icon name="ic:baseline-close" size="14"></Icon>
</button>
</div>
</Transition>
</template>