@destyler/tooltip 0.0.3 → 0.0.5
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.
- package/README.md +7 -0
- package/dist/component.cjs +369 -360
- package/dist/component.d.cts +438 -58
- package/dist/component.d.mts +438 -58
- package/dist/component.d.ts +438 -58
- package/dist/component.mjs +359 -360
- package/dist/index.cjs +13 -7
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/resolver.cjs +8 -8
- package/dist/resolver.d.cts +2 -2
- package/dist/resolver.d.mts +2 -2
- package/dist/resolver.d.ts +2 -2
- package/dist/resolver.mjs +8 -8
- package/dist/shared/tooltip.6a045e60.d.cts +1047 -0
- package/dist/shared/tooltip.6a045e60.d.mts +1047 -0
- package/dist/shared/tooltip.6a045e60.d.ts +1047 -0
- package/package.json +18 -20
- package/dist/shared/tooltip.79d8523b.d.cts +0 -600
- package/dist/shared/tooltip.79d8523b.d.mts +0 -600
- package/dist/shared/tooltip.79d8523b.d.ts +0 -600
package/dist/component.mjs
CHANGED
|
@@ -1,182 +1,102 @@
|
|
|
1
|
-
import { defineComponent, h, mergeProps, toRefs, ref, computed, watch, useSlots, onMounted,
|
|
2
|
-
import {
|
|
3
|
-
import { useTimeoutFn, useVModel,
|
|
4
|
-
import { createContext
|
|
1
|
+
import { defineComponent, h, mergeProps, toRefs, ref, computed, watch, useSlots, onMounted, withModifiers } from 'vue';
|
|
2
|
+
import { popperArrowProps, PopperArrow, PopperRoot, popperContentProps, PopperContent, PopperAnchor } from '@destyler/popper';
|
|
3
|
+
import { useForwardExpose, useTimeoutFn, useVModel, useForwardProps, useGraceArea, useForwardPropsEmits, useId } from '@destyler/composition';
|
|
4
|
+
import { createContext } from '@destyler/shared';
|
|
5
|
+
import { primitiveProps, Primitive } from '@destyler/primitive';
|
|
5
6
|
import { useEventListener } from '@vueuse/core';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { DestylerPrimitive } from '@destyler/primitive';
|
|
7
|
+
import { DismissableLayer } from '@destyler/dismissable-layer';
|
|
8
|
+
import { VisuallyHidden } from '@destyler/visually-hidden';
|
|
9
|
+
import { teleportPrimitiveProps, TeleportPrimitive } from '@destyler/teleport';
|
|
10
10
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
type: [String, Object],
|
|
14
|
-
required: false,
|
|
15
|
-
default: "div"
|
|
16
|
-
},
|
|
17
|
-
asChild: {
|
|
18
|
-
type: Boolean,
|
|
19
|
-
required: false,
|
|
20
|
-
default: false
|
|
21
|
-
},
|
|
22
|
-
width: {
|
|
23
|
-
type: Number,
|
|
24
|
-
required: false,
|
|
25
|
-
default: 10
|
|
26
|
-
},
|
|
27
|
-
height: {
|
|
28
|
-
type: Number,
|
|
29
|
-
required: false,
|
|
30
|
-
default: 5
|
|
31
|
-
}
|
|
11
|
+
const tooltipArrowProps = {
|
|
12
|
+
...popperArrowProps
|
|
32
13
|
};
|
|
33
|
-
const
|
|
14
|
+
const TooltipArrow = defineComponent({
|
|
34
15
|
name: "DestylerTooltipArrow",
|
|
35
|
-
props:
|
|
16
|
+
props: tooltipArrowProps,
|
|
17
|
+
setup() {
|
|
18
|
+
useForwardExpose();
|
|
19
|
+
},
|
|
36
20
|
render() {
|
|
37
|
-
return h(
|
|
21
|
+
return h(PopperArrow, mergeProps(this.$props), () => this.$slots.default?.());
|
|
38
22
|
}
|
|
39
23
|
});
|
|
40
24
|
|
|
41
25
|
const TOOLTIP_OPEN = "tooltip.open";
|
|
42
|
-
function getExitSideFromRect(point, rect) {
|
|
43
|
-
const top = Math.abs(rect.top - point.y);
|
|
44
|
-
const bottom = Math.abs(rect.bottom - point.y);
|
|
45
|
-
const right = Math.abs(rect.right - point.x);
|
|
46
|
-
const left = Math.abs(rect.left - point.x);
|
|
47
|
-
switch (Math.min(top, bottom, right, left)) {
|
|
48
|
-
case left:
|
|
49
|
-
return "left";
|
|
50
|
-
case right:
|
|
51
|
-
return "right";
|
|
52
|
-
case top:
|
|
53
|
-
return "top";
|
|
54
|
-
case bottom:
|
|
55
|
-
return "bottom";
|
|
56
|
-
default:
|
|
57
|
-
throw new Error("unreachable");
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function getPaddedExitPoints(exitPoint, exitSide, padding = 5) {
|
|
61
|
-
const paddedExitPoints = [];
|
|
62
|
-
switch (exitSide) {
|
|
63
|
-
case "top":
|
|
64
|
-
paddedExitPoints.push(
|
|
65
|
-
{ x: exitPoint.x - padding, y: exitPoint.y + padding },
|
|
66
|
-
{ x: exitPoint.x + padding, y: exitPoint.y + padding }
|
|
67
|
-
);
|
|
68
|
-
break;
|
|
69
|
-
case "bottom":
|
|
70
|
-
paddedExitPoints.push(
|
|
71
|
-
{ x: exitPoint.x - padding, y: exitPoint.y - padding },
|
|
72
|
-
{ x: exitPoint.x + padding, y: exitPoint.y - padding }
|
|
73
|
-
);
|
|
74
|
-
break;
|
|
75
|
-
case "left":
|
|
76
|
-
paddedExitPoints.push(
|
|
77
|
-
{ x: exitPoint.x + padding, y: exitPoint.y - padding },
|
|
78
|
-
{ x: exitPoint.x + padding, y: exitPoint.y + padding }
|
|
79
|
-
);
|
|
80
|
-
break;
|
|
81
|
-
case "right":
|
|
82
|
-
paddedExitPoints.push(
|
|
83
|
-
{ x: exitPoint.x - padding, y: exitPoint.y - padding },
|
|
84
|
-
{ x: exitPoint.x - padding, y: exitPoint.y + padding }
|
|
85
|
-
);
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
return paddedExitPoints;
|
|
89
|
-
}
|
|
90
|
-
function getPointsFromRect(rect) {
|
|
91
|
-
const { top, right, bottom, left } = rect;
|
|
92
|
-
return [
|
|
93
|
-
{ x: left, y: top },
|
|
94
|
-
{ x: right, y: top },
|
|
95
|
-
{ x: right, y: bottom },
|
|
96
|
-
{ x: left, y: bottom }
|
|
97
|
-
];
|
|
98
|
-
}
|
|
99
|
-
function getHull(points) {
|
|
100
|
-
const newPoints = points.slice();
|
|
101
|
-
newPoints.sort((a, b) => {
|
|
102
|
-
if (a.x < b.x)
|
|
103
|
-
return -1;
|
|
104
|
-
else if (a.x > b.x)
|
|
105
|
-
return 1;
|
|
106
|
-
else if (a.y < b.y)
|
|
107
|
-
return -1;
|
|
108
|
-
else if (a.y > b.y)
|
|
109
|
-
return 1;
|
|
110
|
-
else
|
|
111
|
-
return 0;
|
|
112
|
-
});
|
|
113
|
-
return getHullPresorted(newPoints);
|
|
114
|
-
}
|
|
115
|
-
function getHullPresorted(points) {
|
|
116
|
-
if (points.length <= 1)
|
|
117
|
-
return points.slice();
|
|
118
|
-
const upperHull = [];
|
|
119
|
-
for (let i = 0; i < points.length; i++) {
|
|
120
|
-
const p = points[i];
|
|
121
|
-
while (upperHull.length >= 2) {
|
|
122
|
-
const q = upperHull[upperHull.length - 1];
|
|
123
|
-
const r = upperHull[upperHull.length - 2];
|
|
124
|
-
if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x))
|
|
125
|
-
upperHull.pop();
|
|
126
|
-
else
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
upperHull.push(p);
|
|
130
|
-
}
|
|
131
|
-
upperHull.pop();
|
|
132
|
-
const lowerHull = [];
|
|
133
|
-
for (let i = points.length - 1; i >= 0; i--) {
|
|
134
|
-
const p = points[i];
|
|
135
|
-
while (lowerHull.length >= 2) {
|
|
136
|
-
const q = lowerHull[lowerHull.length - 1];
|
|
137
|
-
const r = lowerHull[lowerHull.length - 2];
|
|
138
|
-
if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x))
|
|
139
|
-
lowerHull.pop();
|
|
140
|
-
else
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
lowerHull.push(p);
|
|
144
|
-
}
|
|
145
|
-
lowerHull.pop();
|
|
146
|
-
if (upperHull.length === 1 && lowerHull.length === 1 && upperHull[0].x === lowerHull[0].x && upperHull[0].y === lowerHull[0].y)
|
|
147
|
-
return upperHull;
|
|
148
|
-
else
|
|
149
|
-
return upperHull.concat(lowerHull);
|
|
150
|
-
}
|
|
151
26
|
|
|
152
|
-
const
|
|
27
|
+
const tooltipProviderProps = {
|
|
28
|
+
/**
|
|
29
|
+
* The duration from when the pointer enters the trigger until the tooltip gets opened.
|
|
30
|
+
*
|
|
31
|
+
* @default 700
|
|
32
|
+
*/
|
|
153
33
|
delayDuration: {
|
|
154
34
|
type: Number,
|
|
155
35
|
required: false,
|
|
156
36
|
default: 700
|
|
157
37
|
},
|
|
38
|
+
/**
|
|
39
|
+
* How much time a user has to enter another trigger without incurring a delay again.
|
|
40
|
+
*
|
|
41
|
+
* @default 300
|
|
42
|
+
*/
|
|
158
43
|
skipDelayDuration: {
|
|
159
44
|
type: Number,
|
|
160
45
|
required: false,
|
|
161
46
|
default: 300
|
|
162
47
|
},
|
|
48
|
+
/**
|
|
49
|
+
* When `true`, trying to hover the content will result in the tooltip closing as the pointer leaves the trigger.
|
|
50
|
+
*
|
|
51
|
+
* @default false
|
|
52
|
+
*/
|
|
163
53
|
disableHoverableContent: {
|
|
164
54
|
type: Boolean,
|
|
165
55
|
required: false,
|
|
166
56
|
default: false
|
|
167
57
|
},
|
|
58
|
+
/**
|
|
59
|
+
* When `true`, clicking on trigger will not close the content.
|
|
60
|
+
*
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
168
63
|
disableClosingTrigger: {
|
|
169
64
|
type: Boolean,
|
|
170
65
|
required: false,
|
|
171
66
|
default: false
|
|
67
|
+
},
|
|
68
|
+
/**
|
|
69
|
+
* When `true`, disable tooltip
|
|
70
|
+
*
|
|
71
|
+
* @default false
|
|
72
|
+
*/
|
|
73
|
+
disabled: {
|
|
74
|
+
type: Boolean,
|
|
75
|
+
required: false,
|
|
76
|
+
default: false
|
|
77
|
+
},
|
|
78
|
+
/**
|
|
79
|
+
* Prevent the tooltip from opening if the focus did not come from
|
|
80
|
+
* the keyboard by matching against the `:focus-visible` selector.
|
|
81
|
+
* This is useful if you want to avoid opening it when switching
|
|
82
|
+
* browser tabs or closing a dialog.
|
|
83
|
+
*
|
|
84
|
+
* @default false
|
|
85
|
+
*/
|
|
86
|
+
ignoreNonKeyboardFocus: {
|
|
87
|
+
type: Boolean,
|
|
88
|
+
required: false,
|
|
89
|
+
default: false
|
|
172
90
|
}
|
|
173
91
|
};
|
|
174
92
|
const [injectTooltipProviderContext, provideTooltipProviderContext] = createContext("DestylerTooltipProvider");
|
|
175
|
-
const
|
|
93
|
+
const TooltipProvider = defineComponent({
|
|
176
94
|
name: "DestylerTooltipProvider",
|
|
177
|
-
|
|
95
|
+
inheritAttrs: false,
|
|
96
|
+
props: tooltipProviderProps,
|
|
178
97
|
setup(props) {
|
|
179
|
-
const { delayDuration, skipDelayDuration, disableHoverableContent, disableClosingTrigger } = toRefs(props);
|
|
98
|
+
const { delayDuration, skipDelayDuration, disableHoverableContent, disableClosingTrigger, ignoreNonKeyboardFocus, disabled } = toRefs(props);
|
|
99
|
+
useForwardExpose();
|
|
180
100
|
const isOpenDelayed = ref(true);
|
|
181
101
|
const isPointerInTransitRef = ref(false);
|
|
182
102
|
const { start: startTimer, stop: clearTimer } = useTimeoutFn(() => {
|
|
@@ -193,11 +113,10 @@ const DestylerTooltipProvider = defineComponent({
|
|
|
193
113
|
startTimer();
|
|
194
114
|
},
|
|
195
115
|
isPointerInTransitRef,
|
|
196
|
-
onPointerInTransitChange(inTransit) {
|
|
197
|
-
isPointerInTransitRef.value = inTransit;
|
|
198
|
-
},
|
|
199
116
|
disableHoverableContent,
|
|
200
|
-
disableClosingTrigger
|
|
117
|
+
disableClosingTrigger,
|
|
118
|
+
disabled,
|
|
119
|
+
ignoreNonKeyboardFocus
|
|
201
120
|
});
|
|
202
121
|
},
|
|
203
122
|
render() {
|
|
@@ -205,50 +124,105 @@ const DestylerTooltipProvider = defineComponent({
|
|
|
205
124
|
}
|
|
206
125
|
});
|
|
207
126
|
|
|
208
|
-
const
|
|
127
|
+
const tooltipRootProps = {
|
|
128
|
+
/**
|
|
129
|
+
* The open state of the tooltip when it is initially rendered.
|
|
130
|
+
* Use when you do not need to control its open state.
|
|
131
|
+
*
|
|
132
|
+
* @default false
|
|
133
|
+
*/
|
|
209
134
|
defaultOpen: {
|
|
210
135
|
type: Boolean,
|
|
211
136
|
required: false,
|
|
212
137
|
default: false
|
|
213
138
|
},
|
|
139
|
+
/**
|
|
140
|
+
* The controlled open state of the tooltip.
|
|
141
|
+
*/
|
|
214
142
|
open: {
|
|
215
143
|
type: Boolean,
|
|
216
144
|
required: false,
|
|
217
145
|
default: void 0
|
|
218
146
|
},
|
|
147
|
+
/**
|
|
148
|
+
* Override the duration given to the `Provider` to customise
|
|
149
|
+
* the open delay for a specific tooltip.
|
|
150
|
+
*
|
|
151
|
+
* @default 400
|
|
152
|
+
*/
|
|
219
153
|
delayDuration: {
|
|
220
154
|
type: Number,
|
|
221
155
|
required: false,
|
|
222
156
|
default: 400
|
|
223
157
|
},
|
|
158
|
+
/**
|
|
159
|
+
* Prevents Tooltip.Content from remaining open when hovering.
|
|
160
|
+
* Disabling this has accessibility consequences. Inherits
|
|
161
|
+
* from Tooltip.Provider.
|
|
162
|
+
*/
|
|
224
163
|
disableHoverableContent: {
|
|
225
164
|
type: Boolean,
|
|
226
165
|
required: false,
|
|
227
166
|
default: void 0
|
|
228
167
|
},
|
|
168
|
+
/**
|
|
169
|
+
* When `true`, clicking on trigger will not close the content.
|
|
170
|
+
*
|
|
171
|
+
* @default false
|
|
172
|
+
*/
|
|
229
173
|
disableClosingTrigger: {
|
|
230
174
|
type: Boolean,
|
|
231
175
|
required: false,
|
|
232
176
|
default: void 0
|
|
177
|
+
},
|
|
178
|
+
/**
|
|
179
|
+
* When `true`, disable tooltip
|
|
180
|
+
*
|
|
181
|
+
* @default false
|
|
182
|
+
*/
|
|
183
|
+
disabled: {
|
|
184
|
+
type: Boolean,
|
|
185
|
+
required: false,
|
|
186
|
+
default: void 0
|
|
187
|
+
},
|
|
188
|
+
/**
|
|
189
|
+
* Prevent the tooltip from opening if the focus did not come from
|
|
190
|
+
* the keyboard by matching against the `:focus-visible` selector.
|
|
191
|
+
* This is useful if you want to avoid opening it when switching
|
|
192
|
+
* browser tabs or closing a dialog.
|
|
193
|
+
*
|
|
194
|
+
* @default false
|
|
195
|
+
*/
|
|
196
|
+
ignoreNonKeyboardFocus: {
|
|
197
|
+
type: Boolean,
|
|
198
|
+
required: false,
|
|
199
|
+
default: void 0
|
|
233
200
|
}
|
|
234
201
|
};
|
|
202
|
+
const tooltipRootEmits = {
|
|
203
|
+
/**
|
|
204
|
+
* Event handler called when the open state of the tooltip changes.
|
|
205
|
+
*/
|
|
206
|
+
"update:open": (_value) => true
|
|
207
|
+
};
|
|
235
208
|
const [injectTooltipRootContext, provideTooltipRootContext] = createContext("DestylerTooltipRoot");
|
|
236
|
-
const
|
|
209
|
+
const TooltipRoot = defineComponent({
|
|
237
210
|
name: "DestylerTooltipRoot",
|
|
238
|
-
props:
|
|
239
|
-
emits:
|
|
211
|
+
props: tooltipRootProps,
|
|
212
|
+
emits: tooltipRootEmits,
|
|
240
213
|
setup(props, { emit }) {
|
|
214
|
+
useForwardExpose();
|
|
241
215
|
const providerContext = injectTooltipProviderContext();
|
|
242
|
-
const disableHoverableContent = computed(() =>
|
|
243
|
-
return props.disableHoverableContent ?? providerContext.disableHoverableContent.value;
|
|
244
|
-
});
|
|
216
|
+
const disableHoverableContent = computed(() => props.disableHoverableContent ?? providerContext.disableHoverableContent.value);
|
|
245
217
|
const disableClosingTrigger = computed(() => props.disableClosingTrigger ?? providerContext.disableClosingTrigger.value);
|
|
218
|
+
const disableTooltip = computed(() => props.disabled ?? providerContext.disabled.value);
|
|
246
219
|
const delayDuration = computed(() => props.delayDuration ?? providerContext.delayDuration.value);
|
|
247
|
-
const
|
|
220
|
+
const ignoreNonKeyboardFocus = computed(() => props.ignoreNonKeyboardFocus ?? providerContext.ignoreNonKeyboardFocus.value);
|
|
221
|
+
const open = useVModel(props, "open", emit, {
|
|
248
222
|
defaultValue: props.defaultOpen,
|
|
249
223
|
passive: props.open === void 0
|
|
250
224
|
});
|
|
251
|
-
watch(
|
|
225
|
+
watch(open, (isOpen) => {
|
|
252
226
|
if (!providerContext.onClose)
|
|
253
227
|
return;
|
|
254
228
|
if (isOpen) {
|
|
@@ -261,29 +235,29 @@ const DestylerTooltipRoot = defineComponent({
|
|
|
261
235
|
const wasOpenDelayedRef = ref(false);
|
|
262
236
|
const trigger = ref();
|
|
263
237
|
const stateAttribute = computed(() => {
|
|
264
|
-
if (!
|
|
238
|
+
if (!open.value)
|
|
265
239
|
return "closed";
|
|
266
240
|
return wasOpenDelayedRef.value ? "delayed-open" : "instant-open";
|
|
267
241
|
});
|
|
268
242
|
const { start: startTimer, stop: clearTimer } = useTimeoutFn(() => {
|
|
269
243
|
wasOpenDelayedRef.value = true;
|
|
270
|
-
|
|
244
|
+
open.value = true;
|
|
271
245
|
}, delayDuration, { immediate: false });
|
|
272
246
|
function handleOpen() {
|
|
273
247
|
clearTimer();
|
|
274
248
|
wasOpenDelayedRef.value = false;
|
|
275
|
-
|
|
249
|
+
open.value = true;
|
|
276
250
|
}
|
|
277
251
|
function handleClose() {
|
|
278
252
|
clearTimer();
|
|
279
|
-
|
|
253
|
+
open.value = false;
|
|
280
254
|
}
|
|
281
255
|
function handleDelayedOpen() {
|
|
282
256
|
startTimer();
|
|
283
257
|
}
|
|
284
258
|
provideTooltipRootContext({
|
|
285
|
-
contentId:
|
|
286
|
-
open
|
|
259
|
+
contentId: "",
|
|
260
|
+
open,
|
|
287
261
|
stateAttribute,
|
|
288
262
|
trigger,
|
|
289
263
|
onTriggerChange(el) {
|
|
@@ -296,96 +270,150 @@ const DestylerTooltipRoot = defineComponent({
|
|
|
296
270
|
handleOpen();
|
|
297
271
|
},
|
|
298
272
|
onTriggerLeave() {
|
|
299
|
-
if (disableHoverableContent.value)
|
|
273
|
+
if (disableHoverableContent.value) {
|
|
300
274
|
handleClose();
|
|
301
|
-
else
|
|
275
|
+
} else {
|
|
302
276
|
clearTimer();
|
|
277
|
+
}
|
|
303
278
|
},
|
|
304
279
|
onOpen: handleOpen,
|
|
305
280
|
onClose: handleClose,
|
|
306
281
|
disableHoverableContent,
|
|
307
|
-
disableClosingTrigger
|
|
282
|
+
disableClosingTrigger,
|
|
283
|
+
disabled: disableTooltip,
|
|
284
|
+
ignoreNonKeyboardFocus
|
|
308
285
|
});
|
|
309
286
|
},
|
|
310
287
|
render() {
|
|
311
|
-
return h(
|
|
288
|
+
return h(PopperRoot, null, () => this.$slots.default?.());
|
|
312
289
|
}
|
|
313
290
|
});
|
|
314
291
|
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
default: false
|
|
325
|
-
},
|
|
292
|
+
const tooltipContentImplProps = {
|
|
293
|
+
...primitiveProps,
|
|
294
|
+
/**
|
|
295
|
+
* The preferred side of the trigger to render against when open.
|
|
296
|
+
* Will be reversed when collisions occur and avoidCollisions
|
|
297
|
+
* is enabled.
|
|
298
|
+
*
|
|
299
|
+
* @default top
|
|
300
|
+
*/
|
|
326
301
|
side: {
|
|
327
|
-
|
|
328
|
-
required: false,
|
|
302
|
+
...popperContentProps.side,
|
|
329
303
|
default: "top"
|
|
330
304
|
},
|
|
305
|
+
/**
|
|
306
|
+
* The distance in pixels from the trigger.
|
|
307
|
+
*
|
|
308
|
+
* @default 0
|
|
309
|
+
*/
|
|
331
310
|
sideOffset: {
|
|
332
|
-
|
|
333
|
-
required: false,
|
|
334
|
-
default: 0
|
|
311
|
+
...popperContentProps.sideOffset
|
|
335
312
|
},
|
|
313
|
+
/**
|
|
314
|
+
* The preferred alignment against the trigger.
|
|
315
|
+
* May change when collisions occur.
|
|
316
|
+
*
|
|
317
|
+
* @default center
|
|
318
|
+
*/
|
|
336
319
|
align: {
|
|
337
|
-
|
|
338
|
-
required: false,
|
|
339
|
-
default: "center"
|
|
320
|
+
...popperContentProps.align
|
|
340
321
|
},
|
|
322
|
+
/**
|
|
323
|
+
* An offset in pixels from the `start` or `end` alignment options.
|
|
324
|
+
*
|
|
325
|
+
* @default 0
|
|
326
|
+
*/
|
|
341
327
|
alignOffset: {
|
|
342
|
-
|
|
343
|
-
required: false,
|
|
344
|
-
default: 0
|
|
328
|
+
...popperContentProps.alignOffset
|
|
345
329
|
},
|
|
330
|
+
/**
|
|
331
|
+
* When `true`, overrides the side andalign preferences
|
|
332
|
+
* to prevent collisions with boundary edges.
|
|
333
|
+
*
|
|
334
|
+
* @default true
|
|
335
|
+
*/
|
|
346
336
|
avoidCollisions: {
|
|
347
|
-
|
|
348
|
-
required: false,
|
|
349
|
-
default: true
|
|
337
|
+
...popperContentProps.avoidCollisions
|
|
350
338
|
},
|
|
339
|
+
/**
|
|
340
|
+
* The element used as the collision boundary. By default
|
|
341
|
+
* this is the viewport, though you can provide additional
|
|
342
|
+
* element(s) to be included in this check.
|
|
343
|
+
*
|
|
344
|
+
* @default () => []
|
|
345
|
+
*/
|
|
351
346
|
collisionBoundary: {
|
|
352
|
-
|
|
353
|
-
required: false,
|
|
354
|
-
default: () => []
|
|
347
|
+
...popperContentProps.collisionBoundary
|
|
355
348
|
},
|
|
349
|
+
/**
|
|
350
|
+
* The distance in pixels from the boundary edges where collision
|
|
351
|
+
* detection should occur. Accepts a number (same for all sides),
|
|
352
|
+
* or a partial padding object, for example: { top: 20, left: 20 }.
|
|
353
|
+
*
|
|
354
|
+
* @default 0
|
|
355
|
+
*/
|
|
356
356
|
collisionPadding: {
|
|
357
|
-
|
|
358
|
-
required: false,
|
|
359
|
-
default: 0
|
|
357
|
+
...popperContentProps.collisionPadding
|
|
360
358
|
},
|
|
359
|
+
/**
|
|
360
|
+
* The distance in pixels from the boundary edges where collision
|
|
361
|
+
* detection should occur. Accepts a number (same for all sides),
|
|
362
|
+
* or a partial padding object, for example: { top: 20, left: 20 }.
|
|
363
|
+
*
|
|
364
|
+
* @default 0
|
|
365
|
+
*/
|
|
361
366
|
arrowPadding: {
|
|
362
|
-
|
|
363
|
-
required: false,
|
|
364
|
-
default: 0
|
|
367
|
+
...popperContentProps.arrowPadding
|
|
365
368
|
},
|
|
369
|
+
/**
|
|
370
|
+
* The sticky behavior on the align axis. `partial` will keep the
|
|
371
|
+
* content in the boundary as long as the trigger is at least partially
|
|
372
|
+
* in the boundary whilst "always" will keep the content in the boundary
|
|
373
|
+
* regardless.
|
|
374
|
+
*
|
|
375
|
+
* @default partial
|
|
376
|
+
*/
|
|
366
377
|
sticky: {
|
|
367
|
-
|
|
368
|
-
required: false,
|
|
369
|
-
default: "partial"
|
|
378
|
+
...popperContentProps.sticky
|
|
370
379
|
},
|
|
380
|
+
/**
|
|
381
|
+
* Whether to hide the content when the trigger becomes fully occluded.
|
|
382
|
+
*
|
|
383
|
+
* @default false
|
|
384
|
+
*/
|
|
371
385
|
hideWhenDetached: {
|
|
372
|
-
|
|
373
|
-
required: false,
|
|
374
|
-
default: false
|
|
386
|
+
...popperContentProps.hideWhenDetached
|
|
375
387
|
},
|
|
388
|
+
/**
|
|
389
|
+
* By default, screenreaders will announce the content inside
|
|
390
|
+
* the component. If this is not descriptive enough, or you have
|
|
391
|
+
* content that cannot be announced, use aria-label as a more
|
|
392
|
+
* descriptive label.
|
|
393
|
+
*
|
|
394
|
+
*/
|
|
376
395
|
ariaLabel: {
|
|
377
396
|
type: String,
|
|
378
397
|
required: false
|
|
379
398
|
}
|
|
380
399
|
};
|
|
381
|
-
const
|
|
382
|
-
|
|
400
|
+
const tooltipContentImplEmits = {
|
|
401
|
+
/**
|
|
402
|
+
* Event handler called when focus moves to the destructive action after opening. It can be prevented by calling `event.preventDefault`
|
|
403
|
+
*/
|
|
404
|
+
escapeKeyDown: (_event) => true,
|
|
405
|
+
/**
|
|
406
|
+
* Event handler called when a pointer event occurs outside the bounds of the component. It can be prevented by calling `event.preventDefault`.
|
|
407
|
+
*/
|
|
408
|
+
pointerDownOutside: (_event) => true
|
|
409
|
+
};
|
|
410
|
+
const TooltipContentImpl = defineComponent({
|
|
383
411
|
name: "DestylerTooltipContentImpl",
|
|
384
|
-
props:
|
|
385
|
-
emits:
|
|
412
|
+
props: tooltipContentImplProps,
|
|
413
|
+
emits: tooltipContentImplEmits,
|
|
386
414
|
setup(props) {
|
|
387
|
-
const contentElement = ref();
|
|
388
415
|
const rootContext = injectTooltipRootContext();
|
|
416
|
+
const { forwardRef } = useForwardExpose();
|
|
389
417
|
const slot = useSlots();
|
|
390
418
|
const defaultSlot = computed(() => slot.default?.());
|
|
391
419
|
const ariaLabel = computed(() => {
|
|
@@ -401,7 +429,7 @@ const DestylerTooltipContentImpl = defineComponent({
|
|
|
401
429
|
defaultSlot.value?.forEach((node) => recursiveTextSearch(node));
|
|
402
430
|
return content;
|
|
403
431
|
});
|
|
404
|
-
const
|
|
432
|
+
const popperContentProps2 = computed(() => {
|
|
405
433
|
const { ariaLabel: _, ...restProps } = props;
|
|
406
434
|
return restProps;
|
|
407
435
|
});
|
|
@@ -414,14 +442,14 @@ const DestylerTooltipContentImpl = defineComponent({
|
|
|
414
442
|
useEventListener(window, TOOLTIP_OPEN, rootContext.onClose);
|
|
415
443
|
});
|
|
416
444
|
return {
|
|
417
|
-
contentElement,
|
|
418
445
|
rootContext,
|
|
419
|
-
popperContentProps,
|
|
420
|
-
ariaLabel
|
|
446
|
+
popperContentProps: popperContentProps2,
|
|
447
|
+
ariaLabel,
|
|
448
|
+
forwardRef
|
|
421
449
|
};
|
|
422
450
|
},
|
|
423
451
|
render() {
|
|
424
|
-
return h(
|
|
452
|
+
return h(DismissableLayer, {
|
|
425
453
|
asChild: true,
|
|
426
454
|
disableOutsidePointerEvents: false,
|
|
427
455
|
onEscapeKeyDown: (event) => {
|
|
@@ -432,164 +460,137 @@ const DestylerTooltipContentImpl = defineComponent({
|
|
|
432
460
|
event.preventDefault();
|
|
433
461
|
this.$emit("pointerDownOutside", event);
|
|
434
462
|
},
|
|
463
|
+
onFocusOutside: withModifiers(() => {
|
|
464
|
+
}, ["prevent"]),
|
|
435
465
|
onDismiss: () => {
|
|
436
466
|
this.rootContext.onClose();
|
|
437
467
|
}
|
|
438
|
-
}, () => h(
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
"
|
|
445
|
-
"
|
|
446
|
-
"
|
|
468
|
+
}, () => h(PopperContent, mergeProps(
|
|
469
|
+
{
|
|
470
|
+
...this.$attrs,
|
|
471
|
+
...this.popperContentProps
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
"ref": this.forwardRef,
|
|
475
|
+
"data-state": this.rootContext.stateAttribute.value,
|
|
476
|
+
"style": {
|
|
477
|
+
"--destyler-tooltip-content-transform-origin": "var(--destyler-popper-transform-origin)",
|
|
478
|
+
"--destyler-tooltip-content-available-width": "var(--destyler-popper-available-width)",
|
|
479
|
+
"--destyler-tooltip-content-available-height": "var(--destyler-popper-available-height)",
|
|
480
|
+
"--destyler-tooltip-trigger-width": "var(--destyler-popper-anchor-width)",
|
|
481
|
+
"--destyler-tooltip-trigger-height": "var(--destyler-popper-anchor-height)"
|
|
482
|
+
}
|
|
447
483
|
}
|
|
448
|
-
|
|
484
|
+
), () => [
|
|
449
485
|
this.$slots.default?.(),
|
|
450
|
-
h(
|
|
451
|
-
role: "tooltip"
|
|
486
|
+
h(VisuallyHidden, {
|
|
487
|
+
role: "tooltip",
|
|
488
|
+
id: this.rootContext.contentId
|
|
452
489
|
}, () => this.ariaLabel)
|
|
453
490
|
]));
|
|
454
491
|
}
|
|
455
492
|
});
|
|
456
493
|
|
|
457
|
-
const
|
|
494
|
+
const TooltipContentHoverable = defineComponent({
|
|
458
495
|
name: "DestylerTooltipContentHoverable",
|
|
459
|
-
props:
|
|
460
|
-
setup() {
|
|
496
|
+
props: tooltipContentImplProps,
|
|
497
|
+
setup(props) {
|
|
498
|
+
const forwardedProps = useForwardProps(props);
|
|
461
499
|
const { forwardRef, currentElement } = useForwardExpose();
|
|
462
500
|
const { trigger, onClose } = injectTooltipRootContext();
|
|
463
501
|
const providerContext = injectTooltipProviderContext();
|
|
464
|
-
const
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
}
|
|
469
|
-
function handleCreateGraceArea(event, hoverTarget) {
|
|
470
|
-
const currentTarget = event.currentTarget;
|
|
471
|
-
const exitPoint = { x: event.clientX, y: event.clientY };
|
|
472
|
-
const exitSide = getExitSideFromRect(exitPoint, currentTarget.getBoundingClientRect());
|
|
473
|
-
const paddedExitPoints = getPaddedExitPoints(exitPoint, exitSide);
|
|
474
|
-
const hoverTargetPoints = getPointsFromRect(hoverTarget.getBoundingClientRect());
|
|
475
|
-
const graceArea = getHull([...paddedExitPoints, ...hoverTargetPoints]);
|
|
476
|
-
pointerGraceArea.value = graceArea;
|
|
477
|
-
providerContext.onPointerInTransitChange(true);
|
|
478
|
-
}
|
|
479
|
-
watchEffect((cleanupFn) => {
|
|
480
|
-
if (trigger.value && currentElement.value) {
|
|
481
|
-
const handleTriggerLeave = (event) => handleCreateGraceArea(event, currentElement.value);
|
|
482
|
-
const handleContentLeave = (event) => handleCreateGraceArea(event, trigger.value);
|
|
483
|
-
trigger.value.addEventListener("pointerleave", handleTriggerLeave);
|
|
484
|
-
currentElement.value.addEventListener("pointerleave", handleContentLeave);
|
|
485
|
-
cleanupFn(() => {
|
|
486
|
-
trigger.value?.removeEventListener("pointerleave", handleTriggerLeave);
|
|
487
|
-
currentElement.value?.removeEventListener("pointerleave", handleContentLeave);
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
});
|
|
491
|
-
watchEffect((cleanupFn) => {
|
|
492
|
-
if (pointerGraceArea.value) {
|
|
493
|
-
const handleTrackPointerGrace = (event) => {
|
|
494
|
-
if (!pointerGraceArea.value)
|
|
495
|
-
return;
|
|
496
|
-
const target = event.target;
|
|
497
|
-
const pointerPosition = { x: event.clientX, y: event.clientY };
|
|
498
|
-
const hasEnteredTarget = trigger.value?.contains(target) || currentElement.value?.contains(target);
|
|
499
|
-
const isPointerOutsideGraceArea = !isPointInPolygon(pointerPosition, pointerGraceArea.value);
|
|
500
|
-
if (hasEnteredTarget) {
|
|
501
|
-
handleRemoveGraceArea();
|
|
502
|
-
} else if (isPointerOutsideGraceArea) {
|
|
503
|
-
handleRemoveGraceArea();
|
|
504
|
-
onClose();
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
document.addEventListener("pointermove", handleTrackPointerGrace);
|
|
508
|
-
cleanupFn(() => document.removeEventListener("pointermove", handleTrackPointerGrace));
|
|
509
|
-
}
|
|
502
|
+
const { isPointerInTransit, onPointerExit } = useGraceArea(trigger, currentElement);
|
|
503
|
+
providerContext.isPointerInTransitRef = isPointerInTransit;
|
|
504
|
+
onPointerExit(() => {
|
|
505
|
+
onClose();
|
|
510
506
|
});
|
|
511
507
|
return {
|
|
512
|
-
forwardRef
|
|
508
|
+
forwardRef,
|
|
509
|
+
forwardedProps
|
|
513
510
|
};
|
|
514
511
|
},
|
|
515
512
|
render() {
|
|
516
|
-
return h(
|
|
517
|
-
ref:
|
|
518
|
-
|
|
519
|
-
}, () => this.$slots.default?.());
|
|
513
|
+
return h(TooltipContentImpl, mergeProps(this.forwardedProps, {
|
|
514
|
+
ref: this.forwardRef
|
|
515
|
+
}), () => this.$slots.default?.());
|
|
520
516
|
}
|
|
521
517
|
});
|
|
522
518
|
|
|
523
|
-
const
|
|
524
|
-
...
|
|
519
|
+
const tooltipContentProps = {
|
|
520
|
+
...tooltipContentImplProps
|
|
525
521
|
};
|
|
526
|
-
const
|
|
527
|
-
|
|
522
|
+
const tooltipContentEmits = {
|
|
523
|
+
...tooltipContentImplEmits
|
|
524
|
+
};
|
|
525
|
+
const TooltipContent = defineComponent({
|
|
528
526
|
name: "DestylerTooltipContent",
|
|
529
|
-
props:
|
|
530
|
-
emits:
|
|
527
|
+
props: tooltipContentProps,
|
|
528
|
+
emits: tooltipContentEmits,
|
|
531
529
|
setup(props, { emit }) {
|
|
532
530
|
const rootContext = injectTooltipRootContext();
|
|
533
531
|
const forwarded = useForwardPropsEmits(props, emit);
|
|
532
|
+
const { forwardRef } = useForwardExpose();
|
|
534
533
|
return {
|
|
535
534
|
rootContext,
|
|
536
|
-
forwarded
|
|
535
|
+
forwarded,
|
|
536
|
+
forwardRef
|
|
537
537
|
};
|
|
538
538
|
},
|
|
539
539
|
render() {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
540
|
+
if (this.rootContext.open.value) {
|
|
541
|
+
return h(this.rootContext.disableHoverableContent.value ? TooltipContentImpl : TooltipContentHoverable, mergeProps(this.forwarded, {
|
|
542
|
+
ref: this.forwardRef
|
|
543
|
+
}), () => this.$slots.default?.());
|
|
544
|
+
}
|
|
544
545
|
}
|
|
545
546
|
});
|
|
546
547
|
|
|
547
|
-
const
|
|
548
|
-
|
|
549
|
-
type: [String, Object],
|
|
550
|
-
required: false,
|
|
551
|
-
default: "body"
|
|
552
|
-
},
|
|
553
|
-
disabled: {
|
|
554
|
-
type: Boolean,
|
|
555
|
-
required: false,
|
|
556
|
-
default: false
|
|
557
|
-
},
|
|
558
|
-
forceMount: {
|
|
559
|
-
type: Boolean,
|
|
560
|
-
required: false,
|
|
561
|
-
default: false
|
|
562
|
-
}
|
|
548
|
+
const tooltipPortalProps = {
|
|
549
|
+
...teleportPrimitiveProps
|
|
563
550
|
};
|
|
564
|
-
const
|
|
551
|
+
const TooltipPortal = defineComponent({
|
|
565
552
|
name: "DestylerTooltipPortal",
|
|
566
|
-
props:
|
|
553
|
+
props: tooltipPortalProps,
|
|
567
554
|
render() {
|
|
568
|
-
return h(
|
|
555
|
+
return h(TeleportPrimitive, mergeProps(this.$props), () => this.$slots.default?.());
|
|
569
556
|
}
|
|
570
557
|
});
|
|
571
558
|
|
|
572
|
-
const
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
},
|
|
559
|
+
const tooltipTriggerProps = {
|
|
560
|
+
...primitiveProps,
|
|
561
|
+
/**
|
|
562
|
+
* @default button
|
|
563
|
+
*/
|
|
578
564
|
as: {
|
|
579
|
-
|
|
580
|
-
required: false,
|
|
565
|
+
...primitiveProps.as,
|
|
581
566
|
default: "button"
|
|
582
567
|
}
|
|
583
568
|
};
|
|
584
|
-
const
|
|
569
|
+
const TooltipTrigger = defineComponent({
|
|
585
570
|
name: "DestylerTooltipTrigger",
|
|
586
|
-
props:
|
|
571
|
+
props: tooltipTriggerProps,
|
|
587
572
|
setup() {
|
|
588
573
|
const rootContext = injectTooltipRootContext();
|
|
589
574
|
const providerContext = injectTooltipProviderContext();
|
|
575
|
+
rootContext.contentId || (rootContext.contentId = useId(void 0, "destyler-tooltip-content"));
|
|
590
576
|
const { forwardRef, currentElement: triggerElement } = useForwardExpose();
|
|
591
577
|
const isPointerDown = ref(false);
|
|
592
578
|
const hasPointerMoveOpened = ref(false);
|
|
579
|
+
const tooltipListeners = computed(() => {
|
|
580
|
+
if (rootContext.disabled.value)
|
|
581
|
+
return {};
|
|
582
|
+
return {
|
|
583
|
+
onclick: handleClick,
|
|
584
|
+
onfocus: handleFocus,
|
|
585
|
+
onpointermove: handlePointerMove,
|
|
586
|
+
onpointerleave: handlePointerLeave,
|
|
587
|
+
onpointerdown: handlePointerDown,
|
|
588
|
+
onblur: handleBlur
|
|
589
|
+
};
|
|
590
|
+
});
|
|
591
|
+
onMounted(() => {
|
|
592
|
+
rootContext.onTriggerChange(triggerElement.value);
|
|
593
|
+
});
|
|
593
594
|
function handlePointerUp() {
|
|
594
595
|
isPointerDown.value = false;
|
|
595
596
|
}
|
|
@@ -597,55 +598,53 @@ const DestylerTooltipTrigger = defineComponent({
|
|
|
597
598
|
isPointerDown.value = true;
|
|
598
599
|
document.addEventListener("pointerup", handlePointerUp, { once: true });
|
|
599
600
|
}
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
601
|
+
function handlePointerMove(event) {
|
|
602
|
+
if (event.pointerType === "touch")
|
|
603
|
+
return;
|
|
604
|
+
if (!hasPointerMoveOpened.value && !providerContext.isPointerInTransitRef.value) {
|
|
605
|
+
rootContext.onTriggerEnter();
|
|
606
|
+
hasPointerMoveOpened.value = true;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
function handlePointerLeave() {
|
|
610
|
+
rootContext.onTriggerLeave();
|
|
611
|
+
hasPointerMoveOpened.value = false;
|
|
612
|
+
}
|
|
613
|
+
function handleFocus(event) {
|
|
614
|
+
if (isPointerDown.value)
|
|
615
|
+
return;
|
|
616
|
+
if (rootContext.ignoreNonKeyboardFocus.value && !event.target.matches?.(":focus-visible"))
|
|
617
|
+
return;
|
|
618
|
+
rootContext.onOpen();
|
|
619
|
+
}
|
|
620
|
+
function handleBlur() {
|
|
621
|
+
rootContext.onClose();
|
|
622
|
+
}
|
|
623
|
+
function handleClick() {
|
|
624
|
+
if (!rootContext.disableClosingTrigger.value)
|
|
625
|
+
rootContext.onClose();
|
|
626
|
+
}
|
|
603
627
|
return {
|
|
604
628
|
rootContext,
|
|
605
629
|
providerContext,
|
|
606
630
|
forwardRef,
|
|
607
631
|
isPointerDown,
|
|
608
632
|
hasPointerMoveOpened,
|
|
609
|
-
handlePointerDown
|
|
633
|
+
handlePointerDown,
|
|
634
|
+
tooltipListeners
|
|
610
635
|
};
|
|
611
636
|
},
|
|
612
637
|
render() {
|
|
613
|
-
return h(
|
|
638
|
+
return h(PopperAnchor, {
|
|
614
639
|
asChild: true
|
|
615
|
-
}, () => h(
|
|
616
|
-
"ref":
|
|
640
|
+
}, () => h(Primitive, mergeProps(this.tooltipListeners, {
|
|
641
|
+
"ref": this.forwardRef,
|
|
617
642
|
"aria-describedby": this.rootContext.open.value ? this.rootContext.contentId : void 0,
|
|
618
643
|
"data-state": this.rootContext.stateAttribute.value,
|
|
619
644
|
"as": this.$props.as,
|
|
620
|
-
"asChild": this.$props.asChild
|
|
621
|
-
|
|
622
|
-
if (event.pointerType === "touch")
|
|
623
|
-
return;
|
|
624
|
-
if (!this.hasPointerMoveOpened && !this.providerContext.isPointerInTransitRef.value) {
|
|
625
|
-
this.rootContext.onTriggerEnter();
|
|
626
|
-
this.hasPointerMoveOpened = true;
|
|
627
|
-
}
|
|
628
|
-
},
|
|
629
|
-
"onPointerleave": () => {
|
|
630
|
-
this.rootContext.onTriggerLeave();
|
|
631
|
-
this.hasPointerMoveOpened = false;
|
|
632
|
-
},
|
|
633
|
-
"onPointerdown": () => {
|
|
634
|
-
this.handlePointerDown();
|
|
635
|
-
},
|
|
636
|
-
"onFocus": () => {
|
|
637
|
-
if (!this.isPointerDown)
|
|
638
|
-
this.rootContext.onOpen();
|
|
639
|
-
},
|
|
640
|
-
"onBlur": () => {
|
|
641
|
-
this.rootContext.onClose();
|
|
642
|
-
},
|
|
643
|
-
"onClick": () => {
|
|
644
|
-
if (!this.rootContext.disableClosingTrigger.value)
|
|
645
|
-
this.rootContext.onClose();
|
|
646
|
-
}
|
|
647
|
-
}, () => this.$slots.default?.()));
|
|
645
|
+
"asChild": this.$props.asChild
|
|
646
|
+
}), () => this.$slots.default?.()));
|
|
648
647
|
}
|
|
649
648
|
});
|
|
650
649
|
|
|
651
|
-
export {
|
|
650
|
+
export { TooltipArrow, TooltipContent, TooltipContentHoverable, TooltipContentImpl, TooltipPortal, TooltipProvider, TooltipRoot, TooltipTrigger, tooltipArrowProps, tooltipContentEmits, tooltipContentImplEmits, tooltipContentImplProps, tooltipContentProps, tooltipPortalProps, tooltipProviderProps, tooltipRootEmits, tooltipRootProps, tooltipTriggerProps };
|