CommonAlert.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. id?: string
  10. }
  11. const props = withDefaults(defineProps<Props>(), {
  12. variant: 'info',
  13. dismissible: false,
  14. })
  15. const icon = computed(() => {
  16. switch (props.variant) {
  17. case 'success':
  18. return 'common-alert-success'
  19. case 'warning':
  20. return 'common-alert-warning'
  21. case 'danger':
  22. return 'common-alert-danger'
  23. case 'info':
  24. default:
  25. return 'common-alert-info'
  26. }
  27. })
  28. const classMap = getAlertClasses()
  29. const dismissed = ref(false)
  30. </script>
  31. <template>
  32. <div
  33. v-if="!dismissed"
  34. :id="props.id"
  35. class="-:rounded-lg gap-1.5 border-transparent p-2"
  36. :class="[classMap.base, classMap[props.variant]]"
  37. role="alert"
  38. data-test-id="common-alert"
  39. >
  40. <CommonIcon
  41. class="mx-auto mt-0.5 md:mx-0"
  42. :name="icon"
  43. size="tiny"
  44. decorative
  45. />
  46. <slot />
  47. <div v-if="props.dismissible">
  48. <CommonIcon
  49. v-if="props.dismissible"
  50. size="tiny"
  51. decorative
  52. name="common-alert-dismiss"
  53. class="mx-auto cursor-pointer md:mx-0"
  54. @click="dismissed = true"
  55. />
  56. </div>
  57. </div>
  58. </template>