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. ref="iconRef"
  16. icon
  17. class="ml-3"
  18. size="18px"
  19. @click="onIconClicked"
  20. >
  21. {{ icon }}
  22. </v-icon>
  23. </template>
  24. <div ref="slotDiv" v-click-out="onClickOutside" class="tooltip">
  25. <slot/>
  26. </div>
  27. </v-tooltip>
  28. </template>
  29. <script setup lang="ts">
  30. import type { Ref } from 'vue'
  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(
  64. props.left || (!props.right && !props.bottom && !props.top),
  65. )
  66. const onIconClicked = (e: any) => {
  67. show.value = !show.value
  68. e.stopPropagation()
  69. }
  70. const onClickOutside = (e: any) => {
  71. if (show.value) {
  72. if (e.target === (iconRef.value as any).$el) {
  73. return
  74. }
  75. show.value = false
  76. }
  77. }
  78. </script>
  79. <style>
  80. .v-icon {
  81. cursor: pointer;
  82. height: 18px;
  83. width: 18px;
  84. }
  85. .v-tooltip__content {
  86. pointer-events: all !important;
  87. }
  88. </style>