@yuno-payments/dashboard-design-system 1.0.2 → 1.0.4-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.
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
* Custom hook to lock/unlock body scroll when a modal or overlay is open
|
|
3
3
|
* This prevents the background from scrolling while a modal is active
|
|
4
4
|
*
|
|
5
|
+
* Uses a reference counter to support multiple overlays - scroll is only
|
|
6
|
+
* restored when ALL overlays are closed.
|
|
7
|
+
*
|
|
5
8
|
* @param isLocked - Whether the body scroll should be locked
|
|
6
9
|
*
|
|
7
10
|
* @example
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import { useEffect as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { useEffect as i } from "react";
|
|
2
|
+
let o = 0, d = "", n = "";
|
|
3
|
+
function c(t) {
|
|
4
|
+
i(() => {
|
|
5
|
+
if (t) {
|
|
6
|
+
if (o === 0) {
|
|
7
|
+
d = document.body.style.overflow, n = document.body.style.paddingRight;
|
|
8
|
+
const e = window.innerWidth - document.documentElement.clientWidth;
|
|
9
|
+
document.body.style.overflow = "hidden", e > 0 && (document.body.style.paddingRight = `${e}px`);
|
|
10
|
+
}
|
|
11
|
+
return o++, () => {
|
|
12
|
+
o--, o === 0 && (document.body.style.overflow = d, document.body.style.paddingRight = n);
|
|
13
|
+
};
|
|
8
14
|
}
|
|
9
|
-
|
|
10
|
-
document.body.style.overflow = d, document.body.style.paddingRight = e;
|
|
11
|
-
};
|
|
12
|
-
}, [o]);
|
|
15
|
+
}, [t]);
|
|
13
16
|
}
|
|
14
17
|
export {
|
|
15
|
-
|
|
18
|
+
c as useBodyScrollLock
|
|
16
19
|
};
|