@adamjanicki/ui 1.2.6 → 1.2.8
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/components/Layer/Layer.js +4 -4
- package/hooks/useScrollLock.js +12 -25
- package/package.json +1 -1
|
@@ -25,8 +25,8 @@ import React, { useEffect } from "react";
|
|
|
25
25
|
import { useFocusTrap, useScrollLock } from "../../hooks";
|
|
26
26
|
import { classNames } from "../../utils/util";
|
|
27
27
|
var BaseLayer = function (_a) {
|
|
28
|
-
var onClose = _a.onClose, children = _a.children, style = _a.style, className = _a.className, _b = _a.disableEscape, disableEscape = _b === void 0 ? false : _b;
|
|
29
|
-
var focusRef = useFocusTrap(
|
|
28
|
+
var onClose = _a.onClose, children = _a.children, style = _a.style, className = _a.className, _b = _a.disableEscape, disableEscape = _b === void 0 ? false : _b, visible = _a.visible;
|
|
29
|
+
var focusRef = useFocusTrap(visible);
|
|
30
30
|
useEffect(function () {
|
|
31
31
|
var handleEscape = function (event) {
|
|
32
32
|
if (event.key === "Escape") {
|
|
@@ -52,7 +52,7 @@ var BaseLayer = function (_a) {
|
|
|
52
52
|
var Layer = function (props) {
|
|
53
53
|
// Lock and unlock on mount and unmount
|
|
54
54
|
useScrollLock();
|
|
55
|
-
return _jsx(BaseLayer, __assign({}, props));
|
|
55
|
+
return _jsx(BaseLayer, __assign({}, props, { visible: true }));
|
|
56
56
|
};
|
|
57
57
|
var defaultInvisibleStyle = {
|
|
58
58
|
visibility: "hidden",
|
|
@@ -66,6 +66,6 @@ export var AnimatedLayer = function (_a) {
|
|
|
66
66
|
useScrollLock(visible);
|
|
67
67
|
var mergedStyle = __assign(__assign({}, style), (visible ? visibleStyle : invisibleStyle));
|
|
68
68
|
var mergedClassName = classNames(className, visible ? visibleClassName : invisibleClassName);
|
|
69
|
-
return (_jsx(BaseLayer, __assign({}, props, { style: mergedStyle, className: mergedClassName })));
|
|
69
|
+
return (_jsx(BaseLayer, __assign({}, props, { style: mergedStyle, className: mergedClassName, visible: visible })));
|
|
70
70
|
};
|
|
71
71
|
export default Layer;
|
package/hooks/useScrollLock.js
CHANGED
|
@@ -1,31 +1,18 @@
|
|
|
1
1
|
import { useEffect } from "react";
|
|
2
|
-
var touchEvents = ["touchstart", "touchmove"];
|
|
3
|
-
var empty = function () { };
|
|
4
2
|
var lockScroll = function () {
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
3
|
+
var scrollPosition = window.scrollY;
|
|
4
|
+
var style = document.body.style;
|
|
5
|
+
var overflow = style.overflow, position = style.position, top = style.top, width = style.width;
|
|
6
|
+
style.overflow = "hidden";
|
|
7
|
+
style.position = "fixed";
|
|
8
|
+
style.top = "-".concat(scrollPosition, "px");
|
|
9
|
+
style.width = "100%";
|
|
13
10
|
return function () {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
bodyStyle.removeProperty("overflow");
|
|
20
|
-
// remove style attribute if empty
|
|
21
|
-
if (!bodyStyle.length) {
|
|
22
|
-
document.body.removeAttribute("style");
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
// remove touch event listeners
|
|
26
|
-
touchEvents.forEach(function (event) {
|
|
27
|
-
window.removeEventListener(event, empty);
|
|
28
|
-
});
|
|
11
|
+
style.overflow = overflow;
|
|
12
|
+
style.position = position;
|
|
13
|
+
style.top = top;
|
|
14
|
+
style.width = width;
|
|
15
|
+
window.scrollTo(0, scrollPosition);
|
|
29
16
|
};
|
|
30
17
|
};
|
|
31
18
|
/**
|