CommonAlert.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed, ref } from 'vue'
  4. import { getAlertClasses } from '#shared/initializer/initializeAlertClasses.ts'
  5. import type { AlertVariant } from './types.ts'
  6. export interface Props {
  7. variant?: AlertVariant
  8. dismissible?: boolean
  9. link?: string | null
  10. linkText?: string | null
  11. id?: string
  12. }
  13. const props = withDefaults(defineProps<Props>(), {
  14. variant: 'info',
  15. dismissible: false,
  16. })
  17. const icon = computed(() => {
  18. switch (props.variant) {
  19. case 'success':
  20. return 'common-alert-success'
  21. case 'warning':
  22. return 'common-alert-warning'
  23. case 'danger':
  24. return 'common-alert-danger'
  25. case 'info':
  26. default:
  27. return 'common-alert-info'
  28. }
  29. })
  30. const classMap = getAlertClasses()
  31. const dismissed = ref(false)
  32. </script>
  33. <template>
  34. <div
  35. v-if="!dismissed"
  36. :id="props.id"
  37. class="-:rounded-lg gap-1.5 border-transparent p-2"
  38. :class="[classMap.base, classMap[props.variant]]"
  39. role="alert"
  40. data-test-id="common-alert"
  41. >
  42. <CommonIcon class="mx-auto md:mx-0" :name="icon" size="tiny" decorative />
  43. <slot />
  44. <div
  45. v-if="props.link || props.dismissible"
  46. class="flex items-center justify-start ltr:ml-auto rtl:mr-auto"
  47. >
  48. <CommonLink
  49. v-if="props.link"
  50. class="text-ellipsis ltr:mr-2 rtl:ml-2"
  51. :class="classMap.link"
  52. :link="props.link"
  53. open-in-new-tab
  54. rel="noopener noreferrer"
  55. >{{ props.linkText || props.link }}</CommonLink
  56. >
  57. <CommonIcon
  58. v-if="props.dismissible"
  59. size="tiny"
  60. decorative
  61. name="common-alert-dismiss"
  62. class="mx-auto cursor-pointer md:mx-0"
  63. @click="dismissed = true"
  64. />
  65. </div>
  66. </div>
  67. </template>