@coreui/react-pro 4.1.2 → 4.1.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/README.md CHANGED
@@ -43,7 +43,7 @@
43
43
 
44
44
  Several quick start options are available:
45
45
 
46
- - [Download the latest release](https://github.com/coreui/coreui-react/archive/v4.1.2.zip)
46
+ - [Download the latest release](https://github.com/coreui/coreui-react/archive/v4.1.3.zip)
47
47
  - Clone the repo: `git clone https://github.com/coreui/coreui-react.git`
48
48
  - Install with [npm](https://www.npmjs.com/): `npm install @coreui/react`
49
49
  - Install with [yarn](https://yarnpkg.com/): `yarn add @coreui/react`
@@ -52,6 +52,7 @@ export interface CModalProps extends HTMLAttributes<HTMLDivElement> {
52
52
  * Remove animation to create modal that simply appear rather than fade in to view.
53
53
  */
54
54
  transition?: boolean;
55
+ unmountOnClose?: boolean;
55
56
  /**
56
57
  * Toggle the visibility of modal component.
57
58
  */
package/dist/index.es.js CHANGED
@@ -6490,11 +6490,12 @@ CModalDialog.displayName = 'CModalDialog';
6490
6490
 
6491
6491
  var CModalContext = createContext({});
6492
6492
  var CModal = forwardRef(function (_a, ref) {
6493
- var children = _a.children, alignment = _a.alignment, _b = _a.backdrop, backdrop = _b === void 0 ? true : _b, className = _a.className, _c = _a.duration, duration = _c === void 0 ? 150 : _c, fullscreen = _a.fullscreen, _d = _a.keyboard, keyboard = _d === void 0 ? true : _d, onClose = _a.onClose, onClosePrevented = _a.onClosePrevented, onShow = _a.onShow, _e = _a.portal, portal = _e === void 0 ? true : _e, scrollable = _a.scrollable, size = _a.size, _f = _a.transition, transition = _f === void 0 ? true : _f, visible = _a.visible;
6493
+ var children = _a.children, alignment = _a.alignment, _b = _a.backdrop, backdrop = _b === void 0 ? true : _b, className = _a.className, _c = _a.duration, duration = _c === void 0 ? 150 : _c, fullscreen = _a.fullscreen, _d = _a.keyboard, keyboard = _d === void 0 ? true : _d, onClose = _a.onClose, onClosePrevented = _a.onClosePrevented, onShow = _a.onShow, _e = _a.portal, portal = _e === void 0 ? true : _e, scrollable = _a.scrollable, size = _a.size, _f = _a.transition, transition = _f === void 0 ? true : _f, _g = _a.unmountOnClose, unmountOnClose = _g === void 0 ? true : _g, visible = _a.visible;
6494
6494
  var modalRef = useRef(null);
6495
+ var modalContentRef = useRef(null);
6495
6496
  var forkedRef = useForkedRef(ref, modalRef);
6496
- var _g = useState(visible), _visible = _g[0], setVisible = _g[1];
6497
- var _h = useState(false), staticBackdrop = _h[0], setStaticBackdrop = _h[1];
6497
+ var _h = useState(visible), _visible = _h[0], setVisible = _h[1];
6498
+ var _j = useState(false), staticBackdrop = _j[0], setStaticBackdrop = _j[1];
6498
6499
  useEffect(function () {
6499
6500
  setVisible(visible);
6500
6501
  }, [visible]);
@@ -6502,6 +6503,14 @@ var CModal = forwardRef(function (_a, ref) {
6502
6503
  visible: _visible,
6503
6504
  setVisible: setVisible,
6504
6505
  };
6506
+ useEffect(function () {
6507
+ modalRef.current && modalRef.current.addEventListener('click', handleClickOutside);
6508
+ modalRef.current && modalRef.current.addEventListener('keyup', handleKeyDown);
6509
+ return function () {
6510
+ modalRef.current && modalRef.current.removeEventListener('click', handleClickOutside);
6511
+ modalRef.current && modalRef.current.removeEventListener('keyup', handleKeyDown);
6512
+ };
6513
+ }, [_visible]);
6505
6514
  var handleDismiss = function () {
6506
6515
  if (backdrop === 'static') {
6507
6516
  return setStaticBackdrop(true);
@@ -6539,6 +6548,12 @@ var CModal = forwardRef(function (_a, ref) {
6539
6548
  }
6540
6549
  return function () { return document.body.classList.remove('modal-open'); };
6541
6550
  }, [_visible]);
6551
+ var handleClickOutside = function (event) {
6552
+ if (modalContentRef.current &&
6553
+ !modalContentRef.current.contains(event.target)) {
6554
+ handleDismiss();
6555
+ }
6556
+ };
6542
6557
  var handleKeyDown = useCallback(function (event) {
6543
6558
  if (event.key === 'Escape' && keyboard) {
6544
6559
  return handleDismiss();
@@ -6547,17 +6562,16 @@ var CModal = forwardRef(function (_a, ref) {
6547
6562
  var modal = function (ref, transitionClass) {
6548
6563
  return (React__default.createElement(CModalContext.Provider, { value: contextValues },
6549
6564
  React__default.createElement("div", { className: classNames$1(_className, transitionClass), tabIndex: -1, role: "dialog", ref: ref },
6550
- React__default.createElement(CModalDialog, { alignment: alignment, fullscreen: fullscreen, scrollable: scrollable, size: size, onClick: function (event) { return event.stopPropagation(); } },
6551
- React__default.createElement(CModalContent, null, children)))));
6565
+ React__default.createElement(CModalDialog, { alignment: alignment, fullscreen: fullscreen, scrollable: scrollable, size: size },
6566
+ React__default.createElement(CModalContent, { ref: modalContentRef }, children)))));
6552
6567
  };
6553
6568
  return (React__default.createElement(React__default.Fragment, null,
6554
- React__default.createElement("div", { onClick: handleDismiss, onKeyDown: handleKeyDown },
6555
- React__default.createElement(Transition$1, { in: _visible, mountOnEnter: true, onEnter: onShow, onExit: onClose, unmountOnExit: true, timeout: !transition ? 0 : duration }, function (state) {
6556
- var transitionClass = getTransitionClass(state);
6557
- return typeof window !== 'undefined' && portal
6558
- ? createPortal(modal(forkedRef, transitionClass), document.body)
6559
- : modal(forkedRef, transitionClass);
6560
- })),
6569
+ React__default.createElement(Transition$1, { in: _visible, mountOnEnter: true, onEnter: onShow, onExit: onClose, unmountOnExit: unmountOnClose, timeout: !transition ? 0 : duration }, function (state) {
6570
+ var transitionClass = getTransitionClass(state);
6571
+ return typeof window !== 'undefined' && portal
6572
+ ? createPortal(modal(forkedRef, transitionClass), document.body)
6573
+ : modal(forkedRef, transitionClass);
6574
+ }),
6561
6575
  typeof window !== 'undefined' && portal
6562
6576
  ? backdrop && createPortal(React__default.createElement(CBackdrop, { visible: _visible }), document.body)
6563
6577
  : backdrop && React__default.createElement(CBackdrop, { visible: _visible })));
@@ -6580,6 +6594,7 @@ CModal.propTypes = {
6580
6594
  scrollable: PropTypes$1.bool,
6581
6595
  size: PropTypes$1.oneOf(['sm', 'lg', 'xl']),
6582
6596
  transition: PropTypes$1.bool,
6597
+ unmountOnClose: PropTypes$1.bool,
6583
6598
  visible: PropTypes$1.bool,
6584
6599
  };
6585
6600
  CModal.displayName = 'CModal';