CommonSectionMenuLink.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <!-- Copyright (C) 2012-2024 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.ts'
  6. export interface Props {
  7. label?: string
  8. labelPlaceholder?: string[]
  9. link?: string
  10. linkExternal?: boolean
  11. icon?: string | (IconProps & HTMLAttributes)
  12. iconBg?: string
  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. :external="link && linkExternal"
  30. class="cursor-pointer border-b border-white/10 px-3 first:pt-1 last:border-0 last:pb-1"
  31. data-test-id="section-menu-link"
  32. >
  33. <div
  34. data-test-id="section-menu-item"
  35. class="flex items-center justify-between"
  36. >
  37. <div class="flex min-h-[54px] items-center">
  38. <div
  39. v-if="iconProps || $slots.icon"
  40. class="flex h-8 w-8 items-center justify-center ltr:mr-2 rtl:ml-2"
  41. data-test-id="wrapper-icon"
  42. :class="{
  43. [`rounded-lg ${iconBg}`]: iconBg,
  44. }"
  45. >
  46. <slot name="icon">
  47. <CommonIcon
  48. v-if="iconProps"
  49. v-bind="iconProps"
  50. size="base"
  51. decorative
  52. />
  53. </slot>
  54. </div>
  55. <slot>{{ i18n.t(label, ...(labelPlaceholder || [])) }}</slot>
  56. </div>
  57. <div
  58. class="flex items-center ltr:mr-1 rtl:ml-1"
  59. data-test-id="section-menu-information"
  60. >
  61. <slot name="right">{{ information && i18n.t(`${information}`) }}</slot>
  62. <CommonIcon
  63. class="text-white ltr:-mr-2 ltr:ml-2 rtl:-ml-2 rtl:mr-2"
  64. :name="`chevron-${
  65. locale.localeData?.dir === 'rtl' ? 'left' : 'right'
  66. }`"
  67. size="base"
  68. decorative
  69. />
  70. </div>
  71. </div>
  72. </component>
  73. </template>