@sb1/ffe-modals-react 0.3.1 → 0.3.3
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/es/Modal.js +9 -6
- package/lib/Modal.js +9 -6
- package/package.json +3 -3
package/es/Modal.js
CHANGED
|
@@ -21,12 +21,14 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
return t;
|
|
22
22
|
};
|
|
23
23
|
import React, { useEffect, useImperativeHandle, useState, useRef } from 'react';
|
|
24
|
+
import { createPortal } from 'react-dom';
|
|
24
25
|
import classnames from 'classnames';
|
|
25
26
|
import { CloseButton } from './CloseButton';
|
|
26
27
|
export var Modal = React.forwardRef(function (_a, ref) {
|
|
27
28
|
var children = _a.children, onClick = _a.onClick, ariaLabelledby = _a.ariaLabelledby, className = _a.className, _b = _a.locale, locale = _b === void 0 ? 'nb' : _b, onClose = _a.onClose, rest = __rest(_a, ["children", "onClick", "ariaLabelledby", "className", "locale", "onClose"]);
|
|
28
29
|
var _c = useState(false), isOpen = _c[0], setIsOpen = _c[1];
|
|
29
30
|
var modalRef = useRef(null);
|
|
31
|
+
var htmlOverflowY = useRef(document.documentElement.style.overflowY);
|
|
30
32
|
useImperativeHandle(ref, function () { return ({
|
|
31
33
|
open: function () {
|
|
32
34
|
var _a;
|
|
@@ -40,18 +42,19 @@ export var Modal = React.forwardRef(function (_a, ref) {
|
|
|
40
42
|
}); });
|
|
41
43
|
useEffect(function () {
|
|
42
44
|
var _a;
|
|
45
|
+
var html = document.documentElement;
|
|
43
46
|
var inShadow = ((_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.getRootNode()) instanceof ShadowRoot;
|
|
44
47
|
if (inShadow) {
|
|
45
|
-
var html = document.documentElement;
|
|
46
48
|
if (isOpen) {
|
|
47
|
-
html.
|
|
49
|
+
htmlOverflowY.current = html.style.overflowY;
|
|
50
|
+
html.style.overflowY = 'hidden';
|
|
48
51
|
}
|
|
49
|
-
else {
|
|
50
|
-
html.
|
|
52
|
+
else if (!isOpen) {
|
|
53
|
+
html.style.overflowY = htmlOverflowY.current;
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
}, [isOpen]);
|
|
54
|
-
return (
|
|
57
|
+
return createPortal(
|
|
55
58
|
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
56
59
|
React.createElement("dialog", __assign({}, rest, { ref: modalRef, className: classnames('ffe-modal', className), "aria-labelledby": ariaLabelledby, onClick: function (event) {
|
|
57
60
|
var target = event.target;
|
|
@@ -65,5 +68,5 @@ export var Modal = React.forwardRef(function (_a, ref) {
|
|
|
65
68
|
} }),
|
|
66
69
|
React.createElement("div", { className: "ffe-modal__body" },
|
|
67
70
|
React.createElement(CloseButton, { onClick: function () { var _a; return (_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.close(); }, locale: locale }),
|
|
68
|
-
children)));
|
|
71
|
+
children)), document.body);
|
|
69
72
|
});
|
package/lib/Modal.js
CHANGED
|
@@ -50,12 +50,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
50
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
51
|
exports.Modal = void 0;
|
|
52
52
|
var react_1 = __importStar(require("react"));
|
|
53
|
+
var react_dom_1 = require("react-dom");
|
|
53
54
|
var classnames_1 = __importDefault(require("classnames"));
|
|
54
55
|
var CloseButton_1 = require("./CloseButton");
|
|
55
56
|
exports.Modal = react_1.default.forwardRef(function (_a, ref) {
|
|
56
57
|
var children = _a.children, onClick = _a.onClick, ariaLabelledby = _a.ariaLabelledby, className = _a.className, _b = _a.locale, locale = _b === void 0 ? 'nb' : _b, onClose = _a.onClose, rest = __rest(_a, ["children", "onClick", "ariaLabelledby", "className", "locale", "onClose"]);
|
|
57
58
|
var _c = (0, react_1.useState)(false), isOpen = _c[0], setIsOpen = _c[1];
|
|
58
59
|
var modalRef = (0, react_1.useRef)(null);
|
|
60
|
+
var htmlOverflowY = (0, react_1.useRef)(document.documentElement.style.overflowY);
|
|
59
61
|
(0, react_1.useImperativeHandle)(ref, function () { return ({
|
|
60
62
|
open: function () {
|
|
61
63
|
var _a;
|
|
@@ -69,18 +71,19 @@ exports.Modal = react_1.default.forwardRef(function (_a, ref) {
|
|
|
69
71
|
}); });
|
|
70
72
|
(0, react_1.useEffect)(function () {
|
|
71
73
|
var _a;
|
|
74
|
+
var html = document.documentElement;
|
|
72
75
|
var inShadow = ((_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.getRootNode()) instanceof ShadowRoot;
|
|
73
76
|
if (inShadow) {
|
|
74
|
-
var html = document.documentElement;
|
|
75
77
|
if (isOpen) {
|
|
76
|
-
html.
|
|
78
|
+
htmlOverflowY.current = html.style.overflowY;
|
|
79
|
+
html.style.overflowY = 'hidden';
|
|
77
80
|
}
|
|
78
|
-
else {
|
|
79
|
-
html.
|
|
81
|
+
else if (!isOpen) {
|
|
82
|
+
html.style.overflowY = htmlOverflowY.current;
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
}, [isOpen]);
|
|
83
|
-
return (
|
|
86
|
+
return (0, react_dom_1.createPortal)(
|
|
84
87
|
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
85
88
|
react_1.default.createElement("dialog", __assign({}, rest, { ref: modalRef, className: (0, classnames_1.default)('ffe-modal', className), "aria-labelledby": ariaLabelledby, onClick: function (event) {
|
|
86
89
|
var target = event.target;
|
|
@@ -94,5 +97,5 @@ exports.Modal = react_1.default.forwardRef(function (_a, ref) {
|
|
|
94
97
|
} }),
|
|
95
98
|
react_1.default.createElement("div", { className: "ffe-modal__body" },
|
|
96
99
|
react_1.default.createElement(CloseButton_1.CloseButton, { onClick: function () { var _a; return (_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.close(); }, locale: locale }),
|
|
97
|
-
children)));
|
|
100
|
+
children)), document.body);
|
|
98
101
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sb1/ffe-modals-react",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "SpareBank 1",
|
|
6
6
|
"files": [
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@sb1/ffe-icons-react": "^10.0.5",
|
|
29
|
-
"@sb1/ffe-modals": "^0.2.
|
|
29
|
+
"@sb1/ffe-modals": "^0.2.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@sb1/ffe-buildtool": "^0.6.4",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "9d6c8ac64616a7ac88ec366211487f59c4fcb450"
|
|
44
44
|
}
|