@coreui/react 4.9.2 → 4.10.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/dist/index.js CHANGED
@@ -4311,14 +4311,103 @@ 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
+
4314
4398
  var usePopper = function () {
4315
4399
  var _popper = React.useRef();
4400
+ var el = React.useRef();
4316
4401
  var initPopper = function (reference, popper, options) {
4317
4402
  _popper.current = createPopper(reference, popper, options);
4403
+ el.current = popper;
4318
4404
  };
4319
4405
  var destroyPopper = function () {
4320
- if (_popper.current) {
4321
- _popper.current.destroy();
4406
+ var popperInstance = _popper.current;
4407
+ if (popperInstance && el.current) {
4408
+ executeAfterTransition(function () {
4409
+ popperInstance.destroy();
4410
+ }, el.current);
4322
4411
  }
4323
4412
  _popper.current = undefined;
4324
4413
  };
@@ -4834,38 +4923,6 @@ CCardTitle.propTypes = {
4834
4923
  };
4835
4924
  CCardTitle.displayName = 'CCardTitle';
4836
4925
 
4837
- var isRTL = function (element) {
4838
- if (typeof document !== 'undefined' && document.documentElement.dir === 'rtl') {
4839
- return true;
4840
- }
4841
- if (element) {
4842
- return element.closest('[dir="rtl"]') !== null;
4843
- }
4844
- return false;
4845
- };
4846
-
4847
- var getRTLPlacement = function (placement, element) {
4848
- switch (placement) {
4849
- case 'right': {
4850
- return isRTL(element) ? 'left' : 'right';
4851
- }
4852
- case 'left': {
4853
- return isRTL(element) ? 'right' : 'left';
4854
- }
4855
- default: {
4856
- return placement;
4857
- }
4858
- }
4859
- };
4860
-
4861
- var isInViewport = function (element) {
4862
- var rect = element.getBoundingClientRect();
4863
- return (Math.floor(rect.top) >= 0 &&
4864
- Math.floor(rect.left) >= 0 &&
4865
- Math.floor(rect.bottom) <= (window.innerHeight || document.documentElement.clientHeight) &&
4866
- Math.floor(rect.right) <= (window.innerWidth || document.documentElement.clientWidth));
4867
- };
4868
-
4869
4926
  var CCarouselContext = React.createContext({});
4870
4927
  var CCarousel = React.forwardRef(function (_a, ref) {
4871
4928
  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(_a, ["children", "activeIndex", "className", "controls", "dark", "indicators", "interval", "onSlid", "onSlide", "pause", "touch", "transition", "wrap"]);
@@ -5971,12 +6028,13 @@ CModalDialog.displayName = 'CModalDialog';
5971
6028
 
5972
6029
  var CModalContext = React.createContext({});
5973
6030
  var CModal = React.forwardRef(function (_a, ref) {
5974
- 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(_a, ["children", "alignment", "backdrop", "className", "duration", "fullscreen", "keyboard", "onClose", "onClosePrevented", "onShow", "portal", "scrollable", "size", "transition", "unmountOnClose", "visible"]);
6031
+ 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(_a, ["children", "alignment", "backdrop", "className", "duration", "focus", "fullscreen", "keyboard", "onClose", "onClosePrevented", "onShow", "portal", "scrollable", "size", "transition", "unmountOnClose", "visible"]);
6032
+ var activeElementRef = React.useRef(null);
5975
6033
  var modalRef = React.useRef(null);
5976
6034
  var modalContentRef = React.useRef(null);
5977
6035
  var forkedRef = useForkedRef(ref, modalRef);
5978
- var _h = React.useState(visible), _visible = _h[0], setVisible = _h[1];
5979
- var _j = React.useState(false), staticBackdrop = _j[0], setStaticBackdrop = _j[1];
6036
+ var _j = React.useState(visible), _visible = _j[0], setVisible = _j[1];
6037
+ var _k = React.useState(false), staticBackdrop = _k[0], setStaticBackdrop = _k[1];
5980
6038
  var contextValues = {
5981
6039
  visible: _visible,
5982
6040
  setVisible: setVisible,
@@ -5985,10 +6043,15 @@ var CModal = React.forwardRef(function (_a, ref) {
5985
6043
  setVisible(visible);
5986
6044
  }, [visible]);
5987
6045
  React.useEffect(function () {
6046
+ var _a;
5988
6047
  if (_visible) {
6048
+ activeElementRef.current = document.activeElement;
5989
6049
  document.addEventListener('mouseup', handleClickOutside);
5990
6050
  document.addEventListener('keydown', handleKeyDown);
5991
6051
  }
6052
+ else {
6053
+ (_a = activeElementRef.current) === null || _a === void 0 ? void 0 : _a.focus();
6054
+ }
5992
6055
  return function () {
5993
6056
  document.removeEventListener('mouseup', handleClickOutside);
5994
6057
  document.removeEventListener('keydown', handleKeyDown);
@@ -6015,7 +6078,7 @@ var CModal = React.forwardRef(function (_a, ref) {
6015
6078
  }
6016
6079
  setTimeout(function () {
6017
6080
  var _a;
6018
- (_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.focus();
6081
+ focus && ((_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.focus());
6019
6082
  }, transition ? duration : 0);
6020
6083
  }
6021
6084
  else {
@@ -6047,13 +6110,15 @@ var CModal = React.forwardRef(function (_a, ref) {
6047
6110
  return (React.createElement(React.Fragment, null,
6048
6111
  React.createElement(Transition$1, { in: _visible, mountOnEnter: true, nodeRef: modalRef, onEnter: onShow, onExit: onClose, unmountOnExit: unmountOnClose, timeout: transition ? duration : 0 }, function (state) { return (React.createElement(CConditionalPortal, { portal: portal },
6049
6112
  React.createElement(CModalContext.Provider, { value: contextValues },
6050
- React.createElement("div", { className: classNames('modal', {
6113
+ React.createElement("div", __assign({ className: classNames('modal', {
6051
6114
  'modal-static': staticBackdrop,
6052
6115
  fade: transition,
6053
6116
  show: state === 'entered',
6054
- }, className), tabIndex: -1, role: "dialog", style: __assign({}, (state !== 'exited' && { display: 'block' })), ref: forkedRef },
6117
+ }, className), tabIndex: -1 }, (_visible
6118
+ ? { 'aria-modal': true, role: 'dialog' }
6119
+ : { 'aria-hidden': 'true' }), { style: __assign({}, (state !== 'exited' && { display: 'block' })) }, rest, { ref: forkedRef }),
6055
6120
  React.createElement(CModalDialog, { alignment: alignment, fullscreen: fullscreen, scrollable: scrollable, size: size },
6056
- React.createElement(CModalContent, __assign({}, rest, { ref: modalContentRef }), children)))))); }),
6121
+ React.createElement(CModalContent, { ref: modalContentRef }, children)))))); }),
6057
6122
  backdrop && (React.createElement(CConditionalPortal, { portal: portal },
6058
6123
  React.createElement(CBackdrop, { visible: _visible })))));
6059
6124
  });
@@ -6063,6 +6128,7 @@ CModal.propTypes = {
6063
6128
  children: PropTypes.node,
6064
6129
  className: PropTypes.string,
6065
6130
  duration: PropTypes.number,
6131
+ focus: PropTypes.bool,
6066
6132
  fullscreen: PropTypes.oneOfType([
6067
6133
  PropTypes.bool,
6068
6134
  PropTypes.oneOf(['sm', 'md', 'lg', 'xl', 'xxl']),
@@ -6597,10 +6663,11 @@ CProgress.propTypes = {
6597
6663
  };
6598
6664
  CProgress.displayName = 'CProgress';
6599
6665
 
6600
- var CPopover = function (_a) {
6666
+ var CPopover = React.forwardRef(function (_a, ref) {
6601
6667
  var children = _a.children, _b = _a.animation, animation = _b === void 0 ? true : _b, className = _a.className, content = _a.content, _c = _a.delay, delay = _c === void 0 ? 0 : _c, _d = _a.fallbackPlacements, fallbackPlacements = _d === void 0 ? ['top', 'right', 'bottom', 'left'] : _d, _e = _a.offset, offset = _e === void 0 ? [0, 8] : _e, onHide = _a.onHide, onShow = _a.onShow, _f = _a.placement, placement = _f === void 0 ? 'top' : _f, title = _a.title, _g = _a.trigger, trigger = _g === void 0 ? 'click' : _g, visible = _a.visible, rest = __rest(_a, ["children", "animation", "className", "content", "delay", "fallbackPlacements", "offset", "onHide", "onShow", "placement", "title", "trigger", "visible"]);
6602
6668
  var popoverRef = React.useRef(null);
6603
6669
  var togglerRef = React.useRef(null);
6670
+ var forkedRef = useForkedRef(ref, popoverRef);
6604
6671
  var _h = usePopper(), initPopper = _h.initPopper, destroyPopper = _h.destroyPopper;
6605
6672
  var _j = React.useState(visible), _visible = _j[0], setVisible = _j[1];
6606
6673
  var _delay = typeof delay === 'number' ? { show: delay, hide: delay } : delay;
@@ -6658,15 +6725,17 @@ var CPopover = function (_a) {
6658
6725
  typeof window !== 'undefined' &&
6659
6726
  ReactDOM.createPortal(React.createElement(Transition$1, { in: _visible, mountOnEnter: true, nodeRef: popoverRef, onEnter: onShow, onExit: onHide, timeout: {
6660
6727
  enter: 0,
6661
- exit: 200,
6728
+ exit: popoverRef.current
6729
+ ? getTransitionDurationFromElement(popoverRef.current) + 50
6730
+ : 200,
6662
6731
  }, unmountOnExit: true }, function (state) { return (React.createElement("div", __assign({ className: classNames('popover', 'bs-popover-auto', {
6663
6732
  fade: animation,
6664
6733
  show: state === 'entered',
6665
- }, className), ref: popoverRef, role: "tooltip" }, rest),
6734
+ }, className), ref: forkedRef, role: "tooltip" }, rest),
6666
6735
  React.createElement("div", { className: "popover-arrow" }),
6667
6736
  React.createElement("div", { className: "popover-header" }, title),
6668
6737
  React.createElement("div", { className: "popover-body" }, content))); }), document.body)));
6669
- };
6738
+ });
6670
6739
  CPopover.propTypes = {
6671
6740
  animation: PropTypes.bool,
6672
6741
  children: PropTypes.node,
@@ -7210,10 +7279,11 @@ CToaster.propTypes = {
7210
7279
  };
7211
7280
  CToaster.displayName = 'CToaster';
7212
7281
 
7213
- var CTooltip = function (_a) {
7282
+ var CTooltip = React.forwardRef(function (_a, ref) {
7214
7283
  var children = _a.children, _b = _a.animation, animation = _b === void 0 ? true : _b, className = _a.className, content = _a.content, _c = _a.delay, delay = _c === void 0 ? 0 : _c, _d = _a.fallbackPlacements, fallbackPlacements = _d === void 0 ? ['top', 'right', 'bottom', 'left'] : _d, _e = _a.offset, offset = _e === void 0 ? [0, 6] : _e, onHide = _a.onHide, onShow = _a.onShow, _f = _a.placement, placement = _f === void 0 ? 'top' : _f, _g = _a.trigger, trigger = _g === void 0 ? ['hover', 'focus'] : _g, visible = _a.visible, rest = __rest(_a, ["children", "animation", "className", "content", "delay", "fallbackPlacements", "offset", "onHide", "onShow", "placement", "trigger", "visible"]);
7215
7284
  var tooltipRef = React.useRef(null);
7216
7285
  var togglerRef = React.useRef(null);
7286
+ var forkedRef = useForkedRef(ref, tooltipRef);
7217
7287
  var _h = usePopper(), initPopper = _h.initPopper, destroyPopper = _h.destroyPopper;
7218
7288
  var _j = React.useState(visible), _visible = _j[0], setVisible = _j[1];
7219
7289
  var _delay = typeof delay === 'number' ? { show: delay, hide: delay } : delay;
@@ -7269,16 +7339,18 @@ var CTooltip = function (_a) {
7269
7339
  onMouseLeave: function () { return toggleVisible(false); },
7270
7340
  }))),
7271
7341
  typeof window !== 'undefined' &&
7272
- ReactDOM.createPortal(React.createElement(Transition$1, { in: _visible, mountOnEnter: true, onEnter: onShow, onExit: onHide, timeout: {
7342
+ ReactDOM.createPortal(React.createElement(Transition$1, { in: _visible, mountOnEnter: true, nodeRef: tooltipRef, onEnter: onShow, onExit: onHide, timeout: {
7273
7343
  enter: 0,
7274
- exit: 200,
7344
+ exit: tooltipRef.current
7345
+ ? getTransitionDurationFromElement(tooltipRef.current) + 50
7346
+ : 200,
7275
7347
  }, unmountOnExit: true }, function (state) { return (React.createElement("div", __assign({ className: classNames('tooltip', 'bs-tooltip-auto', {
7276
7348
  fade: animation,
7277
7349
  show: state === 'entered',
7278
- }, className), ref: tooltipRef, role: "tooltip" }, rest),
7350
+ }, className), ref: forkedRef, role: "tooltip" }, rest),
7279
7351
  React.createElement("div", { className: "tooltip-arrow" }),
7280
7352
  React.createElement("div", { className: "tooltip-inner" }, content))); }), document.body)));
7281
- };
7353
+ });
7282
7354
  CTooltip.propTypes = {
7283
7355
  animation: PropTypes.bool,
7284
7356
  children: PropTypes.node,