Help.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 {useNuxtApp} from "#app";
  31. import {Ref} from "@vue/reactivity";
  32. const props = defineProps({
  33. left: {
  34. type: Boolean,
  35. required: false,
  36. default: false
  37. },
  38. right: {
  39. type: Boolean,
  40. required: false,
  41. default: false
  42. },
  43. top: {
  44. type: Boolean,
  45. required: false,
  46. default: false
  47. },
  48. bottom: {
  49. type: Boolean,
  50. required: false,
  51. default: false
  52. },
  53. icon: {
  54. type: String,
  55. required: false,
  56. default: 'mdi-help-circle'
  57. }
  58. })
  59. const { $refs } = useNuxtApp()
  60. const show: Ref<Boolean> = ref(false)
  61. // Template reference to the icon object
  62. const iconRef = ref(null)
  63. // Left is the default, set it to true if not any other is true
  64. const leftOrDefault: Ref<Boolean> = ref(props.left || (!props.right && !props.bottom && !props.top))
  65. const onIconClicked = (e: any) => {
  66. show.value = !show.value
  67. e.stopPropagation()
  68. }
  69. const onClickOutside = (e: any) => {
  70. if (show.value) {
  71. if (e.target === (iconRef.value as any).$el) {
  72. return
  73. }
  74. show.value = false
  75. }
  76. }
  77. </script>
  78. <style>
  79. .v-icon {
  80. cursor: pointer;
  81. height: 18px;
  82. width: 18px;
  83. }
  84. .v-tooltip__content {
  85. pointer-events: all !important;
  86. }
  87. </style>