@destyler/tooltip 0.0.6 → 0.0.7-beta.1
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/dist/index.cjs +494 -25
- package/dist/index.d.cts +146 -5
- package/dist/index.d.mts +146 -5
- package/dist/index.d.ts +146 -5
- package/dist/index.mjs +490 -10
- package/package.json +11 -21
- package/README.md +0 -7
- package/dist/component.cjs +0 -669
- package/dist/component.d.cts +0 -770
- package/dist/component.d.mts +0 -770
- package/dist/component.d.ts +0 -770
- package/dist/component.mjs +0 -650
- package/dist/resolver.cjs +0 -25
- package/dist/resolver.d.cts +0 -6
- package/dist/resolver.d.mts +0 -6
- package/dist/resolver.d.ts +0 -6
- package/dist/resolver.mjs +0 -22
- package/dist/shared/tooltip.6a045e60.d.cts +0 -1047
- package/dist/shared/tooltip.6a045e60.d.mts +0 -1047
- package/dist/shared/tooltip.6a045e60.d.ts +0 -1047
package/dist/index.cjs
CHANGED
|
@@ -1,27 +1,496 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
require('
|
|
5
|
-
require('@
|
|
6
|
-
require('@
|
|
7
|
-
require('@
|
|
8
|
-
require('@
|
|
9
|
-
require('@
|
|
10
|
-
require('@
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
3
|
+
const anatomy$1 = require('@zag-js/anatomy');
|
|
4
|
+
const domQuery = require('@zag-js/dom-query');
|
|
5
|
+
const focusVisible = require('@zag-js/focus-visible');
|
|
6
|
+
const popper = require('@zag-js/popper');
|
|
7
|
+
const core = require('@zag-js/core');
|
|
8
|
+
const domEvent = require('@zag-js/dom-event');
|
|
9
|
+
const utils = require('@zag-js/utils');
|
|
10
|
+
const types = require('@zag-js/types');
|
|
11
|
+
|
|
12
|
+
const anatomy = anatomy$1.createAnatomy("tooltip").parts("trigger", "arrow", "arrowTip", "positioner", "content");
|
|
13
|
+
const parts = anatomy.build();
|
|
14
|
+
|
|
15
|
+
const dom = domQuery.createScope({
|
|
16
|
+
getTriggerId: (ctx) => ctx.ids?.trigger ?? `tooltip:${ctx.id}:trigger`,
|
|
17
|
+
getContentId: (ctx) => ctx.ids?.content ?? `tooltip:${ctx.id}:content`,
|
|
18
|
+
getArrowId: (ctx) => ctx.ids?.arrow ?? `tooltip:${ctx.id}:arrow`,
|
|
19
|
+
getPositionerId: (ctx) => ctx.ids?.positioner ?? `tooltip:${ctx.id}:popper`,
|
|
20
|
+
getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
|
|
21
|
+
getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
|
|
22
|
+
getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
|
|
23
|
+
getArrowEl: (ctx) => dom.getById(ctx, dom.getArrowId(ctx))
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const store = core.proxy({
|
|
27
|
+
id: null,
|
|
28
|
+
prevId: null,
|
|
29
|
+
setId(val) {
|
|
30
|
+
this.prevId = this.id;
|
|
31
|
+
this.id = val;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
function connect(state, send, normalize) {
|
|
36
|
+
const id = state.context.id;
|
|
37
|
+
const hasAriaLabel = state.context.hasAriaLabel;
|
|
38
|
+
const open = state.hasTag("open");
|
|
39
|
+
const triggerId = dom.getTriggerId(state.context);
|
|
40
|
+
const contentId = dom.getContentId(state.context);
|
|
41
|
+
const disabled = state.context.disabled;
|
|
42
|
+
const popperStyles = popper.getPlacementStyles({
|
|
43
|
+
...state.context.positioning,
|
|
44
|
+
placement: state.context.currentPlacement
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
open,
|
|
48
|
+
setOpen(nextOpen) {
|
|
49
|
+
if (nextOpen === open)
|
|
50
|
+
return;
|
|
51
|
+
send(nextOpen ? "OPEN" : "CLOSE");
|
|
52
|
+
},
|
|
53
|
+
reposition(options = {}) {
|
|
54
|
+
send({ type: "POSITIONING.SET", options });
|
|
55
|
+
},
|
|
56
|
+
getTriggerProps() {
|
|
57
|
+
return normalize.button({
|
|
58
|
+
...parts.trigger.attrs,
|
|
59
|
+
"id": triggerId,
|
|
60
|
+
"dir": state.context.dir,
|
|
61
|
+
"data-expanded": domQuery.dataAttr(open),
|
|
62
|
+
"data-state": open ? "open" : "closed",
|
|
63
|
+
"aria-describedby": open ? contentId : void 0,
|
|
64
|
+
onClick(event) {
|
|
65
|
+
if (event.defaultPrevented)
|
|
66
|
+
return;
|
|
67
|
+
if (disabled)
|
|
68
|
+
return;
|
|
69
|
+
if (!state.context.closeOnClick)
|
|
70
|
+
return;
|
|
71
|
+
send({ type: "CLOSE", src: "trigger.click" });
|
|
72
|
+
},
|
|
73
|
+
onFocus(event) {
|
|
74
|
+
if (event.defaultPrevented)
|
|
75
|
+
return;
|
|
76
|
+
if (disabled)
|
|
77
|
+
return;
|
|
78
|
+
if (state.event.src === "trigger.pointerdown")
|
|
79
|
+
return;
|
|
80
|
+
if (!focusVisible.isFocusVisible())
|
|
81
|
+
return;
|
|
82
|
+
send({ type: "OPEN", src: "trigger.focus" });
|
|
83
|
+
},
|
|
84
|
+
onBlur(event) {
|
|
85
|
+
if (event.defaultPrevented)
|
|
86
|
+
return;
|
|
87
|
+
if (disabled)
|
|
88
|
+
return;
|
|
89
|
+
if (id === store.id) {
|
|
90
|
+
send({ type: "CLOSE", src: "trigger.blur" });
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
onPointerDown(event) {
|
|
94
|
+
if (event.defaultPrevented)
|
|
95
|
+
return;
|
|
96
|
+
if (disabled)
|
|
97
|
+
return;
|
|
98
|
+
if (!state.context.closeOnPointerDown)
|
|
99
|
+
return;
|
|
100
|
+
if (id === store.id) {
|
|
101
|
+
send({ type: "CLOSE", src: "trigger.pointerdown" });
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
onPointerMove(event) {
|
|
105
|
+
if (event.defaultPrevented)
|
|
106
|
+
return;
|
|
107
|
+
if (disabled)
|
|
108
|
+
return;
|
|
109
|
+
if (event.pointerType === "touch")
|
|
110
|
+
return;
|
|
111
|
+
send("POINTER_MOVE");
|
|
112
|
+
},
|
|
113
|
+
onPointerLeave() {
|
|
114
|
+
if (disabled)
|
|
115
|
+
return;
|
|
116
|
+
send("POINTER_LEAVE");
|
|
117
|
+
},
|
|
118
|
+
onPointerCancel() {
|
|
119
|
+
if (disabled)
|
|
120
|
+
return;
|
|
121
|
+
send("POINTER_LEAVE");
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
getArrowProps() {
|
|
126
|
+
return normalize.element({
|
|
127
|
+
id: dom.getArrowId(state.context),
|
|
128
|
+
...parts.arrow.attrs,
|
|
129
|
+
dir: state.context.dir,
|
|
130
|
+
style: popperStyles.arrow
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
getArrowTipProps() {
|
|
134
|
+
return normalize.element({
|
|
135
|
+
...parts.arrowTip.attrs,
|
|
136
|
+
dir: state.context.dir,
|
|
137
|
+
style: popperStyles.arrowTip
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
getPositionerProps() {
|
|
141
|
+
return normalize.element({
|
|
142
|
+
id: dom.getPositionerId(state.context),
|
|
143
|
+
...parts.positioner.attrs,
|
|
144
|
+
dir: state.context.dir,
|
|
145
|
+
style: popperStyles.floating
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
getContentProps() {
|
|
149
|
+
return normalize.element({
|
|
150
|
+
...parts.content.attrs,
|
|
151
|
+
"dir": state.context.dir,
|
|
152
|
+
"hidden": !open,
|
|
153
|
+
"data-state": open ? "open" : "closed",
|
|
154
|
+
"role": hasAriaLabel ? void 0 : "tooltip",
|
|
155
|
+
"id": hasAriaLabel ? void 0 : contentId,
|
|
156
|
+
"data-placement": state.context.currentPlacement,
|
|
157
|
+
onPointerEnter() {
|
|
158
|
+
send("CONTENT.POINTER_MOVE");
|
|
159
|
+
},
|
|
160
|
+
onPointerLeave() {
|
|
161
|
+
send("CONTENT.POINTER_LEAVE");
|
|
162
|
+
},
|
|
163
|
+
"style": {
|
|
164
|
+
pointerEvents: state.context.interactive ? "auto" : "none"
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const { and, not } = core.guards;
|
|
172
|
+
function machine(userContext) {
|
|
173
|
+
const ctx = utils.compact(userContext);
|
|
174
|
+
return core.createMachine(
|
|
175
|
+
{
|
|
176
|
+
id: "tooltip",
|
|
177
|
+
initial: ctx.open ? "open" : "closed",
|
|
178
|
+
activities: ["trackFocusVisible"],
|
|
179
|
+
context: {
|
|
180
|
+
openDelay: 1e3,
|
|
181
|
+
closeDelay: 500,
|
|
182
|
+
closeOnPointerDown: true,
|
|
183
|
+
closeOnEscape: true,
|
|
184
|
+
interactive: false,
|
|
185
|
+
closeOnScroll: true,
|
|
186
|
+
closeOnClick: true,
|
|
187
|
+
...ctx,
|
|
188
|
+
currentPlacement: void 0,
|
|
189
|
+
hasPointerMoveOpened: false,
|
|
190
|
+
positioning: {
|
|
191
|
+
placement: "bottom",
|
|
192
|
+
...ctx.positioning
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
computed: {
|
|
196
|
+
hasAriaLabel: (ctx2) => !!ctx2["aria-label"]
|
|
197
|
+
},
|
|
198
|
+
watch: {
|
|
199
|
+
disabled: ["closeIfDisabled"],
|
|
200
|
+
open: ["toggleVisibility"]
|
|
201
|
+
},
|
|
202
|
+
states: {
|
|
203
|
+
closed: {
|
|
204
|
+
tags: ["closed"],
|
|
205
|
+
entry: ["clearGlobalId"],
|
|
206
|
+
on: {
|
|
207
|
+
"CONTROLLED.OPEN": "open",
|
|
208
|
+
"OPEN": {
|
|
209
|
+
target: "open",
|
|
210
|
+
actions: ["invokeOnOpen"]
|
|
211
|
+
},
|
|
212
|
+
"POINTER_LEAVE": {
|
|
213
|
+
actions: ["clearPointerMoveOpened"]
|
|
214
|
+
},
|
|
215
|
+
"POINTER_MOVE": [
|
|
216
|
+
{
|
|
217
|
+
guard: and("noVisibleTooltip", not("hasPointerMoveOpened")),
|
|
218
|
+
target: "opening"
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
guard: not("hasPointerMoveOpened"),
|
|
222
|
+
target: "open",
|
|
223
|
+
actions: ["setPointerMoveOpened", "invokeOnOpen"]
|
|
224
|
+
}
|
|
225
|
+
]
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
opening: {
|
|
229
|
+
tags: ["closed"],
|
|
230
|
+
activities: ["trackScroll", "trackPointerlockChange"],
|
|
231
|
+
after: {
|
|
232
|
+
OPEN_DELAY: [
|
|
233
|
+
{
|
|
234
|
+
guard: "isOpenControlled",
|
|
235
|
+
actions: ["setPointerMoveOpened", "invokeOnOpen"]
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
target: "open",
|
|
239
|
+
actions: ["setPointerMoveOpened", "invokeOnOpen"]
|
|
240
|
+
}
|
|
241
|
+
]
|
|
242
|
+
},
|
|
243
|
+
on: {
|
|
244
|
+
"CONTROLLED.OPEN": "open",
|
|
245
|
+
"CONTROLLED.CLOSE": "closed",
|
|
246
|
+
"OPEN": [
|
|
247
|
+
{
|
|
248
|
+
guard: "isOpenControlled",
|
|
249
|
+
actions: ["invokeOnOpen"]
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
target: "open",
|
|
253
|
+
actions: ["invokeOnOpen"]
|
|
254
|
+
}
|
|
255
|
+
],
|
|
256
|
+
"POINTER_LEAVE": [
|
|
257
|
+
{
|
|
258
|
+
guard: "isOpenControlled",
|
|
259
|
+
actions: ["clearPointerMoveOpened", "invokeOnClose"]
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
target: "closed",
|
|
263
|
+
actions: ["clearPointerMoveOpened", "invokeOnClose"]
|
|
264
|
+
}
|
|
265
|
+
],
|
|
266
|
+
"CLOSE": {
|
|
267
|
+
target: "closed",
|
|
268
|
+
actions: ["invokeOnClose"]
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
open: {
|
|
273
|
+
tags: ["open"],
|
|
274
|
+
activities: ["trackEscapeKey", "trackScroll", "trackPointerlockChange", "trackPositioning"],
|
|
275
|
+
entry: ["setGlobalId"],
|
|
276
|
+
on: {
|
|
277
|
+
"CONTROLLED.CLOSE": "closed",
|
|
278
|
+
"CLOSE": {
|
|
279
|
+
target: "closed",
|
|
280
|
+
actions: ["invokeOnClose"]
|
|
281
|
+
},
|
|
282
|
+
"POINTER_LEAVE": [
|
|
283
|
+
{
|
|
284
|
+
guard: "isVisible",
|
|
285
|
+
target: "closing",
|
|
286
|
+
actions: ["clearPointerMoveOpened"]
|
|
287
|
+
},
|
|
288
|
+
// == group ==
|
|
289
|
+
{
|
|
290
|
+
guard: "isOpenControlled",
|
|
291
|
+
actions: ["clearPointerMoveOpened", "invokeOnClose"]
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
target: "closed",
|
|
295
|
+
actions: ["clearPointerMoveOpened", "invokeOnClose"]
|
|
296
|
+
}
|
|
297
|
+
],
|
|
298
|
+
"CONTENT.POINTER_LEAVE": {
|
|
299
|
+
guard: "isInteractive",
|
|
300
|
+
target: "closing"
|
|
301
|
+
},
|
|
302
|
+
"POSITIONING.SET": {
|
|
303
|
+
actions: "reposition"
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
closing: {
|
|
308
|
+
tags: ["open"],
|
|
309
|
+
activities: ["trackStore", "trackPositioning"],
|
|
310
|
+
after: {
|
|
311
|
+
CLOSE_DELAY: [
|
|
312
|
+
{
|
|
313
|
+
guard: "isOpenControlled",
|
|
314
|
+
actions: ["invokeOnClose"]
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
target: "closed",
|
|
318
|
+
actions: ["invokeOnClose"]
|
|
319
|
+
}
|
|
320
|
+
]
|
|
321
|
+
},
|
|
322
|
+
on: {
|
|
323
|
+
"CONTROLLED.CLOSE": "closed",
|
|
324
|
+
"CONTROLLED.OPEN": "open",
|
|
325
|
+
"CLOSE": [
|
|
326
|
+
{
|
|
327
|
+
guard: "isOpenControlled",
|
|
328
|
+
actions: ["invokeOnClose"]
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
target: "closed",
|
|
332
|
+
actions: ["invokeOnClose"]
|
|
333
|
+
}
|
|
334
|
+
],
|
|
335
|
+
"POINTER_MOVE": [
|
|
336
|
+
{
|
|
337
|
+
guard: "isOpenControlled",
|
|
338
|
+
actions: ["setPointerMoveOpened", "invokeOnOpen"]
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
target: "open",
|
|
342
|
+
actions: ["setPointerMoveOpened", "invokeOnOpen"]
|
|
343
|
+
}
|
|
344
|
+
],
|
|
345
|
+
"CONTENT.POINTER_MOVE": {
|
|
346
|
+
guard: "isInteractive",
|
|
347
|
+
target: "open"
|
|
348
|
+
},
|
|
349
|
+
"POSITIONING.SET": {
|
|
350
|
+
actions: "reposition"
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
activities: {
|
|
358
|
+
trackFocusVisible(ctx2) {
|
|
359
|
+
return focusVisible.trackFocusVisible({ root: dom.getRootNode(ctx2) });
|
|
360
|
+
},
|
|
361
|
+
trackPositioning(ctx2) {
|
|
362
|
+
ctx2.currentPlacement = ctx2.positioning.placement;
|
|
363
|
+
const getPositionerEl = () => dom.getPositionerEl(ctx2);
|
|
364
|
+
return popper.getPlacement(dom.getTriggerEl(ctx2), getPositionerEl, {
|
|
365
|
+
...ctx2.positioning,
|
|
366
|
+
defer: true,
|
|
367
|
+
onComplete(data) {
|
|
368
|
+
ctx2.currentPlacement = data.placement;
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
},
|
|
372
|
+
trackPointerlockChange(ctx2, _evt, { send }) {
|
|
373
|
+
const onChange = () => send({ type: "CLOSE", src: "pointerlock:change" });
|
|
374
|
+
return domEvent.addDomEvent(dom.getDoc(ctx2), "pointerlockchange", onChange, false);
|
|
375
|
+
},
|
|
376
|
+
trackScroll(ctx2, _evt, { send }) {
|
|
377
|
+
if (!ctx2.closeOnScroll)
|
|
378
|
+
return;
|
|
379
|
+
const triggerEl = dom.getTriggerEl(ctx2);
|
|
380
|
+
if (!triggerEl)
|
|
381
|
+
return;
|
|
382
|
+
const overflowParents = domQuery.getOverflowAncestors(triggerEl);
|
|
383
|
+
const cleanups = overflowParents.map((overflowParent) => {
|
|
384
|
+
const onScroll = () => {
|
|
385
|
+
send({ type: "CLOSE", src: "scroll" });
|
|
386
|
+
};
|
|
387
|
+
return domEvent.addDomEvent(overflowParent, "scroll", onScroll, { passive: true, capture: true });
|
|
388
|
+
});
|
|
389
|
+
return () => {
|
|
390
|
+
cleanups.forEach((fn) => fn?.());
|
|
391
|
+
};
|
|
392
|
+
},
|
|
393
|
+
trackStore(ctx2, _evt, { send }) {
|
|
394
|
+
return core.subscribe(store, () => {
|
|
395
|
+
if (store.id !== ctx2.id) {
|
|
396
|
+
send({ type: "CLOSE", src: "id.change" });
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
},
|
|
400
|
+
trackEscapeKey(ctx2, _evt, { send }) {
|
|
401
|
+
if (!ctx2.closeOnEscape)
|
|
402
|
+
return;
|
|
403
|
+
const onKeyDown = (event) => {
|
|
404
|
+
if (domQuery.isComposingEvent(event))
|
|
405
|
+
return;
|
|
406
|
+
if (event.key !== "Escape")
|
|
407
|
+
return;
|
|
408
|
+
event.stopPropagation();
|
|
409
|
+
send({ type: "CLOSE", src: "keydown.escape" });
|
|
410
|
+
};
|
|
411
|
+
return domEvent.addDomEvent(dom.getDoc(ctx2), "keydown", onKeyDown, true);
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
actions: {
|
|
415
|
+
setGlobalId(ctx2) {
|
|
416
|
+
store.setId(ctx2.id);
|
|
417
|
+
},
|
|
418
|
+
clearGlobalId(ctx2) {
|
|
419
|
+
if (ctx2.id === store.id) {
|
|
420
|
+
store.setId(null);
|
|
421
|
+
}
|
|
422
|
+
},
|
|
423
|
+
invokeOnOpen(ctx2) {
|
|
424
|
+
ctx2.onOpenChange?.({ open: true });
|
|
425
|
+
},
|
|
426
|
+
invokeOnClose(ctx2) {
|
|
427
|
+
ctx2.onOpenChange?.({ open: false });
|
|
428
|
+
},
|
|
429
|
+
closeIfDisabled(ctx2, _evt, { send }) {
|
|
430
|
+
if (!ctx2.disabled)
|
|
431
|
+
return;
|
|
432
|
+
send({ type: "CLOSE", src: "disabled.change" });
|
|
433
|
+
},
|
|
434
|
+
reposition(ctx2, evt) {
|
|
435
|
+
const getPositionerEl = () => dom.getPositionerEl(ctx2);
|
|
436
|
+
popper.getPlacement(dom.getTriggerEl(ctx2), getPositionerEl, {
|
|
437
|
+
...ctx2.positioning,
|
|
438
|
+
...evt.options,
|
|
439
|
+
defer: true,
|
|
440
|
+
listeners: false,
|
|
441
|
+
onComplete(data) {
|
|
442
|
+
ctx2.currentPlacement = data.placement;
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
},
|
|
446
|
+
toggleVisibility(ctx2, evt, { send }) {
|
|
447
|
+
send({ type: ctx2.open ? "CONTROLLED.OPEN" : "CONTROLLED.CLOSE", previousEvent: evt });
|
|
448
|
+
},
|
|
449
|
+
setPointerMoveOpened(ctx2) {
|
|
450
|
+
ctx2.hasPointerMoveOpened = true;
|
|
451
|
+
},
|
|
452
|
+
clearPointerMoveOpened(ctx2) {
|
|
453
|
+
ctx2.hasPointerMoveOpened = false;
|
|
454
|
+
}
|
|
455
|
+
},
|
|
456
|
+
guards: {
|
|
457
|
+
noVisibleTooltip: () => store.id === null,
|
|
458
|
+
isVisible: (ctx2) => ctx2.id === store.id,
|
|
459
|
+
isInteractive: (ctx2) => ctx2.interactive,
|
|
460
|
+
hasPointerMoveOpened: (ctx2) => !!ctx2.hasPointerMoveOpened,
|
|
461
|
+
isOpenControlled: (ctx2) => !!ctx2["open.controlled"]
|
|
462
|
+
},
|
|
463
|
+
delays: {
|
|
464
|
+
OPEN_DELAY: (ctx2) => ctx2.openDelay,
|
|
465
|
+
CLOSE_DELAY: (ctx2) => ctx2.closeDelay
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const props = types.createProps()([
|
|
472
|
+
"aria-label",
|
|
473
|
+
"closeDelay",
|
|
474
|
+
"closeOnEscape",
|
|
475
|
+
"closeOnPointerDown",
|
|
476
|
+
"closeOnScroll",
|
|
477
|
+
"closeOnClick",
|
|
478
|
+
"dir",
|
|
479
|
+
"disabled",
|
|
480
|
+
"getRootNode",
|
|
481
|
+
"id",
|
|
482
|
+
"ids",
|
|
483
|
+
"interactive",
|
|
484
|
+
"onOpenChange",
|
|
485
|
+
"open.controlled",
|
|
486
|
+
"open",
|
|
487
|
+
"openDelay",
|
|
488
|
+
"positioning"
|
|
489
|
+
]);
|
|
490
|
+
const splitProps = utils.createSplitProps(props);
|
|
491
|
+
|
|
492
|
+
exports.anatomy = anatomy;
|
|
493
|
+
exports.connect = connect;
|
|
494
|
+
exports.machine = machine;
|
|
495
|
+
exports.props = props;
|
|
496
|
+
exports.splitProps = splitProps;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,146 @@
|
|
|
1
|
-
|
|
2
|
-
import '@
|
|
3
|
-
import '
|
|
4
|
-
import '@
|
|
5
|
-
import '@
|
|
1
|
+
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
|
+
import { RequiredBy, PropTypes, DirectionProperty, CommonProperties, NormalizeProps } from '@zag-js/types';
|
|
3
|
+
import * as _zag_js_core from '@zag-js/core';
|
|
4
|
+
import { Machine, StateMachine } from '@zag-js/core';
|
|
5
|
+
import { PositioningOptions, Placement } from '@zag-js/popper';
|
|
6
|
+
export { Placement, PositioningOptions } from '@zag-js/popper';
|
|
7
|
+
|
|
8
|
+
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"trigger" | "arrow" | "arrowTip" | "positioner" | "content">;
|
|
9
|
+
|
|
10
|
+
interface OpenChangeDetails {
|
|
11
|
+
open: boolean;
|
|
12
|
+
}
|
|
13
|
+
type ElementIds = Partial<{
|
|
14
|
+
trigger: string;
|
|
15
|
+
content: string;
|
|
16
|
+
arrow: string;
|
|
17
|
+
positioner: string;
|
|
18
|
+
}>;
|
|
19
|
+
interface PublicContext extends DirectionProperty, CommonProperties {
|
|
20
|
+
/**
|
|
21
|
+
* The ids of the elements in the tooltip. Useful for composition.
|
|
22
|
+
*/
|
|
23
|
+
'ids'?: ElementIds | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* The `id` of the tooltip.
|
|
26
|
+
*/
|
|
27
|
+
'id': string;
|
|
28
|
+
/**
|
|
29
|
+
* The open delay of the tooltip.
|
|
30
|
+
* @default 1000
|
|
31
|
+
*/
|
|
32
|
+
'openDelay': number;
|
|
33
|
+
/**
|
|
34
|
+
* The close delay of the tooltip.
|
|
35
|
+
* @default 500
|
|
36
|
+
*/
|
|
37
|
+
'closeDelay': number;
|
|
38
|
+
/**
|
|
39
|
+
* Whether to close the tooltip on pointerdown.
|
|
40
|
+
* @default true
|
|
41
|
+
*/
|
|
42
|
+
'closeOnPointerDown': boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Whether to close the tooltip when the Escape key is pressed.
|
|
45
|
+
* @default true
|
|
46
|
+
*/
|
|
47
|
+
'closeOnEscape'?: boolean | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Whether the tooltip should close on scroll
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
52
|
+
'closeOnScroll'?: boolean | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Whether the tooltip should close on click
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
|
+
'closeOnClick'?: boolean | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Whether the tooltip's content is interactive.
|
|
60
|
+
* In this mode, the tooltip will remain open when user hovers over the content.
|
|
61
|
+
* @see https://www.w3.org/TR/WCAG21/#content-on-hover-or-focus
|
|
62
|
+
*
|
|
63
|
+
* @default false
|
|
64
|
+
*/
|
|
65
|
+
'interactive': boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Function called when the tooltip is opened.
|
|
68
|
+
*/
|
|
69
|
+
'onOpenChange'?: (details: OpenChangeDetails) => void;
|
|
70
|
+
/**
|
|
71
|
+
* Custom label for the tooltip.
|
|
72
|
+
*/
|
|
73
|
+
'aria-label'?: string | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* The user provided options used to position the popover content
|
|
76
|
+
*/
|
|
77
|
+
'positioning': PositioningOptions;
|
|
78
|
+
/**
|
|
79
|
+
* Whether the tooltip is disabled
|
|
80
|
+
*/
|
|
81
|
+
'disabled'?: boolean | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Whether the tooltip is open
|
|
84
|
+
*/
|
|
85
|
+
'open'?: boolean | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* Whether the tooltip is controlled by the user
|
|
88
|
+
*/
|
|
89
|
+
'open.controlled'?: boolean | undefined;
|
|
90
|
+
}
|
|
91
|
+
type UserDefinedContext = RequiredBy<PublicContext, 'id'>;
|
|
92
|
+
type ComputedContext = Readonly<{
|
|
93
|
+
/**
|
|
94
|
+
* @computed Whether an `aria-label` is set.
|
|
95
|
+
*/
|
|
96
|
+
hasAriaLabel: boolean;
|
|
97
|
+
}>;
|
|
98
|
+
interface PrivateContext {
|
|
99
|
+
/**
|
|
100
|
+
* @internal
|
|
101
|
+
* The computed placement of the tooltip.
|
|
102
|
+
*/
|
|
103
|
+
currentPlacement?: Placement | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* @internal
|
|
106
|
+
* Whether the pointermove already opened the tooltip.
|
|
107
|
+
*/
|
|
108
|
+
hasPointerMoveOpened?: boolean | undefined;
|
|
109
|
+
}
|
|
110
|
+
interface MachineContext extends PublicContext, ComputedContext, PrivateContext {
|
|
111
|
+
}
|
|
112
|
+
interface MachineState {
|
|
113
|
+
value: 'opening' | 'open' | 'closing' | 'closed';
|
|
114
|
+
tags: 'open' | 'closed';
|
|
115
|
+
}
|
|
116
|
+
type State = StateMachine.State<MachineContext, MachineState>;
|
|
117
|
+
type Send = StateMachine.Send<StateMachine.AnyEventObject>;
|
|
118
|
+
type Service = Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
|
|
119
|
+
interface MachineApi<T extends PropTypes = PropTypes> {
|
|
120
|
+
/**
|
|
121
|
+
* Whether the tooltip is open.
|
|
122
|
+
*/
|
|
123
|
+
open: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Function to open the tooltip.
|
|
126
|
+
*/
|
|
127
|
+
setOpen: (open: boolean) => void;
|
|
128
|
+
/**
|
|
129
|
+
* Function to reposition the popover
|
|
130
|
+
*/
|
|
131
|
+
reposition: (options?: Partial<PositioningOptions>) => void;
|
|
132
|
+
getTriggerProps: () => T['button'];
|
|
133
|
+
getArrowProps: () => T['element'];
|
|
134
|
+
getArrowTipProps: () => T['element'];
|
|
135
|
+
getPositionerProps: () => T['element'];
|
|
136
|
+
getContentProps: () => T['element'];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
|
|
140
|
+
|
|
141
|
+
declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
142
|
+
|
|
143
|
+
declare const props: ("ids" | "id" | "openDelay" | "closeDelay" | "closeOnPointerDown" | "closeOnEscape" | "closeOnScroll" | "closeOnClick" | "interactive" | "onOpenChange" | "aria-label" | "positioning" | "disabled" | "open" | "open.controlled" | "dir" | "getRootNode")[];
|
|
144
|
+
declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "ids" | "id" | "openDelay" | "closeDelay" | "closeOnPointerDown" | "closeOnEscape" | "closeOnScroll" | "closeOnClick" | "interactive" | "onOpenChange" | "aria-label" | "positioning" | "disabled" | "open" | "open.controlled" | "dir" | "getRootNode">];
|
|
145
|
+
|
|
146
|
+
export { type MachineApi as Api, type UserDefinedContext as Context, type ElementIds, type OpenChangeDetails, type Service, anatomy, connect, machine, props, splitProps };
|