Help.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <v-tooltip
  3. :value="show"
  4. :top="top"
  5. :bottom="bottom"
  6. :right="right"
  7. :left="leftOrDefault"
  8. :open-on-hover="false"
  9. :open-on-focus="false"
  10. :open-on-click="false"
  11. max-width="360px"
  12. >
  13. <template #activator="{}">
  14. <v-icon
  15. ref="iconRef"
  16. :icon="icon"
  17. class="ml-3"
  18. size="18px"
  19. @click="onIconClicked"
  20. />
  21. </template>
  22. <div ref="slotDiv" v-click-out="onClickOutside" class="tooltip">
  23. <slot />
  24. </div>
  25. </v-tooltip>
  26. </template>
  27. <script setup lang="ts">
  28. import type { Ref } from 'vue'
  29. const props = defineProps({
  30. left: {
  31. type: Boolean,
  32. required: false,
  33. default: false,
  34. },
  35. right: {
  36. type: Boolean,
  37. required: false,
  38. default: false,
  39. },
  40. top: {
  41. type: Boolean,
  42. required: false,
  43. default: false,
  44. },
  45. bottom: {
  46. type: Boolean,
  47. required: false,
  48. default: false,
  49. },
  50. icon: {
  51. type: String,
  52. required: false,
  53. default: 'mdi-help-circle',
  54. },
  55. })
  56. const { $refs } = useNuxtApp()
  57. const show: Ref<boolean> = ref(false)
  58. // Template reference to the icon object
  59. const iconRef = ref(null)
  60. // Left is the default, set it to true if not any other is true
  61. const leftOrDefault: Ref<boolean> = ref(
  62. props.left || (!props.right && !props.bottom && !props.top),
  63. )
  64. const onIconClicked = (e: MouseEvent) => {
  65. show.value = !show.value
  66. e.stopPropagation()
  67. }
  68. const onClickOutside = (e: MouseEvent) => {
  69. if (show.value) {
  70. if (e.target === (iconRef.value as { $el: HTMLElement }).$el) {
  71. return
  72. }
  73. show.value = false
  74. }
  75. }
  76. </script>
  77. <style>
  78. .v-icon {
  79. cursor: pointer;
  80. height: 18px;
  81. width: 18px;
  82. }
  83. .v-tooltip__content {
  84. pointer-events: all !important;
  85. }
  86. </style>