@sb1/ffe-modals-react 0.2.1 → 0.3.0

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,11 +20,11 @@ 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, 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
28
  var modalRef = useRef(null);
29
29
  useImperativeHandle(ref, function () { return ({
30
30
  open: function () {
@@ -36,6 +36,16 @@ export var Modal = React.forwardRef(function (_a, ref) {
36
36
  (_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.close();
37
37
  },
38
38
  }); });
39
+ 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]);
39
49
  return (
40
50
  // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
41
51
  React.createElement("dialog", __assign({}, rest, { ref: modalRef, className: classnames('ffe-modal', className), "aria-labelledby": ariaLabelledby, onClick: function (event) {
package/lib/Modal.js CHANGED
@@ -53,7 +53,7 @@ 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
57
  var modalRef = (0, react_1.useRef)(null);
58
58
  (0, react_1.useImperativeHandle)(ref, function () { return ({
59
59
  open: function () {
@@ -65,6 +65,16 @@ exports.Modal = react_1.default.forwardRef(function (_a, ref) {
65
65
  (_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.close();
66
66
  },
67
67
  }); });
68
+ (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]);
68
78
  return (
69
79
  // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
70
80
  react_1.default.createElement("dialog", __assign({}, rest, { ref: modalRef, className: (0, classnames_1.default)('ffe-modal', className), "aria-labelledby": ariaLabelledby, onClick: function (event) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sb1/ffe-modals-react",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
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": "f999ee39cf125cd064cf7472095476f5ba2061c9"
43
+ "gitHead": "5c8cab2bd05091251b3f1b51422c19949084c34e"
44
44
  }
package/types/Modal.d.ts CHANGED
@@ -5,6 +5,8 @@ export interface ModalProps extends React.ComponentPropsWithoutRef<'dialog'> {
5
5
  ariaLabelledby: string;
6
6
  /** Id of modal heading */
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;