TicketSidebarButton.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed } from 'vue'
  4. import CommonButton from '#desktop/components/CommonButton/CommonButton.vue'
  5. import CommonUpdateIndicator from '#desktop/components/CommonUpdateIndicator/CommonUpdateIndicator.vue'
  6. import {
  7. TicketSidebarButtonBadgeType,
  8. type TicketSidebarButtonBadgeDetails,
  9. } from '../../types/sidebar.ts'
  10. interface Props {
  11. name: string
  12. label: string
  13. icon: string
  14. selected?: boolean
  15. badge?: TicketSidebarButtonBadgeDetails
  16. updateIndicator?: boolean
  17. }
  18. const props = defineProps<Props>()
  19. defineEmits<{
  20. click: [string]
  21. }>()
  22. const processedBadgeValue = computed(() => {
  23. const value = props.badge?.value
  24. if (!value) return
  25. if (!(typeof value === 'number')) return value
  26. if (value > 99) return '99+'
  27. return value
  28. })
  29. const badgeColor = computed(() => {
  30. switch (props.badge?.type) {
  31. case TicketSidebarButtonBadgeType.Warning:
  32. return 'bg-yellow-500 text-yellow-100'
  33. case TicketSidebarButtonBadgeType.Danger:
  34. return 'bg-red-500 text-pink-100'
  35. case TicketSidebarButtonBadgeType.Info:
  36. default:
  37. return 'bg-pink-500 text-white'
  38. }
  39. })
  40. </script>
  41. <template>
  42. <div class="relative">
  43. <CommonButton
  44. v-tooltip="$t(label)"
  45. :class="{
  46. 'text-black outline outline-1 outline-offset-1 outline-blue-800 focus:outline focus:outline-1 focus:outline-offset-1 focus:outline-blue-800 dark:text-white':
  47. selected,
  48. }"
  49. size="large"
  50. variant="neutral"
  51. :icon="icon"
  52. :aria-label="$t(label)"
  53. @click="$emit('click', name)"
  54. />
  55. <CommonUpdateIndicator v-if="!selected && updateIndicator" />
  56. <CommonLabel
  57. v-if="badge"
  58. size="xs"
  59. class="pointer-events-none absolute -bottom-2 block min-w-4 max-w-10 truncate rounded-full border-2 border-white px-0.5 py-0.5 text-center font-bold text-white ltr:-right-1.5 rtl:-left-1.5 dark:border-gray-500"
  60. :class="[badgeColor]"
  61. :aria-label="$t(badge.label)"
  62. role="status"
  63. >
  64. {{ processedBadgeValue }}
  65. </CommonLabel>
  66. </div>
  67. </template>