sprintify-ui 0.11.23 → 0.11.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,5 +3,5 @@ type ReturnType = UseFloatingReturn & {
|
|
|
3
3
|
showTooltip: Ref<boolean>;
|
|
4
4
|
};
|
|
5
5
|
import { Ref } from "vue";
|
|
6
|
-
declare function useTooltip(reference: Readonly<Ref<MaybeElement<any>>>, floating: Readonly<Ref<MaybeElement<HTMLElement>>>, interactive?: boolean, delay?: number, options?: UseFloatingOptions | undefined, offset?: number): ReturnType;
|
|
6
|
+
declare function useTooltip(reference: Readonly<Ref<MaybeElement<any>>>, floating: Readonly<Ref<MaybeElement<HTMLElement>>>, interactive?: boolean, delay?: number, options?: UseFloatingOptions | undefined, offset?: number, arrowRef?: Readonly<Ref<MaybeElement<HTMLElement>>>): ReturnType;
|
|
7
7
|
export { useTooltip };
|
package/package.json
CHANGED
|
@@ -5,9 +5,6 @@ import { BaseCardRow } from "."
|
|
|
5
5
|
export default {
|
|
6
6
|
title: "Components/BaseTooltip",
|
|
7
7
|
component: BaseTooltip,
|
|
8
|
-
args: {
|
|
9
|
-
text: "Click here to learn more about this button",
|
|
10
|
-
},
|
|
11
8
|
};
|
|
12
9
|
|
|
13
10
|
const Template = (args) => ({
|
|
@@ -22,8 +19,16 @@ const Template = (args) => ({
|
|
|
22
19
|
template: `
|
|
23
20
|
<BaseCard>
|
|
24
21
|
<BaseCardRow size=sm>
|
|
25
|
-
<BaseTooltip class="inline-block"
|
|
26
|
-
<div>
|
|
22
|
+
<BaseTooltip class="inline-block" text="test 1" v-bind="args">
|
|
23
|
+
<div>TEST 1</div>
|
|
24
|
+
</BaseTooltip>
|
|
25
|
+
|
|
26
|
+
<BaseTooltip class="inline-block" text="test 2" v-bind="args">
|
|
27
|
+
<div>TEST 2</div>
|
|
28
|
+
</BaseTooltip>
|
|
29
|
+
|
|
30
|
+
<BaseTooltip class="inline-block" text="test 3" v-bind="args">
|
|
31
|
+
<div>TEST 3</div>
|
|
27
32
|
</BaseTooltip>
|
|
28
33
|
</BaseCardRow>
|
|
29
34
|
</BaseCard>
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
:style="floatingStyles"
|
|
16
16
|
>
|
|
17
17
|
<transition
|
|
18
|
-
enter-active-class="transition duration-
|
|
18
|
+
enter-active-class="transition duration-100 ease-out"
|
|
19
19
|
enter-from-class="transform scale-90 opacity-0"
|
|
20
20
|
enter-to-class="transform scale-100 opacity-100"
|
|
21
|
-
leave-active-class="transition duration-
|
|
21
|
+
leave-active-class="transition duration-0 ease-in"
|
|
22
22
|
leave-from-class="transform scale-100 opacity-100"
|
|
23
23
|
leave-to-class="transform scale-90 opacity-0"
|
|
24
24
|
>
|
|
@@ -26,13 +26,23 @@
|
|
|
26
26
|
v-if="showTooltip"
|
|
27
27
|
name="tooltip"
|
|
28
28
|
>
|
|
29
|
-
<div
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
<div class="relative filter drop-shadow-[0_1px_2px_rgba(0,0,0,0.1)]">
|
|
30
|
+
<div
|
|
31
|
+
class="text-xs max-w-xs leading-snug rounded-md pt-1.5 pb-2 px-3"
|
|
32
|
+
:class="[
|
|
33
|
+
dark ? 'bg-slate-900 text-white' : 'bg-white text-slate-900',
|
|
34
|
+
]"
|
|
35
|
+
v-html="text"
|
|
36
|
+
/>
|
|
37
|
+
<div
|
|
38
|
+
ref="arrowRef"
|
|
39
|
+
class="absolute w-2 h-2 rotate-45"
|
|
40
|
+
:class="[
|
|
41
|
+
dark ? 'bg-slate-900' : 'bg-white',
|
|
42
|
+
]"
|
|
43
|
+
:style="arrowStyles"
|
|
44
|
+
/>
|
|
45
|
+
</div>
|
|
36
46
|
</slot>
|
|
37
47
|
</transition>
|
|
38
48
|
</div>
|
|
@@ -64,12 +74,12 @@ const props = withDefaults(defineProps<{
|
|
|
64
74
|
text: null,
|
|
65
75
|
floatingOptions() {
|
|
66
76
|
return {
|
|
67
|
-
placement: 'top
|
|
77
|
+
placement: 'top',
|
|
68
78
|
};
|
|
69
79
|
},
|
|
70
80
|
interactive: false,
|
|
71
81
|
delay: 0,
|
|
72
|
-
dark:
|
|
82
|
+
dark: true,
|
|
73
83
|
offset: 6,
|
|
74
84
|
});
|
|
75
85
|
|
|
@@ -78,7 +88,26 @@ const targetRef = ref<HTMLElement | null>(null);
|
|
|
78
88
|
const targetInternal = computed(() => unrefElement(targetRef));
|
|
79
89
|
|
|
80
90
|
const tooltipRef = ref<HTMLElement | null>(null)
|
|
91
|
+
const arrowRef = ref<HTMLElement | null>(null)
|
|
81
92
|
|
|
82
|
-
const { floatingStyles, showTooltip } = useTooltip(targetInternal, tooltipRef, props.interactive, props.delay, props.floatingOptions, props.offset);
|
|
93
|
+
const { floatingStyles, showTooltip, middlewareData, placement } = useTooltip(targetInternal, tooltipRef, props.interactive, props.delay, props.floatingOptions, props.offset, arrowRef);
|
|
94
|
+
|
|
95
|
+
const arrowStyles = computed(() => {
|
|
96
|
+
const arrow = middlewareData.value.arrow;
|
|
97
|
+
const style: Record<string, string> = {};
|
|
98
|
+
|
|
99
|
+
if (arrow?.x != null) {
|
|
100
|
+
style.left = `${arrow.x}px`;
|
|
101
|
+
}
|
|
102
|
+
if (arrow?.y != null) {
|
|
103
|
+
style.top = `${arrow.y}px`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const side = placement.value.split('-')[0];
|
|
107
|
+
const staticSide = { top: 'bottom', right: 'left', bottom: 'top', left: 'right' }[side]!;
|
|
108
|
+
style[staticSide] = '-4px';
|
|
109
|
+
|
|
110
|
+
return style;
|
|
111
|
+
});
|
|
83
112
|
|
|
84
113
|
</script>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UseFloatingOptions, MaybeElement, UseFloatingReturn, autoUpdate, flip, offset as offset2, shift, useFloating } from "@floating-ui/vue";
|
|
1
|
+
import { UseFloatingOptions, MaybeElement, UseFloatingReturn, autoUpdate, flip, offset as offset2, shift, arrow, useFloating } from "@floating-ui/vue";
|
|
2
2
|
import { unrefElement, useEventListener, } from "@vueuse/core";
|
|
3
3
|
import { debounce } from "lodash";
|
|
4
4
|
|
|
@@ -15,6 +15,7 @@ function useTooltip(
|
|
|
15
15
|
delay: number = 0,
|
|
16
16
|
options: UseFloatingOptions | undefined = undefined,
|
|
17
17
|
offset: number = 6,
|
|
18
|
+
arrowRef?: Readonly<Ref<MaybeElement<HTMLElement>>>,
|
|
18
19
|
): ReturnType {
|
|
19
20
|
|
|
20
21
|
const show = ref(false);
|
|
@@ -36,15 +37,26 @@ function useTooltip(
|
|
|
36
37
|
|
|
37
38
|
useEventListener(elementRef, 'mouseleave', () => {
|
|
38
39
|
nextShow = false;
|
|
39
|
-
|
|
40
|
+
|
|
41
|
+
if (interactive) {
|
|
42
|
+
hideDebounce();
|
|
43
|
+
} else {
|
|
44
|
+
show.value = false;
|
|
45
|
+
}
|
|
40
46
|
});
|
|
41
47
|
|
|
42
48
|
useEventListener(floatingRef, 'mouseenter', () => {
|
|
43
49
|
if (!interactive) {
|
|
44
50
|
return;
|
|
45
51
|
}
|
|
52
|
+
|
|
46
53
|
nextShow = true;
|
|
47
|
-
|
|
54
|
+
|
|
55
|
+
if (interactive) {
|
|
56
|
+
showDebounce();
|
|
57
|
+
} else {
|
|
58
|
+
show.value = true;
|
|
59
|
+
}
|
|
48
60
|
});
|
|
49
61
|
|
|
50
62
|
useEventListener(floatingRef, 'mouseleave', () => {
|
|
@@ -67,11 +79,17 @@ function useTooltip(
|
|
|
67
79
|
return;
|
|
68
80
|
}
|
|
69
81
|
show.value = false;
|
|
70
|
-
},
|
|
82
|
+
}, 0);
|
|
83
|
+
|
|
84
|
+
const middleware = [offset2(offset), flip(), shift()];
|
|
85
|
+
|
|
86
|
+
if (arrowRef) {
|
|
87
|
+
middleware.push(arrow({ element: arrowRef }));
|
|
88
|
+
}
|
|
71
89
|
|
|
72
90
|
const config = {
|
|
73
91
|
placement: 'top',
|
|
74
|
-
middleware
|
|
92
|
+
middleware,
|
|
75
93
|
whileElementsMounted: autoUpdate,
|
|
76
94
|
};
|
|
77
95
|
|