sprintify-ui 0.11.24 → 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
|
@@ -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>
|
|
@@ -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);
|
|
@@ -80,9 +81,15 @@ function useTooltip(
|
|
|
80
81
|
show.value = false;
|
|
81
82
|
}, 0);
|
|
82
83
|
|
|
84
|
+
const middleware = [offset2(offset), flip(), shift()];
|
|
85
|
+
|
|
86
|
+
if (arrowRef) {
|
|
87
|
+
middleware.push(arrow({ element: arrowRef }));
|
|
88
|
+
}
|
|
89
|
+
|
|
83
90
|
const config = {
|
|
84
91
|
placement: 'top',
|
|
85
|
-
middleware
|
|
92
|
+
middleware,
|
|
86
93
|
whileElementsMounted: autoUpdate,
|
|
87
94
|
};
|
|
88
95
|
|