@sb1/ffe-modals-react 0.3.2 → 0.3.4
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 +5 -4
- package/lib/Modal.js +5 -4
- package/package.json +2 -2
- package/types/Modal.d.ts +3 -0
package/es/Modal.js
CHANGED
|
@@ -21,11 +21,12 @@ 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
|
-
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
|
-
var
|
|
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, _c = _a.portalContainer, portalContainer = _c === void 0 ? document.body : _c, rest = __rest(_a, ["children", "onClick", "ariaLabelledby", "className", "locale", "onClose", "portalContainer"]);
|
|
29
|
+
var _d = useState(false), isOpen = _d[0], setIsOpen = _d[1];
|
|
29
30
|
var modalRef = useRef(null);
|
|
30
31
|
var htmlOverflowY = useRef(document.documentElement.style.overflowY);
|
|
31
32
|
useImperativeHandle(ref, function () { return ({
|
|
@@ -53,7 +54,7 @@ export var Modal = React.forwardRef(function (_a, ref) {
|
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
}, [isOpen]);
|
|
56
|
-
return (
|
|
57
|
+
return createPortal(
|
|
57
58
|
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
58
59
|
React.createElement("dialog", __assign({}, rest, { ref: modalRef, className: classnames('ffe-modal', className), "aria-labelledby": ariaLabelledby, onClick: function (event) {
|
|
59
60
|
var target = event.target;
|
|
@@ -67,5 +68,5 @@ export var Modal = React.forwardRef(function (_a, ref) {
|
|
|
67
68
|
} }),
|
|
68
69
|
React.createElement("div", { className: "ffe-modal__body" },
|
|
69
70
|
React.createElement(CloseButton, { onClick: function () { var _a; return (_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.close(); }, locale: locale }),
|
|
70
|
-
children)));
|
|
71
|
+
children)), portalContainer);
|
|
71
72
|
});
|
package/lib/Modal.js
CHANGED
|
@@ -50,11 +50,12 @@ 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
|
-
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
|
-
var
|
|
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, _c = _a.portalContainer, portalContainer = _c === void 0 ? document.body : _c, rest = __rest(_a, ["children", "onClick", "ariaLabelledby", "className", "locale", "onClose", "portalContainer"]);
|
|
58
|
+
var _d = (0, react_1.useState)(false), isOpen = _d[0], setIsOpen = _d[1];
|
|
58
59
|
var modalRef = (0, react_1.useRef)(null);
|
|
59
60
|
var htmlOverflowY = (0, react_1.useRef)(document.documentElement.style.overflowY);
|
|
60
61
|
(0, react_1.useImperativeHandle)(ref, function () { return ({
|
|
@@ -82,7 +83,7 @@ exports.Modal = react_1.default.forwardRef(function (_a, ref) {
|
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
}, [isOpen]);
|
|
85
|
-
return (
|
|
86
|
+
return (0, react_dom_1.createPortal)(
|
|
86
87
|
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
87
88
|
react_1.default.createElement("dialog", __assign({}, rest, { ref: modalRef, className: (0, classnames_1.default)('ffe-modal', className), "aria-labelledby": ariaLabelledby, onClick: function (event) {
|
|
88
89
|
var target = event.target;
|
|
@@ -96,5 +97,5 @@ exports.Modal = react_1.default.forwardRef(function (_a, ref) {
|
|
|
96
97
|
} }),
|
|
97
98
|
react_1.default.createElement("div", { className: "ffe-modal__body" },
|
|
98
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 }),
|
|
99
|
-
children)));
|
|
100
|
+
children)), portalContainer);
|
|
100
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.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "SpareBank 1",
|
|
6
6
|
"files": [
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "8260c42bcd273417732bc5628b25e9d1545c0704"
|
|
44
44
|
}
|
package/types/Modal.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
2
3
|
import { Locale } from './types';
|
|
3
4
|
export interface ModalProps extends React.ComponentPropsWithoutRef<'dialog'> {
|
|
4
5
|
/** Id of modal heading */
|
|
@@ -7,6 +8,8 @@ export interface ModalProps extends React.ComponentPropsWithoutRef<'dialog'> {
|
|
|
7
8
|
locale?: Locale;
|
|
8
9
|
/** Called when dialog is closed */
|
|
9
10
|
onClose?: () => void;
|
|
11
|
+
/** Container for portal, default is document.body */
|
|
12
|
+
portalContainer?: Parameters<typeof createPortal>[1];
|
|
10
13
|
}
|
|
11
14
|
export type ModalHandle = {
|
|
12
15
|
readonly open: () => void;
|