CommonNotifications.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. /* eslint-disable vue/no-v-html */
  4. import type { Notification } from '#shared/components/CommonNotifications/types.ts'
  5. import { useNotifications } from '#shared/components/CommonNotifications/useNotifications.ts'
  6. import { getNotificationClasses } from '#shared/initializer/initializeNotificationClasses.ts'
  7. import { markup } from '#shared/utils/markup.ts'
  8. const notificationTypeClassMap = getNotificationClasses()
  9. const { notifications, removeNotification } = useNotifications()
  10. const getClassName = (notification: Notification) => {
  11. return notificationTypeClassMap[notification.type]
  12. }
  13. const clickHandler = (notification: Notification) => {
  14. const { callback } = notification
  15. removeNotification(notification.id)
  16. if (callback) callback()
  17. }
  18. </script>
  19. <template>
  20. <div id="Notifications" class="flex w-full justify-center">
  21. <div
  22. class="fixed top-0 z-50"
  23. :class="notificationTypeClassMap.baseContainer"
  24. role="alert"
  25. >
  26. <TransitionGroup
  27. tag="div"
  28. enter-class="opacity-0"
  29. leave-active-class="transition-opacity duration-1000 opacity-0"
  30. >
  31. <div
  32. v-for="notification in notifications"
  33. :key="notification.id"
  34. data-test-id="notification"
  35. >
  36. <div class="flex justify-center">
  37. <div
  38. class="m-3 flex cursor-pointer items-center"
  39. :class="[
  40. notificationTypeClassMap.base,
  41. getClassName(notification),
  42. ]"
  43. role="button"
  44. tabindex="0"
  45. @keydown.enter="clickHandler(notification)"
  46. @click="clickHandler(notification)"
  47. >
  48. <CommonIcon
  49. :name="`common-notification-${notification.type}`"
  50. size="small"
  51. decorative
  52. />
  53. <span
  54. class="text-sm"
  55. :class="notificationTypeClassMap.message"
  56. v-html="
  57. markup(
  58. $t(
  59. notification.message,
  60. ...(notification.messagePlaceholder || []),
  61. ),
  62. )
  63. "
  64. />
  65. </div>
  66. </div>
  67. </div>
  68. </TransitionGroup>
  69. </div>
  70. </div>
  71. </template>