@coreui/react-pro 4.12.4 → 4.13.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/README.md CHANGED
@@ -42,7 +42,7 @@
42
42
 
43
43
  Several quick start options are available:
44
44
 
45
- - [Download the latest release](https://github.com/coreui/coreui-react-pro/archive/v4.12.4.zip)
45
+ - [Download the latest release](https://github.com/coreui/coreui-react-pro/archive/v4.13.1.zip)
46
46
  - Clone the repo: `git clone https://github.com/coreui/coreui-react.git`
47
47
  - Install with [npm](https://www.npmjs.com/): `npm install @coreui/react`
48
48
  - Install with [yarn](https://yarnpkg.com/): `yarn add @coreui/react`
@@ -16,6 +16,12 @@ export interface CModalProps extends HTMLAttributes<HTMLDivElement> {
16
16
  * @ignore
17
17
  */
18
18
  duration?: number;
19
+ /**
20
+ * Puts the focus on the modal when shown.
21
+ *
22
+ * @since v4.10.0
23
+ */
24
+ focus?: boolean;
19
25
  /**
20
26
  * Set modal to covers the entire user viewport.
21
27
  */
package/dist/index.es.js CHANGED
@@ -4311,14 +4311,117 @@ var createPopper = /*#__PURE__*/popperGenerator({
4311
4311
  defaultModifiers: defaultModifiers
4312
4312
  }); // eslint-disable-next-line import/no-unused-modules
4313
4313
 
4314
+ var getTransitionDurationFromElement = function (element) {
4315
+ if (!element) {
4316
+ return 0;
4317
+ }
4318
+ // Get transition-duration of the element
4319
+ var _a = window.getComputedStyle(element), transitionDuration = _a.transitionDuration, transitionDelay = _a.transitionDelay;
4320
+ var floatTransitionDuration = Number.parseFloat(transitionDuration);
4321
+ var floatTransitionDelay = Number.parseFloat(transitionDelay);
4322
+ // Return 0 if element or transition duration is not found
4323
+ if (!floatTransitionDuration && !floatTransitionDelay) {
4324
+ return 0;
4325
+ }
4326
+ // If multiple durations are defined, take the first
4327
+ transitionDuration = transitionDuration.split(',')[0];
4328
+ transitionDelay = transitionDelay.split(',')[0];
4329
+ return (Number.parseFloat(transitionDuration) + Number.parseFloat(transitionDelay)) * 1000;
4330
+ };
4331
+
4332
+ var execute = function (callback) {
4333
+ if (typeof callback === 'function') {
4334
+ callback();
4335
+ }
4336
+ };
4337
+ var triggerTransitionEnd = function (element) {
4338
+ element.dispatchEvent(new Event('transitionend'));
4339
+ };
4340
+ var executeAfterTransition = function (callback, transitionElement, waitForTransition) {
4341
+ if (waitForTransition === void 0) { waitForTransition = true; }
4342
+ if (!waitForTransition) {
4343
+ execute(callback);
4344
+ return;
4345
+ }
4346
+ var durationPadding = 5;
4347
+ var emulatedDuration = getTransitionDurationFromElement(transitionElement) + durationPadding;
4348
+ var called = false;
4349
+ var handler = function (_a) {
4350
+ var target = _a.target;
4351
+ if (target !== transitionElement) {
4352
+ return;
4353
+ }
4354
+ called = true;
4355
+ transitionElement.removeEventListener('transitionend', handler);
4356
+ execute(callback);
4357
+ };
4358
+ transitionElement.addEventListener('transitionend', handler);
4359
+ setTimeout(function () {
4360
+ if (!called) {
4361
+ triggerTransitionEnd(transitionElement);
4362
+ }
4363
+ }, emulatedDuration);
4364
+ };
4365
+
4366
+ var isRTL = function (element) {
4367
+ if (typeof document !== 'undefined' && document.documentElement.dir === 'rtl') {
4368
+ return true;
4369
+ }
4370
+ if (element) {
4371
+ return element.closest('[dir="rtl"]') !== null;
4372
+ }
4373
+ return false;
4374
+ };
4375
+
4376
+ var getRTLPlacement = function (placement, element) {
4377
+ switch (placement) {
4378
+ case 'right': {
4379
+ return isRTL(element) ? 'left' : 'right';
4380
+ }
4381
+ case 'left': {
4382
+ return isRTL(element) ? 'right' : 'left';
4383
+ }
4384
+ default: {
4385
+ return placement;
4386
+ }
4387
+ }
4388
+ };
4389
+
4390
+ var isInViewport = function (element) {
4391
+ var rect = element.getBoundingClientRect();
4392
+ return (Math.floor(rect.top) >= 0 &&
4393
+ Math.floor(rect.left) >= 0 &&
4394
+ Math.floor(rect.bottom) <= (window.innerHeight || document.documentElement.clientHeight) &&
4395
+ Math.floor(rect.right) <= (window.innerWidth || document.documentElement.clientWidth));
4396
+ };
4397
+
4398
+ var isObjectInArray = function (array, item, ignore) {
4399
+ if (ignore === void 0) { ignore = []; }
4400
+ return array.some(function (_item) {
4401
+ var result = true;
4402
+ for (var key in item) {
4403
+ if (!ignore.includes(key) && item[key] !== _item[key]) {
4404
+ result = false;
4405
+ break;
4406
+ }
4407
+ }
4408
+ return result;
4409
+ });
4410
+ };
4411
+
4314
4412
  var usePopper = function () {
4315
4413
  var _popper = useRef();
4414
+ var el = useRef();
4316
4415
  var initPopper = function (reference, popper, options) {
4317
4416
  _popper.current = createPopper(reference, popper, options);
4417
+ el.current = popper;
4318
4418
  };
4319
4419
  var destroyPopper = function () {
4320
- if (_popper.current) {
4321
- _popper.current.destroy();
4420
+ var popperInstance = _popper.current;
4421
+ if (popperInstance && el.current) {
4422
+ executeAfterTransition(function () {
4423
+ popperInstance.destroy();
4424
+ }, el.current);
4322
4425
  }
4323
4426
  _popper.current = undefined;
4324
4427
  };
@@ -4853,52 +4956,6 @@ CCardTitle.propTypes = {
4853
4956
  };
4854
4957
  CCardTitle.displayName = 'CCardTitle';
4855
4958
 
4856
- var isRTL = function (element) {
4857
- if (typeof document !== 'undefined' && document.documentElement.dir === 'rtl') {
4858
- return true;
4859
- }
4860
- if (element) {
4861
- return element.closest('[dir="rtl"]') !== null;
4862
- }
4863
- return false;
4864
- };
4865
-
4866
- var getRTLPlacement = function (placement, element) {
4867
- switch (placement) {
4868
- case 'right': {
4869
- return isRTL(element) ? 'left' : 'right';
4870
- }
4871
- case 'left': {
4872
- return isRTL(element) ? 'right' : 'left';
4873
- }
4874
- default: {
4875
- return placement;
4876
- }
4877
- }
4878
- };
4879
-
4880
- var isInViewport = function (element) {
4881
- var rect = element.getBoundingClientRect();
4882
- return (Math.floor(rect.top) >= 0 &&
4883
- Math.floor(rect.left) >= 0 &&
4884
- Math.floor(rect.bottom) <= (window.innerHeight || document.documentElement.clientHeight) &&
4885
- Math.floor(rect.right) <= (window.innerWidth || document.documentElement.clientWidth));
4886
- };
4887
-
4888
- var isObjectInArray = function (array, item, ignore) {
4889
- if (ignore === void 0) { ignore = []; }
4890
- return array.some(function (_item) {
4891
- var result = true;
4892
- for (var key in item) {
4893
- if (!ignore.includes(key) && item[key] !== _item[key]) {
4894
- result = false;
4895
- break;
4896
- }
4897
- }
4898
- return result;
4899
- });
4900
- };
4901
-
4902
4959
  var CCarouselContext = createContext({});
4903
4960
  var CCarousel = forwardRef(function (_a, ref) {
4904
4961
  var children = _a.children, _b = _a.activeIndex, activeIndex = _b === void 0 ? 0 : _b, className = _a.className, controls = _a.controls, dark = _a.dark, indicators = _a.indicators, _c = _a.interval, interval = _c === void 0 ? 5000 : _c, onSlid = _a.onSlid, onSlide = _a.onSlide, _d = _a.pause, pause = _d === void 0 ? 'hover' : _d, _e = _a.touch, touch = _e === void 0 ? true : _e, transition = _a.transition, _f = _a.wrap, wrap = _f === void 0 ? true : _f, rest = __rest$1(_a, ["children", "activeIndex", "className", "controls", "dark", "indicators", "interval", "onSlid", "onSlide", "pause", "touch", "transition", "wrap"]);
@@ -10472,12 +10529,13 @@ CModalDialog.displayName = 'CModalDialog';
10472
10529
 
10473
10530
  var CModalContext = createContext({});
10474
10531
  var CModal = forwardRef(function (_a, ref) {
10475
- 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, rest = __rest$1(_a, ["children", "alignment", "backdrop", "className", "duration", "fullscreen", "keyboard", "onClose", "onClosePrevented", "onShow", "portal", "scrollable", "size", "transition", "unmountOnClose", "visible"]);
10532
+ 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, _d = _a.focus, focus = _d === void 0 ? true : _d, fullscreen = _a.fullscreen, _e = _a.keyboard, keyboard = _e === void 0 ? true : _e, onClose = _a.onClose, onClosePrevented = _a.onClosePrevented, onShow = _a.onShow, _f = _a.portal, portal = _f === void 0 ? true : _f, scrollable = _a.scrollable, size = _a.size, _g = _a.transition, transition = _g === void 0 ? true : _g, _h = _a.unmountOnClose, unmountOnClose = _h === void 0 ? true : _h, visible = _a.visible, rest = __rest$1(_a, ["children", "alignment", "backdrop", "className", "duration", "focus", "fullscreen", "keyboard", "onClose", "onClosePrevented", "onShow", "portal", "scrollable", "size", "transition", "unmountOnClose", "visible"]);
10533
+ var activeElementRef = useRef(null);
10476
10534
  var modalRef = useRef(null);
10477
10535
  var modalContentRef = useRef(null);
10478
10536
  var forkedRef = useForkedRef(ref, modalRef);
10479
- var _h = useState(visible), _visible = _h[0], setVisible = _h[1];
10480
- var _j = useState(false), staticBackdrop = _j[0], setStaticBackdrop = _j[1];
10537
+ var _j = useState(visible), _visible = _j[0], setVisible = _j[1];
10538
+ var _k = useState(false), staticBackdrop = _k[0], setStaticBackdrop = _k[1];
10481
10539
  var contextValues = {
10482
10540
  visible: _visible,
10483
10541
  setVisible: setVisible,
@@ -10486,10 +10544,15 @@ var CModal = forwardRef(function (_a, ref) {
10486
10544
  setVisible(visible);
10487
10545
  }, [visible]);
10488
10546
  useEffect(function () {
10547
+ var _a;
10489
10548
  if (_visible) {
10549
+ activeElementRef.current = document.activeElement;
10490
10550
  document.addEventListener('mouseup', handleClickOutside);
10491
10551
  document.addEventListener('keydown', handleKeyDown);
10492
10552
  }
10553
+ else {
10554
+ (_a = activeElementRef.current) === null || _a === void 0 ? void 0 : _a.focus();
10555
+ }
10493
10556
  return function () {
10494
10557
  document.removeEventListener('mouseup', handleClickOutside);
10495
10558
  document.removeEventListener('keydown', handleKeyDown);
@@ -10516,7 +10579,7 @@ var CModal = forwardRef(function (_a, ref) {
10516
10579
  }
10517
10580
  setTimeout(function () {
10518
10581
  var _a;
10519
- (_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.focus();
10582
+ focus && ((_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.focus());
10520
10583
  }, transition ? duration : 0);
10521
10584
  }
10522
10585
  else {
@@ -10548,13 +10611,15 @@ var CModal = forwardRef(function (_a, ref) {
10548
10611
  return (React$1.createElement(React$1.Fragment, null,
10549
10612
  React$1.createElement(Transition$1, { in: _visible, mountOnEnter: true, nodeRef: modalRef, onEnter: onShow, onExit: onClose, unmountOnExit: unmountOnClose, timeout: transition ? duration : 0 }, function (state) { return (React$1.createElement(CConditionalPortal, { portal: portal },
10550
10613
  React$1.createElement(CModalContext.Provider, { value: contextValues },
10551
- React$1.createElement("div", { className: classNames$1('modal', {
10614
+ React$1.createElement("div", __assign$1({ className: classNames$1('modal', {
10552
10615
  'modal-static': staticBackdrop,
10553
10616
  fade: transition,
10554
10617
  show: state === 'entered',
10555
- }, className), tabIndex: -1, role: "dialog", style: __assign$1({}, (state !== 'exited' && { display: 'block' })), ref: forkedRef },
10618
+ }, className), tabIndex: -1 }, (_visible
10619
+ ? { 'aria-modal': true, role: 'dialog' }
10620
+ : { 'aria-hidden': 'true' }), { style: __assign$1({}, (state !== 'exited' && { display: 'block' })) }, rest, { ref: forkedRef }),
10556
10621
  React$1.createElement(CModalDialog, { alignment: alignment, fullscreen: fullscreen, scrollable: scrollable, size: size },
10557
- React$1.createElement(CModalContent, __assign$1({}, rest, { ref: modalContentRef }), children)))))); }),
10622
+ React$1.createElement(CModalContent, { ref: modalContentRef }, children)))))); }),
10558
10623
  backdrop && (React$1.createElement(CConditionalPortal, { portal: portal },
10559
10624
  React$1.createElement(CBackdrop, { visible: _visible })))));
10560
10625
  });
@@ -10564,6 +10629,7 @@ CModal.propTypes = {
10564
10629
  children: PropTypes$1.node,
10565
10630
  className: PropTypes$1.string,
10566
10631
  duration: PropTypes$1.number,
10632
+ focus: PropTypes$1.bool,
10567
10633
  fullscreen: PropTypes$1.oneOfType([
10568
10634
  PropTypes$1.bool,
10569
10635
  PropTypes$1.oneOf(['sm', 'md', 'lg', 'xl', 'xxl']),
@@ -11068,7 +11134,7 @@ var CMultiSelect = forwardRef(function (_a, ref) {
11068
11134
  setSelected(selected.filter(function (option) { return option.disabled; }));
11069
11135
  };
11070
11136
  return (React$1.createElement(CFormControlWrapper, { describedby: rest['aria-describedby'], feedback: feedback, feedbackInvalid: feedbackInvalid, feedbackValid: feedbackValid, id: id, invalid: invalid, label: label, text: text, tooltipFeedback: tooltipFeedback, valid: valid },
11071
- React$1.createElement(CMultiSelectNativeSelect, { id: id, multiple: multiple, options: selected, required: required, value: multiple
11137
+ React$1.createElement(CMultiSelectNativeSelect, { className: 'form-multi-select', id: id, multiple: multiple, options: selected, required: required, value: multiple
11072
11138
  ? selected.map(function (option) { return option.value.toString(); })
11073
11139
  : selected.map(function (option) { return option.value; })[0], onChange: function () { return onChange && onChange(selected); }, ref: nativeSelectRef }),
11074
11140
  React$1.createElement("div", { className: classNames$1('form-multi-select', (_b = {
@@ -11632,7 +11698,7 @@ var CPopover = function (_a) {
11632
11698
  typeof window !== 'undefined' &&
11633
11699
  createPortal(React$1.createElement(Transition$1, { in: _visible, mountOnEnter: true, nodeRef: popoverRef, onEnter: onShow, onExit: onHide, timeout: {
11634
11700
  enter: 0,
11635
- exit: 200,
11701
+ exit: popoverRef.current ? getTransitionDurationFromElement(popoverRef.current) + 50 : 200,
11636
11702
  }, unmountOnExit: true }, function (state) { return (React$1.createElement("div", __assign$1({ className: classNames$1('popover', 'bs-popover-auto', {
11637
11703
  fade: animation,
11638
11704
  show: state === 'entered',
@@ -14336,7 +14402,7 @@ var CTooltip = function (_a) {
14336
14402
  typeof window !== 'undefined' &&
14337
14403
  createPortal(React$1.createElement(Transition$1, { in: _visible, mountOnEnter: true, onEnter: onShow, onExit: onHide, timeout: {
14338
14404
  enter: 0,
14339
- exit: 200,
14405
+ exit: tooltipRef.current ? getTransitionDurationFromElement(tooltipRef.current) + 50 : 200,
14340
14406
  }, unmountOnExit: true }, function (state) { return (React$1.createElement("div", __assign$1({ className: classNames$1('tooltip', 'bs-tooltip-auto', {
14341
14407
  fade: animation,
14342
14408
  show: state === 'entered',