@zag-js/tooltip 0.0.0-dev-20230705143151 → 0.0.0-dev-20230710092359
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.d.mts +122 -0
- package/dist/index.d.ts +122 -4
- package/dist/index.js +418 -8
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +394 -3
- package/dist/index.mjs.map +1 -0
- package/package.json +10 -10
- package/dist/tooltip.anatomy.d.ts +0 -3
- package/dist/tooltip.anatomy.js +0 -11
- package/dist/tooltip.anatomy.mjs +0 -6
- package/dist/tooltip.connect.d.ts +0 -34
- package/dist/tooltip.connect.js +0 -133
- package/dist/tooltip.connect.mjs +0 -129
- package/dist/tooltip.dom.d.ts +0 -31
- package/dist/tooltip.dom.js +0 -19
- package/dist/tooltip.dom.mjs +0 -15
- package/dist/tooltip.machine.d.ts +0 -3
- package/dist/tooltip.machine.js +0 -239
- package/dist/tooltip.machine.mjs +0 -235
- package/dist/tooltip.store.d.ts +0 -8
- package/dist/tooltip.store.js +0 -16
- package/dist/tooltip.store.mjs +0 -12
- package/dist/tooltip.types.d.ts +0 -81
package/dist/tooltip.machine.mjs
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import { createMachine, subscribe } from '@zag-js/core';
|
|
2
|
-
import { addDomEvent } from '@zag-js/dom-event';
|
|
3
|
-
import { getScrollParents, isSafari, isHTMLElement } from '@zag-js/dom-query';
|
|
4
|
-
import { getPlacement } from '@zag-js/popper';
|
|
5
|
-
import { compact } from '@zag-js/utils';
|
|
6
|
-
import { dom } from './tooltip.dom.mjs';
|
|
7
|
-
import { store } from './tooltip.store.mjs';
|
|
8
|
-
|
|
9
|
-
function machine(userContext) {
|
|
10
|
-
const ctx = compact(userContext);
|
|
11
|
-
return createMachine(
|
|
12
|
-
{
|
|
13
|
-
id: "tooltip",
|
|
14
|
-
initial: "closed",
|
|
15
|
-
context: {
|
|
16
|
-
openDelay: 1e3,
|
|
17
|
-
closeDelay: 500,
|
|
18
|
-
closeOnPointerDown: true,
|
|
19
|
-
closeOnEsc: true,
|
|
20
|
-
interactive: true,
|
|
21
|
-
currentPlacement: void 0,
|
|
22
|
-
...ctx,
|
|
23
|
-
positioning: {
|
|
24
|
-
placement: "bottom",
|
|
25
|
-
...ctx.positioning
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
computed: {
|
|
29
|
-
hasAriaLabel: (ctx2) => !!ctx2["aria-label"]
|
|
30
|
-
},
|
|
31
|
-
watch: {
|
|
32
|
-
disabled: ["closeIfDisabled"],
|
|
33
|
-
open: ["toggleVisibility"]
|
|
34
|
-
},
|
|
35
|
-
on: {
|
|
36
|
-
OPEN: "open",
|
|
37
|
-
CLOSE: "closed"
|
|
38
|
-
},
|
|
39
|
-
states: {
|
|
40
|
-
closed: {
|
|
41
|
-
tags: ["closed"],
|
|
42
|
-
entry: ["clearGlobalId", "invokeOnClose"],
|
|
43
|
-
on: {
|
|
44
|
-
FOCUS: "open",
|
|
45
|
-
POINTER_ENTER: [
|
|
46
|
-
{
|
|
47
|
-
guard: "noVisibleTooltip",
|
|
48
|
-
target: "opening"
|
|
49
|
-
},
|
|
50
|
-
{ target: "open" }
|
|
51
|
-
]
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
opening: {
|
|
55
|
-
tags: ["closed"],
|
|
56
|
-
activities: ["trackScroll", "trackPointerlockChange"],
|
|
57
|
-
after: {
|
|
58
|
-
OPEN_DELAY: "open"
|
|
59
|
-
},
|
|
60
|
-
on: {
|
|
61
|
-
POINTER_LEAVE: "closed",
|
|
62
|
-
BLUR: "closed",
|
|
63
|
-
SCROLL: "closed",
|
|
64
|
-
POINTER_LOCK_CHANGE: "closed",
|
|
65
|
-
POINTER_DOWN: {
|
|
66
|
-
guard: "closeOnPointerDown",
|
|
67
|
-
target: "closed"
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
open: {
|
|
72
|
-
tags: ["open"],
|
|
73
|
-
activities: [
|
|
74
|
-
"trackEscapeKey",
|
|
75
|
-
"trackDisabledTriggerOnSafari",
|
|
76
|
-
"trackScroll",
|
|
77
|
-
"trackPointerlockChange",
|
|
78
|
-
"trackPositioning"
|
|
79
|
-
],
|
|
80
|
-
entry: ["setGlobalId", "invokeOnOpen"],
|
|
81
|
-
on: {
|
|
82
|
-
POINTER_LEAVE: [
|
|
83
|
-
{
|
|
84
|
-
guard: "isVisible",
|
|
85
|
-
target: "closing"
|
|
86
|
-
},
|
|
87
|
-
{ target: "closed" }
|
|
88
|
-
],
|
|
89
|
-
BLUR: "closed",
|
|
90
|
-
ESCAPE: "closed",
|
|
91
|
-
SCROLL: "closed",
|
|
92
|
-
POINTER_LOCK_CHANGE: "closed",
|
|
93
|
-
TOOLTIP_POINTER_LEAVE: {
|
|
94
|
-
guard: "isInteractive",
|
|
95
|
-
target: "closing"
|
|
96
|
-
},
|
|
97
|
-
POINTER_DOWN: {
|
|
98
|
-
guard: "closeOnPointerDown",
|
|
99
|
-
target: "closed"
|
|
100
|
-
},
|
|
101
|
-
CLICK: "closed",
|
|
102
|
-
SET_POSITIONING: {
|
|
103
|
-
actions: "setPositioning"
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
closing: {
|
|
108
|
-
tags: ["open"],
|
|
109
|
-
activities: ["trackStore", "trackPositioning"],
|
|
110
|
-
after: {
|
|
111
|
-
CLOSE_DELAY: "closed"
|
|
112
|
-
},
|
|
113
|
-
on: {
|
|
114
|
-
FORCE_CLOSE: "closed",
|
|
115
|
-
POINTER_ENTER: "open",
|
|
116
|
-
TOOLTIP_POINTER_ENTER: {
|
|
117
|
-
guard: "isInteractive",
|
|
118
|
-
target: "open"
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
activities: {
|
|
126
|
-
trackPositioning(ctx2) {
|
|
127
|
-
ctx2.currentPlacement = ctx2.positioning.placement;
|
|
128
|
-
const getPositionerEl = () => dom.getPositionerEl(ctx2);
|
|
129
|
-
return getPlacement(dom.getTriggerEl(ctx2), getPositionerEl, {
|
|
130
|
-
...ctx2.positioning,
|
|
131
|
-
defer: true,
|
|
132
|
-
onComplete(data) {
|
|
133
|
-
ctx2.currentPlacement = data.placement;
|
|
134
|
-
},
|
|
135
|
-
onCleanup() {
|
|
136
|
-
ctx2.currentPlacement = void 0;
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
},
|
|
140
|
-
trackPointerlockChange(ctx2, _evt, { send }) {
|
|
141
|
-
const onChange = () => send("POINTER_LOCK_CHANGE");
|
|
142
|
-
return addDomEvent(dom.getDoc(ctx2), "pointerlockchange", onChange, false);
|
|
143
|
-
},
|
|
144
|
-
trackScroll(ctx2, _evt, { send }) {
|
|
145
|
-
const trigger = dom.getTriggerEl(ctx2);
|
|
146
|
-
if (!trigger)
|
|
147
|
-
return;
|
|
148
|
-
const cleanups = getScrollParents(trigger).map((el) => {
|
|
149
|
-
const opts = { passive: true, capture: true };
|
|
150
|
-
return addDomEvent(el, "scroll", () => send("SCROLL"), opts);
|
|
151
|
-
});
|
|
152
|
-
return () => {
|
|
153
|
-
cleanups.forEach((fn) => fn?.());
|
|
154
|
-
};
|
|
155
|
-
},
|
|
156
|
-
trackStore(ctx2, _evt, { send }) {
|
|
157
|
-
return subscribe(store, () => {
|
|
158
|
-
if (store.id !== ctx2.id) {
|
|
159
|
-
send("FORCE_CLOSE");
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
},
|
|
163
|
-
trackDisabledTriggerOnSafari(ctx2, _evt, { send }) {
|
|
164
|
-
if (!isSafari())
|
|
165
|
-
return;
|
|
166
|
-
const doc = dom.getDoc(ctx2);
|
|
167
|
-
return addDomEvent(doc, "pointermove", (event) => {
|
|
168
|
-
const selector = "[data-part=trigger][data-expanded]";
|
|
169
|
-
if (isHTMLElement(event.target) && event.target.closest(selector))
|
|
170
|
-
return;
|
|
171
|
-
send("POINTER_LEAVE");
|
|
172
|
-
});
|
|
173
|
-
},
|
|
174
|
-
trackEscapeKey(ctx2, _evt, { send }) {
|
|
175
|
-
if (!ctx2.closeOnEsc)
|
|
176
|
-
return;
|
|
177
|
-
const doc = dom.getDoc(ctx2);
|
|
178
|
-
return addDomEvent(doc, "keydown", (event) => {
|
|
179
|
-
if (event.key === "Escape") {
|
|
180
|
-
send("ESCAPE");
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
actions: {
|
|
186
|
-
setGlobalId(ctx2) {
|
|
187
|
-
store.setId(ctx2.id);
|
|
188
|
-
},
|
|
189
|
-
clearGlobalId(ctx2) {
|
|
190
|
-
if (ctx2.id === store.id) {
|
|
191
|
-
store.setId(null);
|
|
192
|
-
}
|
|
193
|
-
},
|
|
194
|
-
invokeOnOpen(ctx2, evt) {
|
|
195
|
-
const omit = ["TOOLTIP_POINTER_ENTER", "POINTER_ENTER"];
|
|
196
|
-
if (!omit.includes(evt.type)) {
|
|
197
|
-
ctx2.onOpen?.();
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
invokeOnClose(ctx2) {
|
|
201
|
-
ctx2.onClose?.();
|
|
202
|
-
},
|
|
203
|
-
closeIfDisabled(ctx2, _evt, { send }) {
|
|
204
|
-
if (ctx2.disabled) {
|
|
205
|
-
send("CLOSE");
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
setPositioning(ctx2, evt) {
|
|
209
|
-
const getPositionerEl = () => dom.getPositionerEl(ctx2);
|
|
210
|
-
getPlacement(dom.getTriggerEl(ctx2), getPositionerEl, {
|
|
211
|
-
...ctx2.positioning,
|
|
212
|
-
...evt.options,
|
|
213
|
-
defer: true,
|
|
214
|
-
listeners: false
|
|
215
|
-
});
|
|
216
|
-
},
|
|
217
|
-
toggleVisibility(ctx2, _evt, { send }) {
|
|
218
|
-
send({ type: ctx2.open ? "OPEN" : "CLOSE", src: "controlled" });
|
|
219
|
-
}
|
|
220
|
-
},
|
|
221
|
-
guards: {
|
|
222
|
-
closeOnPointerDown: (ctx2) => ctx2.closeOnPointerDown,
|
|
223
|
-
noVisibleTooltip: () => store.id === null,
|
|
224
|
-
isVisible: (ctx2) => ctx2.id === store.id,
|
|
225
|
-
isInteractive: (ctx2) => ctx2.interactive
|
|
226
|
-
},
|
|
227
|
-
delays: {
|
|
228
|
-
OPEN_DELAY: (ctx2) => ctx2.openDelay,
|
|
229
|
-
CLOSE_DELAY: (ctx2) => ctx2.closeDelay
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
export { machine };
|
package/dist/tooltip.store.d.ts
DELETED
package/dist/tooltip.store.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const core = require('@zag-js/core');
|
|
6
|
-
|
|
7
|
-
const store = core.proxy({
|
|
8
|
-
id: null,
|
|
9
|
-
prevId: null,
|
|
10
|
-
setId(val) {
|
|
11
|
-
this.prevId = this.id;
|
|
12
|
-
this.id = val;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
exports.store = store;
|
package/dist/tooltip.store.mjs
DELETED
package/dist/tooltip.types.d.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import type { StateMachine as S } from "@zag-js/core";
|
|
2
|
-
import type { Placement, PositioningOptions } from "@zag-js/popper";
|
|
3
|
-
import type { CommonProperties, RequiredBy, RootProperties } from "@zag-js/types";
|
|
4
|
-
type ElementIds = Partial<{
|
|
5
|
-
trigger: string;
|
|
6
|
-
content: string;
|
|
7
|
-
arrow: string;
|
|
8
|
-
positioner: string;
|
|
9
|
-
}>;
|
|
10
|
-
type PublicContext = CommonProperties & {
|
|
11
|
-
/**
|
|
12
|
-
* The ids of the elements in the tooltip. Useful for composition.
|
|
13
|
-
*/
|
|
14
|
-
ids?: ElementIds;
|
|
15
|
-
/**
|
|
16
|
-
* The `id` of the tooltip.
|
|
17
|
-
*/
|
|
18
|
-
id: string;
|
|
19
|
-
/**
|
|
20
|
-
* The open delay of the tooltip.
|
|
21
|
-
*/
|
|
22
|
-
openDelay: number;
|
|
23
|
-
/**
|
|
24
|
-
* The close delay of the tooltip.
|
|
25
|
-
*/
|
|
26
|
-
closeDelay: number;
|
|
27
|
-
/**
|
|
28
|
-
* Whether to close the tooltip on pointerdown.
|
|
29
|
-
*/
|
|
30
|
-
closeOnPointerDown: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Whether to close the tooltip when the Escape key is pressed.
|
|
33
|
-
*/
|
|
34
|
-
closeOnEsc?: boolean;
|
|
35
|
-
/**
|
|
36
|
-
* Whether the tooltip's content is interactive.
|
|
37
|
-
* In this mode, the tooltip will remain open when user hovers over the content.
|
|
38
|
-
* @see https://www.w3.org/TR/WCAG21/#content-on-hover-or-focus
|
|
39
|
-
*/
|
|
40
|
-
interactive: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Function called when the tooltip is opened.
|
|
43
|
-
*/
|
|
44
|
-
onOpen?: VoidFunction;
|
|
45
|
-
/**
|
|
46
|
-
* Function called when the tooltip is closed.
|
|
47
|
-
*/
|
|
48
|
-
onClose?: VoidFunction;
|
|
49
|
-
/**
|
|
50
|
-
* Custom label for the tooltip.
|
|
51
|
-
*/
|
|
52
|
-
"aria-label"?: string;
|
|
53
|
-
/**
|
|
54
|
-
* The user provided options used to position the popover content
|
|
55
|
-
*/
|
|
56
|
-
positioning: PositioningOptions;
|
|
57
|
-
/**
|
|
58
|
-
* Whether the tooltip is disabled
|
|
59
|
-
*/
|
|
60
|
-
disabled?: boolean;
|
|
61
|
-
/**
|
|
62
|
-
* Whether the tooltip is open
|
|
63
|
-
*/
|
|
64
|
-
open?: boolean;
|
|
65
|
-
};
|
|
66
|
-
export type UserDefinedContext = RequiredBy<PublicContext, "id">;
|
|
67
|
-
type ComputedContext = Readonly<{
|
|
68
|
-
/**
|
|
69
|
-
* @computed Whether an `aria-label` is set.
|
|
70
|
-
*/
|
|
71
|
-
readonly hasAriaLabel: boolean;
|
|
72
|
-
}>;
|
|
73
|
-
type PrivateContext = RootProperties & {};
|
|
74
|
-
export type MachineContext = PublicContext & ComputedContext & PrivateContext;
|
|
75
|
-
export type MachineState = {
|
|
76
|
-
value: "opening" | "open" | "closing" | "closed";
|
|
77
|
-
tags: "open" | "closed";
|
|
78
|
-
};
|
|
79
|
-
export type State = S.State<MachineContext, MachineState>;
|
|
80
|
-
export type Send = S.Send<S.AnyEventObject>;
|
|
81
|
-
export type { PositioningOptions, Placement };
|