Help.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 lang="ts">
  30. import { defineComponent, ref, Ref } from '@nuxtjs/composition-api'
  31. export default defineComponent({
  32. props: {
  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. setup(props, $refs) {
  60. const show: Ref<Boolean> = ref(false)
  61. // template reference to the icon object
  62. const iconRef = ref(null)
  63. // Because left is the default direction, this property will return true if
  64. // left has been defined in the props, or if no other direction has been given
  65. const leftOrDefault: Ref<Boolean> = ref(props.left || (!props.right && !props.bottom && !props.top))
  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. return {
  79. iconRef,
  80. leftOrDefault,
  81. show,
  82. onIconClicked,
  83. onClickOutside
  84. }
  85. }
  86. })
  87. </script>
  88. <style>
  89. .v-icon {
  90. cursor: pointer;
  91. height: 18px;
  92. width: 18px;
  93. }
  94. .v-tooltip__content {
  95. pointer-events: all !important;
  96. }
  97. </style>