@coreui/react 4.1.1 → 4.1.2

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.0.zip)
46
+ - [Download the latest release](https://github.com/coreui/coreui-react/archive/v4.1.2.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
@@ -358,6 +358,8 @@ var ReactPropTypesSecret$3 = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
358
358
 
359
359
  var ReactPropTypesSecret_1 = ReactPropTypesSecret$3;
360
360
 
361
+ var has$2 = Function.call.bind(Object.prototype.hasOwnProperty);
362
+
361
363
  /**
362
364
  * Copyright (c) 2013-present, Facebook, Inc.
363
365
  *
@@ -370,7 +372,7 @@ var printWarning$2 = function() {};
370
372
  if (process.env.NODE_ENV !== 'production') {
371
373
  var ReactPropTypesSecret$2 = ReactPropTypesSecret_1;
372
374
  var loggedTypeFailures = {};
373
- var has$1 = Function.call.bind(Object.prototype.hasOwnProperty);
375
+ var has$1 = has$2;
374
376
 
375
377
  printWarning$2 = function(text) {
376
378
  var message = 'Warning: ' + text;
@@ -382,7 +384,7 @@ if (process.env.NODE_ENV !== 'production') {
382
384
  // This error was thrown as a convenience so that you can use this stack
383
385
  // to find the callsite that caused this warning to fire.
384
386
  throw new Error(message);
385
- } catch (x) {}
387
+ } catch (x) { /**/ }
386
388
  };
387
389
  }
388
390
 
@@ -411,7 +413,8 @@ function checkPropTypes$1(typeSpecs, values, location, componentName, getStack)
411
413
  if (typeof typeSpecs[typeSpecName] !== 'function') {
412
414
  var err = Error(
413
415
  (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
414
- 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
416
+ 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' +
417
+ 'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.'
415
418
  );
416
419
  err.name = 'Invariant Violation';
417
420
  throw err;
@@ -470,9 +473,9 @@ var ReactIs$1 = reactIs.exports;
470
473
  var assign = objectAssign;
471
474
 
472
475
  var ReactPropTypesSecret$1 = ReactPropTypesSecret_1;
476
+ var has = has$2;
473
477
  var checkPropTypes = checkPropTypes_1;
474
478
 
475
- var has = Function.call.bind(Object.prototype.hasOwnProperty);
476
479
  var printWarning$1 = function() {};
477
480
 
478
481
  if (process.env.NODE_ENV !== 'production') {
@@ -573,6 +576,7 @@ var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
573
576
  // Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
574
577
  var ReactPropTypes = {
575
578
  array: createPrimitiveTypeChecker('array'),
579
+ bigint: createPrimitiveTypeChecker('bigint'),
576
580
  bool: createPrimitiveTypeChecker('boolean'),
577
581
  func: createPrimitiveTypeChecker('function'),
578
582
  number: createPrimitiveTypeChecker('number'),
@@ -618,8 +622,9 @@ var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
618
622
  * is prohibitively expensive if they are created too often, such as what
619
623
  * happens in oneOfType() for any type before the one that matched.
620
624
  */
621
- function PropTypeError(message) {
625
+ function PropTypeError(message, data) {
622
626
  this.message = message;
627
+ this.data = data && typeof data === 'object' ? data: {};
623
628
  this.stack = '';
624
629
  }
625
630
  // Make `instanceof Error` still work for returned errors.
@@ -654,7 +659,7 @@ var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
654
659
  ) {
655
660
  printWarning$1(
656
661
  'You are manually calling a React.PropTypes validation ' +
657
- 'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' +
662
+ 'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' +
658
663
  'and will throw in the standalone `prop-types` package. ' +
659
664
  'You may be seeing this warning due to a third-party PropTypes ' +
660
665
  'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.'
@@ -693,7 +698,10 @@ var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
693
698
  // 'of type `object`'.
694
699
  var preciseType = getPreciseType(propValue);
695
700
 
696
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
701
+ return new PropTypeError(
702
+ 'Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'),
703
+ {expectedType: expectedType}
704
+ );
697
705
  }
698
706
  return null;
699
707
  }
@@ -837,14 +845,19 @@ var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
837
845
  }
838
846
 
839
847
  function validate(props, propName, componentName, location, propFullName) {
848
+ var expectedTypes = [];
840
849
  for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
841
850
  var checker = arrayOfTypeCheckers[i];
842
- if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret$1) == null) {
851
+ var checkerResult = checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret$1);
852
+ if (checkerResult == null) {
843
853
  return null;
844
854
  }
855
+ if (checkerResult.data.hasOwnProperty('expectedType')) {
856
+ expectedTypes.push(checkerResult.data.expectedType);
857
+ }
845
858
  }
846
-
847
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
859
+ var expectedTypesMessage = (expectedTypes.length > 0) ? ', expected one of type [' + expectedTypes.join(', ') + ']': '';
860
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`' + expectedTypesMessage + '.'));
848
861
  }
849
862
  return createChainableTypeChecker(validate);
850
863
  }
@@ -859,6 +872,13 @@ var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
859
872
  return createChainableTypeChecker(validate);
860
873
  }
861
874
 
875
+ function invalidValidatorError(componentName, location, propFullName, key, type) {
876
+ return new PropTypeError(
877
+ (componentName || 'React class') + ': ' + location + ' type `' + propFullName + '.' + key + '` is invalid; ' +
878
+ 'it must be a function, usually from the `prop-types` package, but received `' + type + '`.'
879
+ );
880
+ }
881
+
862
882
  function createShapeTypeChecker(shapeTypes) {
863
883
  function validate(props, propName, componentName, location, propFullName) {
864
884
  var propValue = props[propName];
@@ -868,8 +888,8 @@ var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
868
888
  }
869
889
  for (var key in shapeTypes) {
870
890
  var checker = shapeTypes[key];
871
- if (!checker) {
872
- continue;
891
+ if (typeof checker !== 'function') {
892
+ return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));
873
893
  }
874
894
  var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret$1);
875
895
  if (error) {
@@ -888,16 +908,18 @@ var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
888
908
  if (propType !== 'object') {
889
909
  return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
890
910
  }
891
- // We need to check all keys in case some are required but missing from
892
- // props.
911
+ // We need to check all keys in case some are required but missing from props.
893
912
  var allKeys = assign({}, props[propName], shapeTypes);
894
913
  for (var key in allKeys) {
895
914
  var checker = shapeTypes[key];
915
+ if (has(shapeTypes, key) && typeof checker !== 'function') {
916
+ return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));
917
+ }
896
918
  if (!checker) {
897
919
  return new PropTypeError(
898
920
  'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' +
899
921
  '\nBad object: ' + JSON.stringify(props[propName], null, ' ') +
900
- '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ')
922
+ '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ')
901
923
  );
902
924
  }
903
925
  var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret$1);
@@ -1082,6 +1104,7 @@ var factoryWithThrowingShims = function() {
1082
1104
  // Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
1083
1105
  var ReactPropTypes = {
1084
1106
  array: shim,
1107
+ bigint: shim,
1085
1108
  bool: shim,
1086
1109
  func: shim,
1087
1110
  number: shim,
@@ -6410,11 +6433,12 @@ CModalDialog.displayName = 'CModalDialog';
6410
6433
 
6411
6434
  var CModalContext = createContext({});
6412
6435
  var CModal = forwardRef(function (_a, ref) {
6413
- 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;
6436
+ 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;
6414
6437
  var modalRef = useRef(null);
6438
+ var modalContentRef = useRef(null);
6415
6439
  var forkedRef = useForkedRef(ref, modalRef);
6416
- var _g = useState(visible), _visible = _g[0], setVisible = _g[1];
6417
- var _h = useState(false), staticBackdrop = _h[0], setStaticBackdrop = _h[1];
6440
+ var _h = useState(visible), _visible = _h[0], setVisible = _h[1];
6441
+ var _j = useState(false), staticBackdrop = _j[0], setStaticBackdrop = _j[1];
6418
6442
  useEffect(function () {
6419
6443
  setVisible(visible);
6420
6444
  }, [visible]);
@@ -6422,6 +6446,14 @@ var CModal = forwardRef(function (_a, ref) {
6422
6446
  visible: _visible,
6423
6447
  setVisible: setVisible,
6424
6448
  };
6449
+ useEffect(function () {
6450
+ modalRef.current && modalRef.current.addEventListener('click', handleClickOutside);
6451
+ modalRef.current && modalRef.current.addEventListener('keyup', handleKeyDown);
6452
+ return function () {
6453
+ modalRef.current && modalRef.current.removeEventListener('click', handleClickOutside);
6454
+ modalRef.current && modalRef.current.removeEventListener('keyup', handleKeyDown);
6455
+ };
6456
+ }, [_visible]);
6425
6457
  var handleDismiss = function () {
6426
6458
  if (backdrop === 'static') {
6427
6459
  return setStaticBackdrop(true);
@@ -6459,6 +6491,12 @@ var CModal = forwardRef(function (_a, ref) {
6459
6491
  }
6460
6492
  return function () { return document.body.classList.remove('modal-open'); };
6461
6493
  }, [_visible]);
6494
+ var handleClickOutside = function (event) {
6495
+ if (modalContentRef.current &&
6496
+ !modalContentRef.current.contains(event.target)) {
6497
+ handleDismiss();
6498
+ }
6499
+ };
6462
6500
  var handleKeyDown = useCallback(function (event) {
6463
6501
  if (event.key === 'Escape' && keyboard) {
6464
6502
  return handleDismiss();
@@ -6467,17 +6505,16 @@ var CModal = forwardRef(function (_a, ref) {
6467
6505
  var modal = function (ref, transitionClass) {
6468
6506
  return (React__default.createElement(CModalContext.Provider, { value: contextValues },
6469
6507
  React__default.createElement("div", { className: classNames(_className, transitionClass), tabIndex: -1, role: "dialog", ref: ref },
6470
- React__default.createElement(CModalDialog, { alignment: alignment, fullscreen: fullscreen, scrollable: scrollable, size: size, onClick: function (event) { return event.stopPropagation(); } },
6471
- React__default.createElement(CModalContent, null, children)))));
6508
+ React__default.createElement(CModalDialog, { alignment: alignment, fullscreen: fullscreen, scrollable: scrollable, size: size },
6509
+ React__default.createElement(CModalContent, { ref: modalContentRef }, children)))));
6472
6510
  };
6473
6511
  return (React__default.createElement(React__default.Fragment, null,
6474
- React__default.createElement("div", { onClick: handleDismiss, onKeyDown: handleKeyDown },
6475
- React__default.createElement(Transition$1, { in: _visible, mountOnEnter: true, onEnter: onShow, onExit: onClose, unmountOnExit: true, timeout: !transition ? 0 : duration }, function (state) {
6476
- var transitionClass = getTransitionClass(state);
6477
- return typeof window !== 'undefined' && portal
6478
- ? createPortal(modal(forkedRef, transitionClass), document.body)
6479
- : modal(forkedRef, transitionClass);
6480
- })),
6512
+ React__default.createElement(Transition$1, { in: _visible, mountOnEnter: true, onEnter: onShow, onExit: onClose, unmountOnExit: unmountOnClose, timeout: !transition ? 0 : duration }, function (state) {
6513
+ var transitionClass = getTransitionClass(state);
6514
+ return typeof window !== 'undefined' && portal
6515
+ ? createPortal(modal(forkedRef, transitionClass), document.body)
6516
+ : modal(forkedRef, transitionClass);
6517
+ }),
6481
6518
  typeof window !== 'undefined' && portal
6482
6519
  ? backdrop && createPortal(React__default.createElement(CBackdrop, { visible: _visible }), document.body)
6483
6520
  : backdrop && React__default.createElement(CBackdrop, { visible: _visible })));
@@ -6500,6 +6537,7 @@ CModal.propTypes = {
6500
6537
  scrollable: PropTypes.bool,
6501
6538
  size: PropTypes.oneOf(['sm', 'lg', 'xl']),
6502
6539
  transition: PropTypes.bool,
6540
+ unmountOnClose: PropTypes.bool,
6503
6541
  visible: PropTypes.bool,
6504
6542
  };
6505
6543
  CModal.displayName = 'CModal';