@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 +1 -1
- package/dist/components/modal/CModal.d.ts +1 -0
- package/dist/index.es.js +27 -12
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +27 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/modal/CModal.tsx +42 -19
- package/src/components/modal/__tests__/CModal.spec.tsx +1 -1
- package/src/components/modal/__tests__/__snapshots__/CModal.spec.tsx.snap +2 -10
package/dist/index.js
CHANGED
|
@@ -6517,11 +6517,12 @@ CModalDialog.displayName = 'CModalDialog';
|
|
|
6517
6517
|
|
|
6518
6518
|
var CModalContext = React.createContext({});
|
|
6519
6519
|
var CModal = React.forwardRef(function (_a, ref) {
|
|
6520
|
-
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;
|
|
6520
|
+
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;
|
|
6521
6521
|
var modalRef = React.useRef(null);
|
|
6522
|
+
var modalContentRef = React.useRef(null);
|
|
6522
6523
|
var forkedRef = useForkedRef(ref, modalRef);
|
|
6523
|
-
var
|
|
6524
|
-
var
|
|
6524
|
+
var _h = React.useState(visible), _visible = _h[0], setVisible = _h[1];
|
|
6525
|
+
var _j = React.useState(false), staticBackdrop = _j[0], setStaticBackdrop = _j[1];
|
|
6525
6526
|
React.useEffect(function () {
|
|
6526
6527
|
setVisible(visible);
|
|
6527
6528
|
}, [visible]);
|
|
@@ -6529,6 +6530,14 @@ var CModal = React.forwardRef(function (_a, ref) {
|
|
|
6529
6530
|
visible: _visible,
|
|
6530
6531
|
setVisible: setVisible,
|
|
6531
6532
|
};
|
|
6533
|
+
React.useEffect(function () {
|
|
6534
|
+
modalRef.current && modalRef.current.addEventListener('click', handleClickOutside);
|
|
6535
|
+
modalRef.current && modalRef.current.addEventListener('keyup', handleKeyDown);
|
|
6536
|
+
return function () {
|
|
6537
|
+
modalRef.current && modalRef.current.removeEventListener('click', handleClickOutside);
|
|
6538
|
+
modalRef.current && modalRef.current.removeEventListener('keyup', handleKeyDown);
|
|
6539
|
+
};
|
|
6540
|
+
}, [_visible]);
|
|
6532
6541
|
var handleDismiss = function () {
|
|
6533
6542
|
if (backdrop === 'static') {
|
|
6534
6543
|
return setStaticBackdrop(true);
|
|
@@ -6566,6 +6575,12 @@ var CModal = React.forwardRef(function (_a, ref) {
|
|
|
6566
6575
|
}
|
|
6567
6576
|
return function () { return document.body.classList.remove('modal-open'); };
|
|
6568
6577
|
}, [_visible]);
|
|
6578
|
+
var handleClickOutside = function (event) {
|
|
6579
|
+
if (modalContentRef.current &&
|
|
6580
|
+
!modalContentRef.current.contains(event.target)) {
|
|
6581
|
+
handleDismiss();
|
|
6582
|
+
}
|
|
6583
|
+
};
|
|
6569
6584
|
var handleKeyDown = React.useCallback(function (event) {
|
|
6570
6585
|
if (event.key === 'Escape' && keyboard) {
|
|
6571
6586
|
return handleDismiss();
|
|
@@ -6574,17 +6589,16 @@ var CModal = React.forwardRef(function (_a, ref) {
|
|
|
6574
6589
|
var modal = function (ref, transitionClass) {
|
|
6575
6590
|
return (React__default["default"].createElement(CModalContext.Provider, { value: contextValues },
|
|
6576
6591
|
React__default["default"].createElement("div", { className: classNames$1(_className, transitionClass), tabIndex: -1, role: "dialog", ref: ref },
|
|
6577
|
-
React__default["default"].createElement(CModalDialog, { alignment: alignment, fullscreen: fullscreen, scrollable: scrollable, size: size
|
|
6578
|
-
React__default["default"].createElement(CModalContent,
|
|
6592
|
+
React__default["default"].createElement(CModalDialog, { alignment: alignment, fullscreen: fullscreen, scrollable: scrollable, size: size },
|
|
6593
|
+
React__default["default"].createElement(CModalContent, { ref: modalContentRef }, children)))));
|
|
6579
6594
|
};
|
|
6580
6595
|
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
6581
|
-
React__default["default"].createElement(
|
|
6582
|
-
|
|
6583
|
-
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
|
|
6587
|
-
})),
|
|
6596
|
+
React__default["default"].createElement(Transition$1, { in: _visible, mountOnEnter: true, onEnter: onShow, onExit: onClose, unmountOnExit: unmountOnClose, timeout: !transition ? 0 : duration }, function (state) {
|
|
6597
|
+
var transitionClass = getTransitionClass(state);
|
|
6598
|
+
return typeof window !== 'undefined' && portal
|
|
6599
|
+
? ReactDOM.createPortal(modal(forkedRef, transitionClass), document.body)
|
|
6600
|
+
: modal(forkedRef, transitionClass);
|
|
6601
|
+
}),
|
|
6588
6602
|
typeof window !== 'undefined' && portal
|
|
6589
6603
|
? backdrop && ReactDOM.createPortal(React__default["default"].createElement(CBackdrop, { visible: _visible }), document.body)
|
|
6590
6604
|
: backdrop && React__default["default"].createElement(CBackdrop, { visible: _visible })));
|
|
@@ -6607,6 +6621,7 @@ CModal.propTypes = {
|
|
|
6607
6621
|
scrollable: PropTypes$1.bool,
|
|
6608
6622
|
size: PropTypes$1.oneOf(['sm', 'lg', 'xl']),
|
|
6609
6623
|
transition: PropTypes$1.bool,
|
|
6624
|
+
unmountOnClose: PropTypes$1.bool,
|
|
6610
6625
|
visible: PropTypes$1.bool,
|
|
6611
6626
|
};
|
|
6612
6627
|
CModal.displayName = 'CModal';
|