@sb1/ffe-modals-react 0.4.1 → 0.4.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 +12 -6
- package/lib/Modal.js +12 -6
- package/package.json +6 -5
package/es/Modal.js
CHANGED
|
@@ -24,26 +24,27 @@ import React, { useEffect, useImperativeHandle, useState, useRef } from 'react';
|
|
|
24
24
|
import { createPortal } from 'react-dom';
|
|
25
25
|
import classnames from 'classnames';
|
|
26
26
|
import { CloseButton } from './CloseButton';
|
|
27
|
+
import dialogPolyfill from 'dialog-polyfill';
|
|
27
28
|
export var Modal = React.forwardRef(function (_a, ref) {
|
|
28
29
|
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, _c = _a.portalContainer, portalContainer = _c === void 0 ? document.body : _c, rest = __rest(_a, ["children", "onClick", "ariaLabelledby", "className", "locale", "onClose", "portalContainer"]);
|
|
29
30
|
var _d = useState(false), isOpen = _d[0], setIsOpen = _d[1];
|
|
30
|
-
var
|
|
31
|
+
var dialogRef = useRef(null);
|
|
31
32
|
var htmlOverflowY = useRef(document.documentElement.style.overflowY);
|
|
32
33
|
useImperativeHandle(ref, function () { return ({
|
|
33
34
|
open: function () {
|
|
34
35
|
var _a;
|
|
35
36
|
setIsOpen(true);
|
|
36
|
-
(_a =
|
|
37
|
+
(_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.showModal();
|
|
37
38
|
},
|
|
38
39
|
close: function () {
|
|
39
40
|
var _a;
|
|
40
|
-
(_a =
|
|
41
|
+
(_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
41
42
|
},
|
|
42
43
|
}); });
|
|
43
44
|
useEffect(function () {
|
|
44
45
|
var _a;
|
|
45
46
|
var html = document.documentElement;
|
|
46
|
-
var inShadow = ((_a =
|
|
47
|
+
var inShadow = ((_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.getRootNode()) instanceof ShadowRoot;
|
|
47
48
|
if (inShadow) {
|
|
48
49
|
if (isOpen) {
|
|
49
50
|
htmlOverflowY.current = html.style.overflowY;
|
|
@@ -54,9 +55,14 @@ export var Modal = React.forwardRef(function (_a, ref) {
|
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
}, [isOpen]);
|
|
58
|
+
useEffect(function () {
|
|
59
|
+
if (dialogRef.current) {
|
|
60
|
+
dialogPolyfill.registerDialog(dialogRef.current);
|
|
61
|
+
}
|
|
62
|
+
}, []);
|
|
57
63
|
return createPortal(
|
|
58
64
|
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
59
|
-
React.createElement("dialog", __assign({}, rest, { ref:
|
|
65
|
+
React.createElement("dialog", __assign({}, rest, { ref: dialogRef, className: classnames('ffe-modal', className), "aria-labelledby": ariaLabelledby, onClick: function (event) {
|
|
60
66
|
var target = event.target;
|
|
61
67
|
if (target.nodeName === 'DIALOG') {
|
|
62
68
|
target.close();
|
|
@@ -67,6 +73,6 @@ export var Modal = React.forwardRef(function (_a, ref) {
|
|
|
67
73
|
setIsOpen(false);
|
|
68
74
|
} }),
|
|
69
75
|
React.createElement("div", { className: "ffe-modal__body" },
|
|
70
|
-
React.createElement(CloseButton, { onClick: function () { var _a; return (_a =
|
|
76
|
+
React.createElement(CloseButton, { onClick: function () { var _a; return (_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.close(); }, locale: locale }),
|
|
71
77
|
children)), portalContainer);
|
|
72
78
|
});
|
package/lib/Modal.js
CHANGED
|
@@ -53,26 +53,27 @@ var react_1 = __importStar(require("react"));
|
|
|
53
53
|
var react_dom_1 = require("react-dom");
|
|
54
54
|
var classnames_1 = __importDefault(require("classnames"));
|
|
55
55
|
var CloseButton_1 = require("./CloseButton");
|
|
56
|
+
var dialog_polyfill_1 = __importDefault(require("dialog-polyfill"));
|
|
56
57
|
exports.Modal = react_1.default.forwardRef(function (_a, ref) {
|
|
57
58
|
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, _c = _a.portalContainer, portalContainer = _c === void 0 ? document.body : _c, rest = __rest(_a, ["children", "onClick", "ariaLabelledby", "className", "locale", "onClose", "portalContainer"]);
|
|
58
59
|
var _d = (0, react_1.useState)(false), isOpen = _d[0], setIsOpen = _d[1];
|
|
59
|
-
var
|
|
60
|
+
var dialogRef = (0, react_1.useRef)(null);
|
|
60
61
|
var htmlOverflowY = (0, react_1.useRef)(document.documentElement.style.overflowY);
|
|
61
62
|
(0, react_1.useImperativeHandle)(ref, function () { return ({
|
|
62
63
|
open: function () {
|
|
63
64
|
var _a;
|
|
64
65
|
setIsOpen(true);
|
|
65
|
-
(_a =
|
|
66
|
+
(_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.showModal();
|
|
66
67
|
},
|
|
67
68
|
close: function () {
|
|
68
69
|
var _a;
|
|
69
|
-
(_a =
|
|
70
|
+
(_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
70
71
|
},
|
|
71
72
|
}); });
|
|
72
73
|
(0, react_1.useEffect)(function () {
|
|
73
74
|
var _a;
|
|
74
75
|
var html = document.documentElement;
|
|
75
|
-
var inShadow = ((_a =
|
|
76
|
+
var inShadow = ((_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.getRootNode()) instanceof ShadowRoot;
|
|
76
77
|
if (inShadow) {
|
|
77
78
|
if (isOpen) {
|
|
78
79
|
htmlOverflowY.current = html.style.overflowY;
|
|
@@ -83,9 +84,14 @@ exports.Modal = react_1.default.forwardRef(function (_a, ref) {
|
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
}, [isOpen]);
|
|
87
|
+
(0, react_1.useEffect)(function () {
|
|
88
|
+
if (dialogRef.current) {
|
|
89
|
+
dialog_polyfill_1.default.registerDialog(dialogRef.current);
|
|
90
|
+
}
|
|
91
|
+
}, []);
|
|
86
92
|
return (0, react_dom_1.createPortal)(
|
|
87
93
|
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
88
|
-
react_1.default.createElement("dialog", __assign({}, rest, { ref:
|
|
94
|
+
react_1.default.createElement("dialog", __assign({}, rest, { ref: dialogRef, className: (0, classnames_1.default)('ffe-modal', className), "aria-labelledby": ariaLabelledby, onClick: function (event) {
|
|
89
95
|
var target = event.target;
|
|
90
96
|
if (target.nodeName === 'DIALOG') {
|
|
91
97
|
target.close();
|
|
@@ -96,6 +102,6 @@ exports.Modal = react_1.default.forwardRef(function (_a, ref) {
|
|
|
96
102
|
setIsOpen(false);
|
|
97
103
|
} }),
|
|
98
104
|
react_1.default.createElement("div", { className: "ffe-modal__body" },
|
|
99
|
-
react_1.default.createElement(CloseButton_1.CloseButton, { onClick: function () { var _a; return (_a =
|
|
105
|
+
react_1.default.createElement(CloseButton_1.CloseButton, { onClick: function () { var _a; return (_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.close(); }, locale: locale }),
|
|
100
106
|
children)), portalContainer);
|
|
101
107
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sb1/ffe-modals-react",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "SpareBank 1",
|
|
6
6
|
"files": [
|
|
@@ -25,11 +25,12 @@
|
|
|
25
25
|
"test:watch": "ffe-buildtool jest --watch"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@sb1/ffe-icons-react": "^11.0.
|
|
29
|
-
"@sb1/ffe-modals": "^0.2.
|
|
28
|
+
"@sb1/ffe-icons-react": "^11.0.1",
|
|
29
|
+
"@sb1/ffe-modals": "^0.2.7",
|
|
30
|
+
"dialog-polyfill": "^0.5.6"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"@sb1/ffe-buildtool": "^0.
|
|
33
|
+
"@sb1/ffe-buildtool": "^0.7.0",
|
|
33
34
|
"eslint": "^8.57.0",
|
|
34
35
|
"react": "^18.2.0",
|
|
35
36
|
"react-dom": "^18.2.0"
|
|
@@ -40,5 +41,5 @@
|
|
|
40
41
|
"publishConfig": {
|
|
41
42
|
"access": "public"
|
|
42
43
|
},
|
|
43
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "4c40e4f22244c9e051239caa01f52519a4add9dd"
|
|
44
45
|
}
|