quasar-ui-danx 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -0,0 +1,66 @@
|
|
1
|
+
<template>
|
2
|
+
<QTooltip
|
3
|
+
class="interactive-tooltip"
|
4
|
+
ref="tooltipBox"
|
5
|
+
v-model="show"
|
6
|
+
no-parent-event
|
7
|
+
@mouseenter="onEnterTooltip"
|
8
|
+
@mouseleave="onLeaveTooltip"
|
9
|
+
:transition-duration="200"
|
10
|
+
>
|
11
|
+
<slot>{{ tooltip }}</slot>
|
12
|
+
</QTooltip>
|
13
|
+
</template>
|
14
|
+
<script setup>
|
15
|
+
import { onMounted, ref } from 'vue';
|
16
|
+
|
17
|
+
defineProps({ tooltip: { type: String, default: '' } });
|
18
|
+
const show = ref(false);
|
19
|
+
const tooltipBox = ref(null);
|
20
|
+
const isHovering = ref(false);
|
21
|
+
const isHoveringParent = ref(false);
|
22
|
+
let timeout = null;
|
23
|
+
onMounted(() => {
|
24
|
+
tooltipBox.value.$el.parentNode.addEventListener('mouseover', onEnterParent);
|
25
|
+
tooltipBox.value.$el.parentNode.addEventListener('mouseleave', onLeaveParent);
|
26
|
+
});
|
27
|
+
function onEnterParent() {
|
28
|
+
show.value = true;
|
29
|
+
isHoveringParent.value = true;
|
30
|
+
if (timeout) clearTimeout(timeout);
|
31
|
+
}
|
32
|
+
function onLeaveParent() {
|
33
|
+
isHoveringParent.value = false;
|
34
|
+
if (show.value) delayClose();
|
35
|
+
}
|
36
|
+
function onEnterTooltip() {
|
37
|
+
isHovering.value = true;
|
38
|
+
show.value = true;
|
39
|
+
if (timeout) clearTimeout(timeout);
|
40
|
+
}
|
41
|
+
function onLeaveTooltip() {
|
42
|
+
isHovering.value = false;
|
43
|
+
if (show.value) delayClose();
|
44
|
+
}
|
45
|
+
function delayClose() {
|
46
|
+
if (timeout) clearTimeout(timeout);
|
47
|
+
timeout = setTimeout(() => {
|
48
|
+
if (isHovering.value || isHoveringParent.value) {
|
49
|
+
delayClose();
|
50
|
+
} else {
|
51
|
+
show.value = false;
|
52
|
+
}
|
53
|
+
}, 200);
|
54
|
+
}
|
55
|
+
|
56
|
+
</script>
|
57
|
+
<style lang="scss">
|
58
|
+
body .q-tooltip {
|
59
|
+
&.interactive-tooltip {
|
60
|
+
pointer-events: auto !important;
|
61
|
+
background: white;
|
62
|
+
color: inherit;
|
63
|
+
box-shadow: 0 0 10px 3px rgba(0, 0, 0, 0.2);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
</style>
|