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. @click="onIconClicked"
  16. icon
  17. class="ml-3"
  18. size="18px"
  19. ref="iconRef"
  20. >
  21. {{ icon }}
  22. </v-icon>
  23. </template>
  24. <div ref="slotDiv" class="tooltip" v-click-out="onClickOutside">
  25. <slot></slot>
  26. </div>
  27. </v-tooltip>
  28. </template>
  29. <script setup lang="ts">
  30. import type {Ref} from "@vue/reactivity";
  31. const props = defineProps({
  32. left: {
  33. type: Boolean,
  34. required: false,
  35. default: false
  36. },
  37. right: {
  38. type: Boolean,
  39. required: false,
  40. default: false
  41. },
  42. top: {
  43. type: Boolean,
  44. required: false,
  45. default: false
  46. },
  47. bottom: {
  48. type: Boolean,
  49. required: false,
  50. default: false
  51. },
  52. icon: {
  53. type: String,
  54. required: false,
  55. default: 'mdi-help-circle'
  56. }
  57. })
  58. const { $refs } = useNuxtApp()
  59. const show: Ref<Boolean> = ref(false)
  60. // Template reference to the icon object
  61. const iconRef = ref(null)
  62. // Left is the default, set it to true if not any other is true
  63. const leftOrDefault: Ref<Boolean> = ref(props.left || (!props.right && !props.bottom && !props.top))
  64. const onIconClicked = (e: any) => {
  65. show.value = !show.value
  66. e.stopPropagation()
  67. }
  68. const onClickOutside = (e: any) => {
  69. if (show.value) {
  70. if (e.target === (iconRef.value as any).$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>