@sb1/ffe-modals-react 0.3.0 → 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 CHANGED
@@ -20,15 +20,17 @@ var __rest = (this && this.__rest) || function (s, e) {
20
20
  }
21
21
  return t;
22
22
  };
23
- import React, { useEffect, 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
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 () {
@@ -37,15 +39,18 @@ export var Modal = React.forwardRef(function (_a, ref) {
37
39
  },
38
40
  }); });
39
41
  useEffect(function () {
40
- var handleClose = function () {
41
- onClose === null || onClose === void 0 ? void 0 : onClose();
42
- };
43
- var modal = modalRef.current;
44
- modal === null || modal === void 0 ? void 0 : modal.addEventListener('close', handleClose);
45
- return function () {
46
- modal === null || modal === void 0 ? void 0 : modal.removeEventListener('close', handleClose);
47
- };
48
- }, [onClose]);
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]);
49
54
  return (
50
55
  // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
51
56
  React.createElement("dialog", __assign({}, rest, { ref: modalRef, className: classnames('ffe-modal', className), "aria-labelledby": ariaLabelledby, onClick: function (event) {
@@ -54,6 +59,9 @@ export var Modal = React.forwardRef(function (_a, ref) {
54
59
  target.close();
55
60
  }
56
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);
57
65
  } }),
58
66
  React.createElement("div", { className: "ffe-modal__body" },
59
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
@@ -54,10 +54,12 @@ 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
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 () {
@@ -66,15 +68,18 @@ exports.Modal = react_1.default.forwardRef(function (_a, ref) {
66
68
  },
67
69
  }); });
68
70
  (0, react_1.useEffect)(function () {
69
- var handleClose = function () {
70
- onClose === null || onClose === void 0 ? void 0 : onClose();
71
- };
72
- var modal = modalRef.current;
73
- modal === null || modal === void 0 ? void 0 : modal.addEventListener('close', handleClose);
74
- return function () {
75
- modal === null || modal === void 0 ? void 0 : modal.removeEventListener('close', handleClose);
76
- };
77
- }, [onClose]);
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]);
78
83
  return (
79
84
  // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
80
85
  react_1.default.createElement("dialog", __assign({}, rest, { ref: modalRef, className: (0, classnames_1.default)('ffe-modal', className), "aria-labelledby": ariaLabelledby, onClick: function (event) {
@@ -83,6 +88,9 @@ exports.Modal = react_1.default.forwardRef(function (_a, ref) {
83
88
  target.close();
84
89
  }
85
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);
86
94
  } }),
87
95
  react_1.default.createElement("div", { className: "ffe-modal__body" },
88
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.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.0"
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": "5c8cab2bd05091251b3f1b51422c19949084c34e"
43
+ "gitHead": "ae4935ebe34ac47c995c69128f860d53dcda1e21"
44
44
  }
package/types/Modal.d.ts CHANGED
@@ -3,7 +3,7 @@ import { Locale } from './types';
3
3
  export interface ModalProps extends React.ComponentPropsWithoutRef<'dialog'> {
4
4
  /** Id of modal heading */
5
5
  ariaLabelledby: string;
6
- /** Id of modal heading */
6
+ /** Locale used */
7
7
  locale?: Locale;
8
8
  /** Called when dialog is closed */
9
9
  onClose?: () => void;