All files / src/components ToastContainer.vue

75% Statements 6/8
0% Branches 0/4
33.33% Functions 1/3
75% Lines 6/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67  1x     1x               1x 1x                                                     1x 1x                                                  
<template>
  <div class="toast-container position-fixed bottom-0 end-0 p-3" style="z-index: 1200">
    <TransitionGroup name="toast">
      <div
        v-for="toast in toastStore.toasts"
        :key="toast.id"
        class="toast show align-items-center border-0 mb-2"
        :class="toast.type === 'success' ? 'text-bg-success' : 'text-bg-danger'"
        role="alert"
        aria-live="assertive"
        aria-atomic="true"
      >
        <div class="d-flex">
          <div class="toast-body">
            <font-awesome-icon
              :icon="
                toast.type === 'success'
                  ? 'fa-solid fa-check-circle'
                  : 'fa-solid fa-exclamation-circle'
              "
              class="me-2"
            />
            {{ toast.message }}
          </div>
          <button
            type="button"
            class="btn-close btn-close-white me-2 m-auto"
            :aria-label="t('common.close')"
            @click="toastStore.dismiss(toast.id)"
          ></button>
        </div>
      </div>
    </TransitionGroup>
  </div>
</template>
 
<script setup lang="ts">
import { useToastStore } from '@/stores/toast'
import { useUILanguage } from '@/composables/useUILanguage'
 
const toastStore = useToastStore()
const { t } = useUILanguage()
</script>
 
<style scoped>
.toast-container {
  max-width: calc(100vw - 2rem);
}
 
.toast {
  min-width: 280px;
}
 
.toast-enter-active,
.toast-leave-active {
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}
 
.toast-enter-from,
.toast-leave-to {
  opacity: 0;
  transform: translateX(2rem);
}
</style>