@sb1/ffe-modals-react 0.2.1 → 0.3.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.
- package/es/Modal.js +20 -2
- package/lib/Modal.js +19 -1
- package/package.json +3 -3
- package/types/Modal.d.ts +3 -1
package/es/Modal.js
CHANGED
|
@@ -20,15 +20,17 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
}
|
|
21
21
|
return t;
|
|
22
22
|
};
|
|
23
|
-
import React, { useImperativeHandle, useRef } from 'react';
|
|
23
|
+
import React, { useEffect, useImperativeHandle, useState, useRef } from 'react';
|
|
24
24
|
import classnames from 'classnames';
|
|
25
25
|
import { CloseButton } from './CloseButton';
|
|
26
26
|
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, rest = __rest(_a, ["children", "onClick", "ariaLabelledby", "className", "locale"]);
|
|
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 _c = useState(false), isOpen = _c[0], setIsOpen = _c[1];
|
|
28
29
|
var modalRef = useRef(null);
|
|
29
30
|
useImperativeHandle(ref, function () { return ({
|
|
30
31
|
open: function () {
|
|
31
32
|
var _a;
|
|
33
|
+
setIsOpen(true);
|
|
32
34
|
(_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.showModal();
|
|
33
35
|
},
|
|
34
36
|
close: function () {
|
|
@@ -36,6 +38,19 @@ export var Modal = React.forwardRef(function (_a, ref) {
|
|
|
36
38
|
(_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
37
39
|
},
|
|
38
40
|
}); });
|
|
41
|
+
useEffect(function () {
|
|
42
|
+
var _a;
|
|
43
|
+
var inShadow = ((_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.getRootNode()) instanceof ShadowRoot;
|
|
44
|
+
if (inShadow) {
|
|
45
|
+
var html = document.documentElement;
|
|
46
|
+
if (isOpen) {
|
|
47
|
+
html.classList.add('ffe-modal__root');
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
html.classList.remove('ffe-modal__root');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}, [isOpen]);
|
|
39
54
|
return (
|
|
40
55
|
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
41
56
|
React.createElement("dialog", __assign({}, rest, { ref: modalRef, className: classnames('ffe-modal', className), "aria-labelledby": ariaLabelledby, onClick: function (event) {
|
|
@@ -44,6 +59,9 @@ export var Modal = React.forwardRef(function (_a, ref) {
|
|
|
44
59
|
target.close();
|
|
45
60
|
}
|
|
46
61
|
onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
|
62
|
+
}, onClose: function () {
|
|
63
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
64
|
+
setIsOpen(false);
|
|
47
65
|
} }),
|
|
48
66
|
React.createElement("div", { className: "ffe-modal__body" },
|
|
49
67
|
React.createElement(CloseButton, { onClick: function () { var _a; return (_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.close(); }, locale: locale }),
|
package/lib/Modal.js
CHANGED
|
@@ -53,11 +53,13 @@ var react_1 = __importStar(require("react"));
|
|
|
53
53
|
var classnames_1 = __importDefault(require("classnames"));
|
|
54
54
|
var CloseButton_1 = require("./CloseButton");
|
|
55
55
|
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, rest = __rest(_a, ["children", "onClick", "ariaLabelledby", "className", "locale"]);
|
|
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 _c = (0, react_1.useState)(false), isOpen = _c[0], setIsOpen = _c[1];
|
|
57
58
|
var modalRef = (0, react_1.useRef)(null);
|
|
58
59
|
(0, react_1.useImperativeHandle)(ref, function () { return ({
|
|
59
60
|
open: function () {
|
|
60
61
|
var _a;
|
|
62
|
+
setIsOpen(true);
|
|
61
63
|
(_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.showModal();
|
|
62
64
|
},
|
|
63
65
|
close: function () {
|
|
@@ -65,6 +67,19 @@ exports.Modal = react_1.default.forwardRef(function (_a, ref) {
|
|
|
65
67
|
(_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
66
68
|
},
|
|
67
69
|
}); });
|
|
70
|
+
(0, react_1.useEffect)(function () {
|
|
71
|
+
var _a;
|
|
72
|
+
var inShadow = ((_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.getRootNode()) instanceof ShadowRoot;
|
|
73
|
+
if (inShadow) {
|
|
74
|
+
var html = document.documentElement;
|
|
75
|
+
if (isOpen) {
|
|
76
|
+
html.classList.add('ffe-modal__root');
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
html.classList.remove('ffe-modal__root');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}, [isOpen]);
|
|
68
83
|
return (
|
|
69
84
|
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
70
85
|
react_1.default.createElement("dialog", __assign({}, rest, { ref: modalRef, className: (0, classnames_1.default)('ffe-modal', className), "aria-labelledby": ariaLabelledby, onClick: function (event) {
|
|
@@ -73,6 +88,9 @@ exports.Modal = react_1.default.forwardRef(function (_a, ref) {
|
|
|
73
88
|
target.close();
|
|
74
89
|
}
|
|
75
90
|
onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
|
91
|
+
}, onClose: function () {
|
|
92
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
93
|
+
setIsOpen(false);
|
|
76
94
|
} }),
|
|
77
95
|
react_1.default.createElement("div", { className: "ffe-modal__body" },
|
|
78
96
|
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 }),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sb1/ffe-modals-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
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.1"
|
|
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": "ae4935ebe34ac47c995c69128f860d53dcda1e21"
|
|
44
44
|
}
|
package/types/Modal.d.ts
CHANGED
|
@@ -3,8 +3,10 @@ import { Locale } from './types';
|
|
|
3
3
|
export interface ModalProps extends React.ComponentPropsWithoutRef<'dialog'> {
|
|
4
4
|
/** Id of modal heading */
|
|
5
5
|
ariaLabelledby: string;
|
|
6
|
-
/**
|
|
6
|
+
/** Locale used */
|
|
7
7
|
locale?: Locale;
|
|
8
|
+
/** Called when dialog is closed */
|
|
9
|
+
onClose?: () => void;
|
|
8
10
|
}
|
|
9
11
|
export type ModalHandle = {
|
|
10
12
|
readonly open: () => void;
|