CommonPopoverMenuItem.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed } from 'vue'
  4. import type { Link } from '#shared/types/router.ts'
  5. import type { ObjectLike } from '#shared/types/utils.ts'
  6. import type { Variant } from '#desktop/components/CommonPopoverMenu/types.ts'
  7. export interface Props {
  8. label?: string
  9. ariaLabel?: string | ((entity?: ObjectLike) => string)
  10. labelPlaceholder?: string[]
  11. link?: Link
  12. linkExternal?: boolean
  13. variant?: Variant
  14. icon?: string
  15. labelClass?: string
  16. }
  17. const props = defineProps<Props>()
  18. const variantClass = computed(() => {
  19. if (props.variant === 'secondary') return 'text-blue-800'
  20. if (props.variant === 'danger') return 'text-red-500'
  21. return 'group-focus-within:text-white group-hover:text-black group-hover:group-focus-within:text-white dark:group-hover:text-white'
  22. })
  23. const iconColor = computed(() => {
  24. if (props.variant === 'secondary') return 'text-blue-800'
  25. if (props.variant === 'danger') return 'text-red-500'
  26. return 'text-stone-200 dark:text-neutral-500 group-hover:text-black dark:group-hover:text-white group-focus-within:text-white group-hover:group-focus-within:text-white'
  27. })
  28. </script>
  29. <template>
  30. <component
  31. :is="link ? 'CommonLink' : 'button'"
  32. :link="link"
  33. :external="link && linkExternal"
  34. class="block cursor-pointer leading-snug hover:no-underline focus-visible:!outline-none"
  35. data-test-id="popover-menu-item"
  36. >
  37. <slot name="leading" />
  38. <CommonLabel
  39. class="gap-2"
  40. :class="[labelClass, variantClass]"
  41. :prefix-icon="icon"
  42. :icon-color="iconColor"
  43. >
  44. <slot>{{ i18n.t(label, ...(labelPlaceholder || [])) }}</slot>
  45. </CommonLabel>
  46. </component>
  47. </template>