@x-plat/design-system 0.14.19 → 0.15.0
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/components/Dropdown/index.cjs +44 -16
- package/dist/components/Dropdown/index.js +44 -16
- package/dist/components/PopOver/index.cjs +43 -15
- package/dist/components/PopOver/index.js +43 -15
- package/dist/components/Select/index.cjs +63 -35
- package/dist/components/Select/index.js +63 -35
- package/dist/components/TimePicker/index.cjs +48 -20
- package/dist/components/TimePicker/index.js +48 -20
- package/dist/components/Tooltip/index.cjs +2 -2
- package/dist/components/Tooltip/index.js +2 -2
- package/dist/components/index.cjs +245 -214
- package/dist/components/index.js +245 -214
- package/dist/index.cjs +250 -219
- package/dist/index.js +250 -219
- package/package.json +1 -1
|
@@ -35,13 +35,13 @@ __export(Dropdown_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(Dropdown_exports);
|
|
36
36
|
|
|
37
37
|
// src/components/Dropdown/Dropdown.tsx
|
|
38
|
-
var
|
|
38
|
+
var import_react5 = __toESM(require("react"), 1);
|
|
39
39
|
|
|
40
40
|
// src/tokens/hooks/Portal.tsx
|
|
41
41
|
var import_react_dom = __toESM(require("react-dom"), 1);
|
|
42
|
-
var Portal = ({ children }) => {
|
|
42
|
+
var Portal = ({ children, container }) => {
|
|
43
43
|
if (typeof document === "undefined") return null;
|
|
44
|
-
return import_react_dom.default.createPortal(children, document.body);
|
|
44
|
+
return import_react_dom.default.createPortal(children, container ?? document.body);
|
|
45
45
|
};
|
|
46
46
|
Portal.displayName = "Portal";
|
|
47
47
|
var Portal_default = Portal;
|
|
@@ -147,8 +147,9 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
147
147
|
);
|
|
148
148
|
if (frozenMaxRef.current === void 0) frozenMaxRef.current = suggested;
|
|
149
149
|
const maxHeight = frozenMaxRef.current;
|
|
150
|
-
|
|
151
|
-
pop.style.
|
|
150
|
+
const hostRect = (pop.offsetParent ?? pop.parentElement)?.getBoundingClientRect();
|
|
151
|
+
pop.style.top = `${top - (hostRect?.top ?? 0)}px`;
|
|
152
|
+
pop.style.left = `${left - (hostRect?.left ?? 0)}px`;
|
|
152
153
|
pop.style.maxHeight = maxHeight === null ? "" : `${maxHeight}px`;
|
|
153
154
|
pop.style.clipPath = over.top || over.right || over.bottom || over.left ? `inset(${over.top}px ${over.right}px ${over.bottom}px ${over.left}px)` : "none";
|
|
154
155
|
directionRef.current = next;
|
|
@@ -223,8 +224,34 @@ var useClickOutside = (refs, handler, enabled = true) => {
|
|
|
223
224
|
};
|
|
224
225
|
var useClickOutside_default = useClickOutside;
|
|
225
226
|
|
|
226
|
-
// src/tokens/hooks/
|
|
227
|
+
// src/tokens/hooks/useOverlayHost.ts
|
|
227
228
|
var import_react3 = __toESM(require("react"), 1);
|
|
229
|
+
var useOverlayHost = (triggerRef, enabled) => {
|
|
230
|
+
const [host, setHost] = import_react3.default.useState(null);
|
|
231
|
+
import_react3.default.useLayoutEffect(() => {
|
|
232
|
+
if (!enabled || !triggerRef.current) {
|
|
233
|
+
setHost(null);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const el = document.createElement("div");
|
|
237
|
+
el.dataset.xplatOverlayHost = "";
|
|
238
|
+
el.style.position = "relative";
|
|
239
|
+
el.style.width = "0";
|
|
240
|
+
el.style.height = "0";
|
|
241
|
+
const parent = findScrollParent(triggerRef.current) ?? document.body;
|
|
242
|
+
parent.appendChild(el);
|
|
243
|
+
setHost(el);
|
|
244
|
+
return () => {
|
|
245
|
+
el.remove();
|
|
246
|
+
setHost(null);
|
|
247
|
+
};
|
|
248
|
+
}, [enabled, triggerRef]);
|
|
249
|
+
return host;
|
|
250
|
+
};
|
|
251
|
+
var useOverlayHost_default = useOverlayHost;
|
|
252
|
+
|
|
253
|
+
// src/tokens/hooks/useOverlayKeyboard.ts
|
|
254
|
+
var import_react4 = __toESM(require("react"), 1);
|
|
228
255
|
var FOCUSABLE = [
|
|
229
256
|
"a[href]",
|
|
230
257
|
"button:not([disabled])",
|
|
@@ -234,7 +261,7 @@ var FOCUSABLE = [
|
|
|
234
261
|
"[tabindex]:not([tabindex='-1'])"
|
|
235
262
|
].join(",");
|
|
236
263
|
var useEscapeKey = (enabled, onEscape) => {
|
|
237
|
-
|
|
264
|
+
import_react4.default.useEffect(() => {
|
|
238
265
|
if (!enabled) return;
|
|
239
266
|
const onKey = (e) => {
|
|
240
267
|
if (e.key !== "Escape") return;
|
|
@@ -247,9 +274,9 @@ var useEscapeKey = (enabled, onEscape) => {
|
|
|
247
274
|
}, [enabled, onEscape]);
|
|
248
275
|
};
|
|
249
276
|
var useCloseWhenFocusHidden = (enabled, triggerRef, popRef, onClose) => {
|
|
250
|
-
const onCloseRef =
|
|
277
|
+
const onCloseRef = import_react4.default.useRef(onClose);
|
|
251
278
|
onCloseRef.current = onClose;
|
|
252
|
-
|
|
279
|
+
import_react4.default.useEffect(() => {
|
|
253
280
|
const trigger = triggerRef.current;
|
|
254
281
|
if (!enabled || !trigger) return;
|
|
255
282
|
const observer = new IntersectionObserver(
|
|
@@ -287,11 +314,12 @@ var clsx_default = clsx;
|
|
|
287
314
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
288
315
|
var Dropdown = (props) => {
|
|
289
316
|
const { items, children } = props;
|
|
290
|
-
const [isOpen, setIsOpen] =
|
|
291
|
-
const [mounted, setMounted] =
|
|
292
|
-
const [visible, setVisible] =
|
|
293
|
-
const triggerRef =
|
|
294
|
-
const menuRef =
|
|
317
|
+
const [isOpen, setIsOpen] = import_react5.default.useState(false);
|
|
318
|
+
const [mounted, setMounted] = import_react5.default.useState(false);
|
|
319
|
+
const [visible, setVisible] = import_react5.default.useState(false);
|
|
320
|
+
const triggerRef = import_react5.default.useRef(null);
|
|
321
|
+
const menuRef = import_react5.default.useRef(null);
|
|
322
|
+
const host = useOverlayHost_default(triggerRef, mounted);
|
|
295
323
|
useAutoPosition_default(triggerRef, menuRef, mounted);
|
|
296
324
|
useClickOutside_default([triggerRef, menuRef], () => setIsOpen(false), isOpen);
|
|
297
325
|
useCloseWhenFocusHidden(isOpen, triggerRef, menuRef, () => setIsOpen(false));
|
|
@@ -299,7 +327,7 @@ var Dropdown = (props) => {
|
|
|
299
327
|
setIsOpen(false);
|
|
300
328
|
triggerRef.current?.focus({ preventScroll: true });
|
|
301
329
|
});
|
|
302
|
-
|
|
330
|
+
import_react5.default.useEffect(() => {
|
|
303
331
|
if (isOpen) {
|
|
304
332
|
setMounted(true);
|
|
305
333
|
const t2 = setTimeout(() => setVisible(true), 1);
|
|
@@ -324,7 +352,7 @@ var Dropdown = (props) => {
|
|
|
324
352
|
children
|
|
325
353
|
}
|
|
326
354
|
),
|
|
327
|
-
mounted && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Portal_default, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
355
|
+
mounted && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Portal_default, { container: host, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
328
356
|
"div",
|
|
329
357
|
{
|
|
330
358
|
ref: menuRef,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// src/components/Dropdown/Dropdown.tsx
|
|
2
|
-
import
|
|
2
|
+
import React5 from "react";
|
|
3
3
|
|
|
4
4
|
// src/tokens/hooks/Portal.tsx
|
|
5
5
|
import ReactDOM from "react-dom";
|
|
6
|
-
var Portal = ({ children }) => {
|
|
6
|
+
var Portal = ({ children, container }) => {
|
|
7
7
|
if (typeof document === "undefined") return null;
|
|
8
|
-
return ReactDOM.createPortal(children, document.body);
|
|
8
|
+
return ReactDOM.createPortal(children, container ?? document.body);
|
|
9
9
|
};
|
|
10
10
|
Portal.displayName = "Portal";
|
|
11
11
|
var Portal_default = Portal;
|
|
@@ -111,8 +111,9 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
111
111
|
);
|
|
112
112
|
if (frozenMaxRef.current === void 0) frozenMaxRef.current = suggested;
|
|
113
113
|
const maxHeight = frozenMaxRef.current;
|
|
114
|
-
|
|
115
|
-
pop.style.
|
|
114
|
+
const hostRect = (pop.offsetParent ?? pop.parentElement)?.getBoundingClientRect();
|
|
115
|
+
pop.style.top = `${top - (hostRect?.top ?? 0)}px`;
|
|
116
|
+
pop.style.left = `${left - (hostRect?.left ?? 0)}px`;
|
|
116
117
|
pop.style.maxHeight = maxHeight === null ? "" : `${maxHeight}px`;
|
|
117
118
|
pop.style.clipPath = over.top || over.right || over.bottom || over.left ? `inset(${over.top}px ${over.right}px ${over.bottom}px ${over.left}px)` : "none";
|
|
118
119
|
directionRef.current = next;
|
|
@@ -187,8 +188,34 @@ var useClickOutside = (refs, handler, enabled = true) => {
|
|
|
187
188
|
};
|
|
188
189
|
var useClickOutside_default = useClickOutside;
|
|
189
190
|
|
|
190
|
-
// src/tokens/hooks/
|
|
191
|
+
// src/tokens/hooks/useOverlayHost.ts
|
|
191
192
|
import React3 from "react";
|
|
193
|
+
var useOverlayHost = (triggerRef, enabled) => {
|
|
194
|
+
const [host, setHost] = React3.useState(null);
|
|
195
|
+
React3.useLayoutEffect(() => {
|
|
196
|
+
if (!enabled || !triggerRef.current) {
|
|
197
|
+
setHost(null);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const el = document.createElement("div");
|
|
201
|
+
el.dataset.xplatOverlayHost = "";
|
|
202
|
+
el.style.position = "relative";
|
|
203
|
+
el.style.width = "0";
|
|
204
|
+
el.style.height = "0";
|
|
205
|
+
const parent = findScrollParent(triggerRef.current) ?? document.body;
|
|
206
|
+
parent.appendChild(el);
|
|
207
|
+
setHost(el);
|
|
208
|
+
return () => {
|
|
209
|
+
el.remove();
|
|
210
|
+
setHost(null);
|
|
211
|
+
};
|
|
212
|
+
}, [enabled, triggerRef]);
|
|
213
|
+
return host;
|
|
214
|
+
};
|
|
215
|
+
var useOverlayHost_default = useOverlayHost;
|
|
216
|
+
|
|
217
|
+
// src/tokens/hooks/useOverlayKeyboard.ts
|
|
218
|
+
import React4 from "react";
|
|
192
219
|
var FOCUSABLE = [
|
|
193
220
|
"a[href]",
|
|
194
221
|
"button:not([disabled])",
|
|
@@ -198,7 +225,7 @@ var FOCUSABLE = [
|
|
|
198
225
|
"[tabindex]:not([tabindex='-1'])"
|
|
199
226
|
].join(",");
|
|
200
227
|
var useEscapeKey = (enabled, onEscape) => {
|
|
201
|
-
|
|
228
|
+
React4.useEffect(() => {
|
|
202
229
|
if (!enabled) return;
|
|
203
230
|
const onKey = (e) => {
|
|
204
231
|
if (e.key !== "Escape") return;
|
|
@@ -211,9 +238,9 @@ var useEscapeKey = (enabled, onEscape) => {
|
|
|
211
238
|
}, [enabled, onEscape]);
|
|
212
239
|
};
|
|
213
240
|
var useCloseWhenFocusHidden = (enabled, triggerRef, popRef, onClose) => {
|
|
214
|
-
const onCloseRef =
|
|
241
|
+
const onCloseRef = React4.useRef(onClose);
|
|
215
242
|
onCloseRef.current = onClose;
|
|
216
|
-
|
|
243
|
+
React4.useEffect(() => {
|
|
217
244
|
const trigger = triggerRef.current;
|
|
218
245
|
if (!enabled || !trigger) return;
|
|
219
246
|
const observer = new IntersectionObserver(
|
|
@@ -251,11 +278,12 @@ var clsx_default = clsx;
|
|
|
251
278
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
252
279
|
var Dropdown = (props) => {
|
|
253
280
|
const { items, children } = props;
|
|
254
|
-
const [isOpen, setIsOpen] =
|
|
255
|
-
const [mounted, setMounted] =
|
|
256
|
-
const [visible, setVisible] =
|
|
257
|
-
const triggerRef =
|
|
258
|
-
const menuRef =
|
|
281
|
+
const [isOpen, setIsOpen] = React5.useState(false);
|
|
282
|
+
const [mounted, setMounted] = React5.useState(false);
|
|
283
|
+
const [visible, setVisible] = React5.useState(false);
|
|
284
|
+
const triggerRef = React5.useRef(null);
|
|
285
|
+
const menuRef = React5.useRef(null);
|
|
286
|
+
const host = useOverlayHost_default(triggerRef, mounted);
|
|
259
287
|
useAutoPosition_default(triggerRef, menuRef, mounted);
|
|
260
288
|
useClickOutside_default([triggerRef, menuRef], () => setIsOpen(false), isOpen);
|
|
261
289
|
useCloseWhenFocusHidden(isOpen, triggerRef, menuRef, () => setIsOpen(false));
|
|
@@ -263,7 +291,7 @@ var Dropdown = (props) => {
|
|
|
263
291
|
setIsOpen(false);
|
|
264
292
|
triggerRef.current?.focus({ preventScroll: true });
|
|
265
293
|
});
|
|
266
|
-
|
|
294
|
+
React5.useEffect(() => {
|
|
267
295
|
if (isOpen) {
|
|
268
296
|
setMounted(true);
|
|
269
297
|
const t2 = setTimeout(() => setVisible(true), 1);
|
|
@@ -288,7 +316,7 @@ var Dropdown = (props) => {
|
|
|
288
316
|
children
|
|
289
317
|
}
|
|
290
318
|
),
|
|
291
|
-
mounted && /* @__PURE__ */ jsx(Portal_default, { children: /* @__PURE__ */ jsx(
|
|
319
|
+
mounted && /* @__PURE__ */ jsx(Portal_default, { container: host, children: /* @__PURE__ */ jsx(
|
|
292
320
|
"div",
|
|
293
321
|
{
|
|
294
322
|
ref: menuRef,
|
|
@@ -35,13 +35,13 @@ __export(PopOver_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(PopOver_exports);
|
|
36
36
|
|
|
37
37
|
// src/components/PopOver/PopOver.tsx
|
|
38
|
-
var
|
|
38
|
+
var import_react5 = __toESM(require("react"), 1);
|
|
39
39
|
|
|
40
40
|
// src/tokens/hooks/Portal.tsx
|
|
41
41
|
var import_react_dom = __toESM(require("react-dom"), 1);
|
|
42
|
-
var Portal = ({ children }) => {
|
|
42
|
+
var Portal = ({ children, container }) => {
|
|
43
43
|
if (typeof document === "undefined") return null;
|
|
44
|
-
return import_react_dom.default.createPortal(children, document.body);
|
|
44
|
+
return import_react_dom.default.createPortal(children, container ?? document.body);
|
|
45
45
|
};
|
|
46
46
|
Portal.displayName = "Portal";
|
|
47
47
|
var Portal_default = Portal;
|
|
@@ -147,8 +147,9 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
147
147
|
);
|
|
148
148
|
if (frozenMaxRef.current === void 0) frozenMaxRef.current = suggested;
|
|
149
149
|
const maxHeight = frozenMaxRef.current;
|
|
150
|
-
|
|
151
|
-
pop.style.
|
|
150
|
+
const hostRect = (pop.offsetParent ?? pop.parentElement)?.getBoundingClientRect();
|
|
151
|
+
pop.style.top = `${top - (hostRect?.top ?? 0)}px`;
|
|
152
|
+
pop.style.left = `${left - (hostRect?.left ?? 0)}px`;
|
|
152
153
|
pop.style.maxHeight = maxHeight === null ? "" : `${maxHeight}px`;
|
|
153
154
|
pop.style.clipPath = over.top || over.right || over.bottom || over.left ? `inset(${over.top}px ${over.right}px ${over.bottom}px ${over.left}px)` : "none";
|
|
154
155
|
directionRef.current = next;
|
|
@@ -223,8 +224,34 @@ var useClickOutside = (refs, handler, enabled = true) => {
|
|
|
223
224
|
};
|
|
224
225
|
var useClickOutside_default = useClickOutside;
|
|
225
226
|
|
|
226
|
-
// src/tokens/hooks/
|
|
227
|
+
// src/tokens/hooks/useOverlayHost.ts
|
|
227
228
|
var import_react3 = __toESM(require("react"), 1);
|
|
229
|
+
var useOverlayHost = (triggerRef, enabled) => {
|
|
230
|
+
const [host, setHost] = import_react3.default.useState(null);
|
|
231
|
+
import_react3.default.useLayoutEffect(() => {
|
|
232
|
+
if (!enabled || !triggerRef.current) {
|
|
233
|
+
setHost(null);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const el = document.createElement("div");
|
|
237
|
+
el.dataset.xplatOverlayHost = "";
|
|
238
|
+
el.style.position = "relative";
|
|
239
|
+
el.style.width = "0";
|
|
240
|
+
el.style.height = "0";
|
|
241
|
+
const parent = findScrollParent(triggerRef.current) ?? document.body;
|
|
242
|
+
parent.appendChild(el);
|
|
243
|
+
setHost(el);
|
|
244
|
+
return () => {
|
|
245
|
+
el.remove();
|
|
246
|
+
setHost(null);
|
|
247
|
+
};
|
|
248
|
+
}, [enabled, triggerRef]);
|
|
249
|
+
return host;
|
|
250
|
+
};
|
|
251
|
+
var useOverlayHost_default = useOverlayHost;
|
|
252
|
+
|
|
253
|
+
// src/tokens/hooks/useOverlayKeyboard.ts
|
|
254
|
+
var import_react4 = __toESM(require("react"), 1);
|
|
228
255
|
var FOCUSABLE = [
|
|
229
256
|
"a[href]",
|
|
230
257
|
"button:not([disabled])",
|
|
@@ -234,7 +261,7 @@ var FOCUSABLE = [
|
|
|
234
261
|
"[tabindex]:not([tabindex='-1'])"
|
|
235
262
|
].join(",");
|
|
236
263
|
var useEscapeKey = (enabled, onEscape) => {
|
|
237
|
-
|
|
264
|
+
import_react4.default.useEffect(() => {
|
|
238
265
|
if (!enabled) return;
|
|
239
266
|
const onKey = (e) => {
|
|
240
267
|
if (e.key !== "Escape") return;
|
|
@@ -247,9 +274,9 @@ var useEscapeKey = (enabled, onEscape) => {
|
|
|
247
274
|
}, [enabled, onEscape]);
|
|
248
275
|
};
|
|
249
276
|
var useCloseWhenFocusHidden = (enabled, triggerRef, popRef, onClose) => {
|
|
250
|
-
const onCloseRef =
|
|
277
|
+
const onCloseRef = import_react4.default.useRef(onClose);
|
|
251
278
|
onCloseRef.current = onClose;
|
|
252
|
-
|
|
279
|
+
import_react4.default.useEffect(() => {
|
|
253
280
|
const trigger = triggerRef.current;
|
|
254
281
|
if (!enabled || !trigger) return;
|
|
255
282
|
const observer = new IntersectionObserver(
|
|
@@ -287,18 +314,19 @@ var clsx_default = clsx;
|
|
|
287
314
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
288
315
|
var PopOver = (props) => {
|
|
289
316
|
const { children, isOpen, onClose, PopOverEl } = props;
|
|
290
|
-
const popRef =
|
|
291
|
-
const triggerRef =
|
|
292
|
-
const [localOpen, setLocalOpen] =
|
|
293
|
-
const [eventTrigger, setEventTrigger] =
|
|
317
|
+
const popRef = import_react5.default.useRef(null);
|
|
318
|
+
const triggerRef = import_react5.default.useRef(null);
|
|
319
|
+
const [localOpen, setLocalOpen] = import_react5.default.useState(false);
|
|
320
|
+
const [eventTrigger, setEventTrigger] = import_react5.default.useState(false);
|
|
294
321
|
useClickOutside_default([popRef, triggerRef], onClose, isOpen);
|
|
295
322
|
useCloseWhenFocusHidden(isOpen, triggerRef, popRef, onClose);
|
|
296
323
|
useEscapeKey(isOpen, () => {
|
|
297
324
|
onClose();
|
|
298
325
|
triggerRef.current?.focus({ preventScroll: true });
|
|
299
326
|
});
|
|
327
|
+
const host = useOverlayHost_default(triggerRef, localOpen);
|
|
300
328
|
useAutoPosition_default(triggerRef, popRef, localOpen);
|
|
301
|
-
|
|
329
|
+
import_react5.default.useEffect(() => {
|
|
302
330
|
if (isOpen) {
|
|
303
331
|
setLocalOpen(isOpen);
|
|
304
332
|
setTimeout(() => {
|
|
@@ -321,7 +349,7 @@ var PopOver = (props) => {
|
|
|
321
349
|
},
|
|
322
350
|
children: [
|
|
323
351
|
children,
|
|
324
|
-
localOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Portal_default, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
352
|
+
localOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Portal_default, { container: host, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
325
353
|
"div",
|
|
326
354
|
{
|
|
327
355
|
className: clsx_default(
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// src/components/PopOver/PopOver.tsx
|
|
2
|
-
import
|
|
2
|
+
import React5 from "react";
|
|
3
3
|
|
|
4
4
|
// src/tokens/hooks/Portal.tsx
|
|
5
5
|
import ReactDOM from "react-dom";
|
|
6
|
-
var Portal = ({ children }) => {
|
|
6
|
+
var Portal = ({ children, container }) => {
|
|
7
7
|
if (typeof document === "undefined") return null;
|
|
8
|
-
return ReactDOM.createPortal(children, document.body);
|
|
8
|
+
return ReactDOM.createPortal(children, container ?? document.body);
|
|
9
9
|
};
|
|
10
10
|
Portal.displayName = "Portal";
|
|
11
11
|
var Portal_default = Portal;
|
|
@@ -111,8 +111,9 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
111
111
|
);
|
|
112
112
|
if (frozenMaxRef.current === void 0) frozenMaxRef.current = suggested;
|
|
113
113
|
const maxHeight = frozenMaxRef.current;
|
|
114
|
-
|
|
115
|
-
pop.style.
|
|
114
|
+
const hostRect = (pop.offsetParent ?? pop.parentElement)?.getBoundingClientRect();
|
|
115
|
+
pop.style.top = `${top - (hostRect?.top ?? 0)}px`;
|
|
116
|
+
pop.style.left = `${left - (hostRect?.left ?? 0)}px`;
|
|
116
117
|
pop.style.maxHeight = maxHeight === null ? "" : `${maxHeight}px`;
|
|
117
118
|
pop.style.clipPath = over.top || over.right || over.bottom || over.left ? `inset(${over.top}px ${over.right}px ${over.bottom}px ${over.left}px)` : "none";
|
|
118
119
|
directionRef.current = next;
|
|
@@ -187,8 +188,34 @@ var useClickOutside = (refs, handler, enabled = true) => {
|
|
|
187
188
|
};
|
|
188
189
|
var useClickOutside_default = useClickOutside;
|
|
189
190
|
|
|
190
|
-
// src/tokens/hooks/
|
|
191
|
+
// src/tokens/hooks/useOverlayHost.ts
|
|
191
192
|
import React3 from "react";
|
|
193
|
+
var useOverlayHost = (triggerRef, enabled) => {
|
|
194
|
+
const [host, setHost] = React3.useState(null);
|
|
195
|
+
React3.useLayoutEffect(() => {
|
|
196
|
+
if (!enabled || !triggerRef.current) {
|
|
197
|
+
setHost(null);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const el = document.createElement("div");
|
|
201
|
+
el.dataset.xplatOverlayHost = "";
|
|
202
|
+
el.style.position = "relative";
|
|
203
|
+
el.style.width = "0";
|
|
204
|
+
el.style.height = "0";
|
|
205
|
+
const parent = findScrollParent(triggerRef.current) ?? document.body;
|
|
206
|
+
parent.appendChild(el);
|
|
207
|
+
setHost(el);
|
|
208
|
+
return () => {
|
|
209
|
+
el.remove();
|
|
210
|
+
setHost(null);
|
|
211
|
+
};
|
|
212
|
+
}, [enabled, triggerRef]);
|
|
213
|
+
return host;
|
|
214
|
+
};
|
|
215
|
+
var useOverlayHost_default = useOverlayHost;
|
|
216
|
+
|
|
217
|
+
// src/tokens/hooks/useOverlayKeyboard.ts
|
|
218
|
+
import React4 from "react";
|
|
192
219
|
var FOCUSABLE = [
|
|
193
220
|
"a[href]",
|
|
194
221
|
"button:not([disabled])",
|
|
@@ -198,7 +225,7 @@ var FOCUSABLE = [
|
|
|
198
225
|
"[tabindex]:not([tabindex='-1'])"
|
|
199
226
|
].join(",");
|
|
200
227
|
var useEscapeKey = (enabled, onEscape) => {
|
|
201
|
-
|
|
228
|
+
React4.useEffect(() => {
|
|
202
229
|
if (!enabled) return;
|
|
203
230
|
const onKey = (e) => {
|
|
204
231
|
if (e.key !== "Escape") return;
|
|
@@ -211,9 +238,9 @@ var useEscapeKey = (enabled, onEscape) => {
|
|
|
211
238
|
}, [enabled, onEscape]);
|
|
212
239
|
};
|
|
213
240
|
var useCloseWhenFocusHidden = (enabled, triggerRef, popRef, onClose) => {
|
|
214
|
-
const onCloseRef =
|
|
241
|
+
const onCloseRef = React4.useRef(onClose);
|
|
215
242
|
onCloseRef.current = onClose;
|
|
216
|
-
|
|
243
|
+
React4.useEffect(() => {
|
|
217
244
|
const trigger = triggerRef.current;
|
|
218
245
|
if (!enabled || !trigger) return;
|
|
219
246
|
const observer = new IntersectionObserver(
|
|
@@ -251,18 +278,19 @@ var clsx_default = clsx;
|
|
|
251
278
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
252
279
|
var PopOver = (props) => {
|
|
253
280
|
const { children, isOpen, onClose, PopOverEl } = props;
|
|
254
|
-
const popRef =
|
|
255
|
-
const triggerRef =
|
|
256
|
-
const [localOpen, setLocalOpen] =
|
|
257
|
-
const [eventTrigger, setEventTrigger] =
|
|
281
|
+
const popRef = React5.useRef(null);
|
|
282
|
+
const triggerRef = React5.useRef(null);
|
|
283
|
+
const [localOpen, setLocalOpen] = React5.useState(false);
|
|
284
|
+
const [eventTrigger, setEventTrigger] = React5.useState(false);
|
|
258
285
|
useClickOutside_default([popRef, triggerRef], onClose, isOpen);
|
|
259
286
|
useCloseWhenFocusHidden(isOpen, triggerRef, popRef, onClose);
|
|
260
287
|
useEscapeKey(isOpen, () => {
|
|
261
288
|
onClose();
|
|
262
289
|
triggerRef.current?.focus({ preventScroll: true });
|
|
263
290
|
});
|
|
291
|
+
const host = useOverlayHost_default(triggerRef, localOpen);
|
|
264
292
|
useAutoPosition_default(triggerRef, popRef, localOpen);
|
|
265
|
-
|
|
293
|
+
React5.useEffect(() => {
|
|
266
294
|
if (isOpen) {
|
|
267
295
|
setLocalOpen(isOpen);
|
|
268
296
|
setTimeout(() => {
|
|
@@ -285,7 +313,7 @@ var PopOver = (props) => {
|
|
|
285
313
|
},
|
|
286
314
|
children: [
|
|
287
315
|
children,
|
|
288
|
-
localOpen && /* @__PURE__ */ jsx(Portal_default, { children: /* @__PURE__ */ jsx(
|
|
316
|
+
localOpen && /* @__PURE__ */ jsx(Portal_default, { container: host, children: /* @__PURE__ */ jsx(
|
|
289
317
|
"div",
|
|
290
318
|
{
|
|
291
319
|
className: clsx_default(
|