@martinsura/ui 0.1.1 → 0.1.2
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 +63 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.js +63 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -648,9 +648,28 @@ var SwitchInput = ({
|
|
|
648
648
|
errorDisplay && /* @__PURE__ */ jsxRuntime.jsx(InputError, { error: String(errorDisplay), className: props.classNames?.error })
|
|
649
649
|
] });
|
|
650
650
|
};
|
|
651
|
+
|
|
652
|
+
// src/floating/layerStack.ts
|
|
653
|
+
var FLOATING_ROOT_SELECTOR = "[data-ui-floating-root]";
|
|
654
|
+
var DRAWER_ROOT_SELECTOR = "[data-ui-drawer-root]";
|
|
655
|
+
function getTopmostElement(selector) {
|
|
656
|
+
const elements = document.querySelectorAll(selector);
|
|
657
|
+
return elements.length > 0 ? elements[elements.length - 1] : null;
|
|
658
|
+
}
|
|
659
|
+
function hasFloatingRootOpen() {
|
|
660
|
+
return getTopmostElement(FLOATING_ROOT_SELECTOR) !== null;
|
|
661
|
+
}
|
|
662
|
+
function isTopmostFloatingRoot(element) {
|
|
663
|
+
return element !== null && getTopmostElement(FLOATING_ROOT_SELECTOR) === element;
|
|
664
|
+
}
|
|
665
|
+
function isTopmostDrawerRoot(element) {
|
|
666
|
+
return element !== null && getTopmostElement(DRAWER_ROOT_SELECTOR) === element;
|
|
667
|
+
}
|
|
668
|
+
function isTargetInsideFloatingRoot(target) {
|
|
669
|
+
return target instanceof Element && target.closest(FLOATING_ROOT_SELECTOR) !== null;
|
|
670
|
+
}
|
|
651
671
|
var GAP = 6;
|
|
652
672
|
var VIEWPORT_MARGIN = 8;
|
|
653
|
-
var FLOATING_ROOT_SELECTOR = "[data-ui-floating-root]";
|
|
654
673
|
function calcPosition(triggerRect, panelRect, placement) {
|
|
655
674
|
const spaceBelow = window.innerHeight - triggerRect.bottom - VIEWPORT_MARGIN;
|
|
656
675
|
const spaceAbove = triggerRect.top - VIEWPORT_MARGIN;
|
|
@@ -757,7 +776,7 @@ var Dropdown = ({
|
|
|
757
776
|
}
|
|
758
777
|
};
|
|
759
778
|
const handleKeyDown = (e) => {
|
|
760
|
-
if (e.key === "Escape") {
|
|
779
|
+
if (e.key === "Escape" && isTopmostFloatingRoot(popupRef.current)) {
|
|
761
780
|
setOpen(false);
|
|
762
781
|
}
|
|
763
782
|
};
|
|
@@ -1921,6 +1940,19 @@ var SelectDropdown = (props) => {
|
|
|
1921
1940
|
react.useEffect(() => {
|
|
1922
1941
|
if (props.isOpen) {
|
|
1923
1942
|
document.addEventListener("mousedown", handleMouseDown);
|
|
1943
|
+
const handleKeyDown = (e) => {
|
|
1944
|
+
if (e.key === "Escape" && isTopmostFloatingRoot(popupRef.current)) {
|
|
1945
|
+
e.preventDefault();
|
|
1946
|
+
e.stopPropagation();
|
|
1947
|
+
e.stopImmediatePropagation();
|
|
1948
|
+
props.onClose();
|
|
1949
|
+
}
|
|
1950
|
+
};
|
|
1951
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
1952
|
+
return () => {
|
|
1953
|
+
document.removeEventListener("mousedown", handleMouseDown);
|
|
1954
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
1955
|
+
};
|
|
1924
1956
|
}
|
|
1925
1957
|
return () => document.removeEventListener("mousedown", handleMouseDown);
|
|
1926
1958
|
}, [props.isOpen, handleMouseDown]);
|
|
@@ -2270,6 +2302,19 @@ var CalendarPopup = (props) => {
|
|
|
2270
2302
|
react.useEffect(() => {
|
|
2271
2303
|
if (props.isOpen) {
|
|
2272
2304
|
document.addEventListener("mousedown", handleMouseDown);
|
|
2305
|
+
const handleKeyDown = (e) => {
|
|
2306
|
+
if (e.key === "Escape" && isTopmostFloatingRoot(popupRef.current)) {
|
|
2307
|
+
e.preventDefault();
|
|
2308
|
+
e.stopPropagation();
|
|
2309
|
+
e.stopImmediatePropagation();
|
|
2310
|
+
props.onClose();
|
|
2311
|
+
}
|
|
2312
|
+
};
|
|
2313
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
2314
|
+
return () => {
|
|
2315
|
+
document.removeEventListener("mousedown", handleMouseDown);
|
|
2316
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
2317
|
+
};
|
|
2273
2318
|
}
|
|
2274
2319
|
return () => document.removeEventListener("mousedown", handleMouseDown);
|
|
2275
2320
|
}, [props.isOpen, handleMouseDown]);
|
|
@@ -2322,7 +2367,7 @@ var CalendarPopup = (props) => {
|
|
|
2322
2367
|
ref: popupRef,
|
|
2323
2368
|
"data-ui-floating-root": "",
|
|
2324
2369
|
style: { top: pos.top, left: pos.left },
|
|
2325
|
-
className: "fixed z-
|
|
2370
|
+
className: "fixed z-1003 bg-white border border-(--ui-border) rounded-(--ui-radius-lg) shadow-lg w-68",
|
|
2326
2371
|
children: [
|
|
2327
2372
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-3 py-2 border-b border-(--ui-border)", children: [
|
|
2328
2373
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -2821,6 +2866,7 @@ var Drawer = ({ placement = "top", ...props }) => {
|
|
|
2821
2866
|
const [footer, setFooter] = react.useState(null);
|
|
2822
2867
|
const [loading, setLoading] = react.useState(false);
|
|
2823
2868
|
const frameRef = react.useRef(0);
|
|
2869
|
+
const panelRef = react.useRef(null);
|
|
2824
2870
|
react.useEffect(() => {
|
|
2825
2871
|
if (props.isOpen) {
|
|
2826
2872
|
setRendered(true);
|
|
@@ -2839,9 +2885,19 @@ var Drawer = ({ placement = "top", ...props }) => {
|
|
|
2839
2885
|
return;
|
|
2840
2886
|
}
|
|
2841
2887
|
const handleKeyDown = (e) => {
|
|
2842
|
-
if (e.key
|
|
2843
|
-
|
|
2888
|
+
if (e.key !== "Escape" || e.defaultPrevented) {
|
|
2889
|
+
return;
|
|
2890
|
+
}
|
|
2891
|
+
if (hasFloatingRootOpen()) {
|
|
2892
|
+
return;
|
|
2893
|
+
}
|
|
2894
|
+
if (isTargetInsideFloatingRoot(e.target)) {
|
|
2895
|
+
return;
|
|
2896
|
+
}
|
|
2897
|
+
if (!isTopmostDrawerRoot(panelRef.current)) {
|
|
2898
|
+
return;
|
|
2844
2899
|
}
|
|
2900
|
+
props.onClose(false);
|
|
2845
2901
|
};
|
|
2846
2902
|
document.body.style.overflow = "hidden";
|
|
2847
2903
|
document.addEventListener("keydown", handleKeyDown);
|
|
@@ -2878,6 +2934,8 @@ var Drawer = ({ placement = "top", ...props }) => {
|
|
|
2878
2934
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2879
2935
|
"div",
|
|
2880
2936
|
{
|
|
2937
|
+
ref: panelRef,
|
|
2938
|
+
"data-ui-drawer-root": "",
|
|
2881
2939
|
className: tailwindMerge.twMerge(
|
|
2882
2940
|
panelBase[placement],
|
|
2883
2941
|
"bg-white shadow-xl transition-transform duration-220 ease-out",
|