CommonSectionMenuLink.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <!-- Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed, type HTMLAttributes } from 'vue'
  4. import { type Props as IconProps } from '@shared/components/CommonIcon/CommonIcon.vue'
  5. import { useLocaleStore } from '@shared/stores/locale'
  6. export interface Props {
  7. label?: string
  8. labelPlaceholder?: string[]
  9. link?: string
  10. icon?: string | (IconProps & HTMLAttributes)
  11. iconBg?: string
  12. // TODO maybe change the name based on the usage
  13. information?: string | number
  14. }
  15. const props = defineProps<Props>()
  16. const locale = useLocaleStore()
  17. const iconProps = computed<IconProps | null>(() => {
  18. if (!props.icon) return null
  19. if (typeof props.icon === 'string') {
  20. return { name: props.icon }
  21. }
  22. return props.icon
  23. })
  24. </script>
  25. <template>
  26. <component
  27. :is="link ? 'CommonLink' : 'button'"
  28. :link="link"
  29. class="cursor-pointer border-b border-white/10 last:border-0"
  30. data-test-id="section-menu-link"
  31. >
  32. <div
  33. data-test-id="section-menu-item"
  34. class="flex items-center justify-between"
  35. >
  36. <div class="flex min-h-[54px] items-center">
  37. <div
  38. v-if="iconProps || $slots.icon"
  39. class="flex h-8 w-8 items-center justify-center ltr:mr-2 rtl:ml-2"
  40. data-test-id="wrapper-icon"
  41. :class="{
  42. [`rounded-lg ${iconBg}`]: iconBg,
  43. }"
  44. >
  45. <slot name="icon">
  46. <CommonIcon
  47. v-if="iconProps"
  48. v-bind="iconProps"
  49. size="base"
  50. decorative
  51. />
  52. </slot>
  53. </div>
  54. <slot>{{ i18n.t(label, ...(labelPlaceholder || [])) }}</slot>
  55. </div>
  56. <div
  57. class="mr-1 flex items-center"
  58. data-test-id="section-menu-information"
  59. >
  60. <slot name="right">{{ information && i18n.t(`${information}`) }}</slot>
  61. <CommonIcon
  62. class="text-gray ltr:ml-2 rtl:mr-2"
  63. :name="`mobile-chevron-${
  64. locale.localeData?.dir === 'rtl' ? 'left' : 'right'
  65. }`"
  66. size="base"
  67. decorative
  68. />
  69. </div>
  70. </div>
  71. </component>
  72. </template>