CommonTooltip.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. // https://www.w3.org/WAI/ARIA/apg/patterns/tooltip/
  4. import { ref } from 'vue'
  5. import { useSharedVisualConfig } from '#shared/composables/useSharedVisualConfig.ts'
  6. import { useTooltipControls } from './useTooltipControls.ts'
  7. import type { TooltipItemDescriptor } from './types.ts'
  8. export interface Props {
  9. name: string
  10. heading?: string
  11. messages?: TooltipItemDescriptor[]
  12. }
  13. defineProps<Props>()
  14. const tooltipTriggerElement = ref<HTMLElement>()
  15. const { tooltip: tooltipConfig } = useSharedVisualConfig()
  16. const { tooltipVisible, showTooltip } = useTooltipControls(
  17. tooltipTriggerElement,
  18. tooltipConfig,
  19. )
  20. </script>
  21. <template>
  22. <div class="relative contents">
  23. <component
  24. :is="tooltipConfig.type === 'popup' ? 'button' : 'div'"
  25. ref="tooltipTriggerElement"
  26. data-test-id="tooltipTrigger"
  27. type="button"
  28. tabindex="0"
  29. :aria-describedby="`tooltip-${name}`"
  30. @click="tooltipConfig.type === 'popup' && showTooltip()"
  31. >
  32. <slot />
  33. </component>
  34. <component
  35. :is="tooltipConfig.component"
  36. :id="`tooltip-${name}`"
  37. v-model:state="tooltipVisible"
  38. :messages="messages"
  39. :heading="heading"
  40. />
  41. </div>
  42. </template>