Files

94 lines
1.8 KiB
Vue

<script setup lang="ts">
import { useToast } from "~/composables/useToast";
const { toasts, dismiss } = useToast();
</script>
<template>
<Teleport to="body">
<div class="toast-container" aria-live="polite">
<TransitionGroup name="toast">
<div
v-for="toast in toasts"
:key="toast.id"
class="toast"
:class="`toast--${toast.type}`"
@click="dismiss(toast.id)"
role="status"
>
<span class="toast-icon">
<template v-if="toast.type === 'success'">&#10003;</template>
<template v-else-if="toast.type === 'error'">&#10007;</template>
<template v-else>&#9432;</template>
</span>
<span class="toast-message">{{ toast.message }}</span>
</div>
</TransitionGroup>
</div>
</Teleport>
</template>
<style scoped>
.toast-container {
position: fixed;
bottom: 1.5rem;
right: 1.5rem;
z-index: 9999;
display: flex;
flex-direction: column-reverse;
gap: 0.5rem;
pointer-events: none;
}
.toast {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.75rem 1rem;
border-radius: 6px;
color: white;
font-size: 0.875rem;
font-weight: 500;
cursor: pointer;
pointer-events: auto;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
max-width: 320px;
}
.toast--success {
background-color: var(--success-color);
}
.toast--error {
background-color: var(--error-color);
}
.toast--info {
background-color: var(--secondary-color);
}
.toast-icon {
flex-shrink: 0;
font-size: 1rem;
}
.toast-message {
line-height: 1.4;
}
.toast-enter-active,
.toast-leave-active {
transition: all 0.3s ease;
}
.toast-enter-from {
opacity: 0;
transform: translateX(1rem);
}
.toast-leave-to {
opacity: 0;
transform: translateX(1rem);
}
</style>