@coreui/react-pro 4.12.4 → 4.13.0
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 +6 -0
- package/dist/index.es.js +123 -57
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +123 -57
- package/dist/index.js.map +1 -1
- package/dist/utils/executeAfterTransition.d.ts +2 -0
- package/dist/utils/getTransitionDurationFromElement.d.ts +2 -0
- package/dist/utils/index.d.ts +3 -1
- package/package.json +1 -1
- package/src/components/modal/CModal.tsx +20 -6
- package/src/components/offcanvas/COffcanvas.tsx +1 -1
- package/src/components/popover/CPopover.tsx +2 -2
- package/src/components/sidebar/CSidebar.tsx +1 -1
- package/src/components/tooltip/CTooltip.tsx +2 -2
- package/src/hooks/usePopper.ts +10 -2
- package/src/utils/executeAfterTransition.ts +46 -0
- package/src/utils/getTransitionDurationFromElement.ts +24 -0
- package/src/utils/index.ts +10 -1
package/dist/index.js
CHANGED
|
@@ -4313,14 +4313,117 @@ var createPopper = /*#__PURE__*/popperGenerator({
|
|
|
4313
4313
|
defaultModifiers: defaultModifiers
|
|
4314
4314
|
}); // eslint-disable-next-line import/no-unused-modules
|
|
4315
4315
|
|
|
4316
|
+
var getTransitionDurationFromElement = function (element) {
|
|
4317
|
+
if (!element) {
|
|
4318
|
+
return 0;
|
|
4319
|
+
}
|
|
4320
|
+
// Get transition-duration of the element
|
|
4321
|
+
var _a = window.getComputedStyle(element), transitionDuration = _a.transitionDuration, transitionDelay = _a.transitionDelay;
|
|
4322
|
+
var floatTransitionDuration = Number.parseFloat(transitionDuration);
|
|
4323
|
+
var floatTransitionDelay = Number.parseFloat(transitionDelay);
|
|
4324
|
+
// Return 0 if element or transition duration is not found
|
|
4325
|
+
if (!floatTransitionDuration && !floatTransitionDelay) {
|
|
4326
|
+
return 0;
|
|
4327
|
+
}
|
|
4328
|
+
// If multiple durations are defined, take the first
|
|
4329
|
+
transitionDuration = transitionDuration.split(',')[0];
|
|
4330
|
+
transitionDelay = transitionDelay.split(',')[0];
|
|
4331
|
+
return (Number.parseFloat(transitionDuration) + Number.parseFloat(transitionDelay)) * 1000;
|
|
4332
|
+
};
|
|
4333
|
+
|
|
4334
|
+
var execute = function (callback) {
|
|
4335
|
+
if (typeof callback === 'function') {
|
|
4336
|
+
callback();
|
|
4337
|
+
}
|
|
4338
|
+
};
|
|
4339
|
+
var triggerTransitionEnd = function (element) {
|
|
4340
|
+
element.dispatchEvent(new Event('transitionend'));
|
|
4341
|
+
};
|
|
4342
|
+
var executeAfterTransition = function (callback, transitionElement, waitForTransition) {
|
|
4343
|
+
if (waitForTransition === void 0) { waitForTransition = true; }
|
|
4344
|
+
if (!waitForTransition) {
|
|
4345
|
+
execute(callback);
|
|
4346
|
+
return;
|
|
4347
|
+
}
|
|
4348
|
+
var durationPadding = 5;
|
|
4349
|
+
var emulatedDuration = getTransitionDurationFromElement(transitionElement) + durationPadding;
|
|
4350
|
+
var called = false;
|
|
4351
|
+
var handler = function (_a) {
|
|
4352
|
+
var target = _a.target;
|
|
4353
|
+
if (target !== transitionElement) {
|
|
4354
|
+
return;
|
|
4355
|
+
}
|
|
4356
|
+
called = true;
|
|
4357
|
+
transitionElement.removeEventListener('transitionend', handler);
|
|
4358
|
+
execute(callback);
|
|
4359
|
+
};
|
|
4360
|
+
transitionElement.addEventListener('transitionend', handler);
|
|
4361
|
+
setTimeout(function () {
|
|
4362
|
+
if (!called) {
|
|
4363
|
+
triggerTransitionEnd(transitionElement);
|
|
4364
|
+
}
|
|
4365
|
+
}, emulatedDuration);
|
|
4366
|
+
};
|
|
4367
|
+
|
|
4368
|
+
var isRTL = function (element) {
|
|
4369
|
+
if (typeof document !== 'undefined' && document.documentElement.dir === 'rtl') {
|
|
4370
|
+
return true;
|
|
4371
|
+
}
|
|
4372
|
+
if (element) {
|
|
4373
|
+
return element.closest('[dir="rtl"]') !== null;
|
|
4374
|
+
}
|
|
4375
|
+
return false;
|
|
4376
|
+
};
|
|
4377
|
+
|
|
4378
|
+
var getRTLPlacement = function (placement, element) {
|
|
4379
|
+
switch (placement) {
|
|
4380
|
+
case 'right': {
|
|
4381
|
+
return isRTL(element) ? 'left' : 'right';
|
|
4382
|
+
}
|
|
4383
|
+
case 'left': {
|
|
4384
|
+
return isRTL(element) ? 'right' : 'left';
|
|
4385
|
+
}
|
|
4386
|
+
default: {
|
|
4387
|
+
return placement;
|
|
4388
|
+
}
|
|
4389
|
+
}
|
|
4390
|
+
};
|
|
4391
|
+
|
|
4392
|
+
var isInViewport = function (element) {
|
|
4393
|
+
var rect = element.getBoundingClientRect();
|
|
4394
|
+
return (Math.floor(rect.top) >= 0 &&
|
|
4395
|
+
Math.floor(rect.left) >= 0 &&
|
|
4396
|
+
Math.floor(rect.bottom) <= (window.innerHeight || document.documentElement.clientHeight) &&
|
|
4397
|
+
Math.floor(rect.right) <= (window.innerWidth || document.documentElement.clientWidth));
|
|
4398
|
+
};
|
|
4399
|
+
|
|
4400
|
+
var isObjectInArray = function (array, item, ignore) {
|
|
4401
|
+
if (ignore === void 0) { ignore = []; }
|
|
4402
|
+
return array.some(function (_item) {
|
|
4403
|
+
var result = true;
|
|
4404
|
+
for (var key in item) {
|
|
4405
|
+
if (!ignore.includes(key) && item[key] !== _item[key]) {
|
|
4406
|
+
result = false;
|
|
4407
|
+
break;
|
|
4408
|
+
}
|
|
4409
|
+
}
|
|
4410
|
+
return result;
|
|
4411
|
+
});
|
|
4412
|
+
};
|
|
4413
|
+
|
|
4316
4414
|
var usePopper = function () {
|
|
4317
4415
|
var _popper = React$1.useRef();
|
|
4416
|
+
var el = React$1.useRef();
|
|
4318
4417
|
var initPopper = function (reference, popper, options) {
|
|
4319
4418
|
_popper.current = createPopper(reference, popper, options);
|
|
4419
|
+
el.current = popper;
|
|
4320
4420
|
};
|
|
4321
4421
|
var destroyPopper = function () {
|
|
4322
|
-
|
|
4323
|
-
|
|
4422
|
+
var popperInstance = _popper.current;
|
|
4423
|
+
if (popperInstance && el.current) {
|
|
4424
|
+
executeAfterTransition(function () {
|
|
4425
|
+
popperInstance.destroy();
|
|
4426
|
+
}, el.current);
|
|
4324
4427
|
}
|
|
4325
4428
|
_popper.current = undefined;
|
|
4326
4429
|
};
|
|
@@ -4855,52 +4958,6 @@ CCardTitle.propTypes = {
|
|
|
4855
4958
|
};
|
|
4856
4959
|
CCardTitle.displayName = 'CCardTitle';
|
|
4857
4960
|
|
|
4858
|
-
var isRTL = function (element) {
|
|
4859
|
-
if (typeof document !== 'undefined' && document.documentElement.dir === 'rtl') {
|
|
4860
|
-
return true;
|
|
4861
|
-
}
|
|
4862
|
-
if (element) {
|
|
4863
|
-
return element.closest('[dir="rtl"]') !== null;
|
|
4864
|
-
}
|
|
4865
|
-
return false;
|
|
4866
|
-
};
|
|
4867
|
-
|
|
4868
|
-
var getRTLPlacement = function (placement, element) {
|
|
4869
|
-
switch (placement) {
|
|
4870
|
-
case 'right': {
|
|
4871
|
-
return isRTL(element) ? 'left' : 'right';
|
|
4872
|
-
}
|
|
4873
|
-
case 'left': {
|
|
4874
|
-
return isRTL(element) ? 'right' : 'left';
|
|
4875
|
-
}
|
|
4876
|
-
default: {
|
|
4877
|
-
return placement;
|
|
4878
|
-
}
|
|
4879
|
-
}
|
|
4880
|
-
};
|
|
4881
|
-
|
|
4882
|
-
var isInViewport = function (element) {
|
|
4883
|
-
var rect = element.getBoundingClientRect();
|
|
4884
|
-
return (Math.floor(rect.top) >= 0 &&
|
|
4885
|
-
Math.floor(rect.left) >= 0 &&
|
|
4886
|
-
Math.floor(rect.bottom) <= (window.innerHeight || document.documentElement.clientHeight) &&
|
|
4887
|
-
Math.floor(rect.right) <= (window.innerWidth || document.documentElement.clientWidth));
|
|
4888
|
-
};
|
|
4889
|
-
|
|
4890
|
-
var isObjectInArray = function (array, item, ignore) {
|
|
4891
|
-
if (ignore === void 0) { ignore = []; }
|
|
4892
|
-
return array.some(function (_item) {
|
|
4893
|
-
var result = true;
|
|
4894
|
-
for (var key in item) {
|
|
4895
|
-
if (!ignore.includes(key) && item[key] !== _item[key]) {
|
|
4896
|
-
result = false;
|
|
4897
|
-
break;
|
|
4898
|
-
}
|
|
4899
|
-
}
|
|
4900
|
-
return result;
|
|
4901
|
-
});
|
|
4902
|
-
};
|
|
4903
|
-
|
|
4904
4961
|
var CCarouselContext = React$1.createContext({});
|
|
4905
4962
|
var CCarousel = React$1.forwardRef(function (_a, ref) {
|
|
4906
4963
|
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"]);
|
|
@@ -10474,12 +10531,13 @@ CModalDialog.displayName = 'CModalDialog';
|
|
|
10474
10531
|
|
|
10475
10532
|
var CModalContext = React$1.createContext({});
|
|
10476
10533
|
var CModal = React$1.forwardRef(function (_a, ref) {
|
|
10477
|
-
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,
|
|
10534
|
+
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"]);
|
|
10535
|
+
var activeElementRef = React$1.useRef(null);
|
|
10478
10536
|
var modalRef = React$1.useRef(null);
|
|
10479
10537
|
var modalContentRef = React$1.useRef(null);
|
|
10480
10538
|
var forkedRef = useForkedRef(ref, modalRef);
|
|
10481
|
-
var
|
|
10482
|
-
var
|
|
10539
|
+
var _j = React$1.useState(visible), _visible = _j[0], setVisible = _j[1];
|
|
10540
|
+
var _k = React$1.useState(false), staticBackdrop = _k[0], setStaticBackdrop = _k[1];
|
|
10483
10541
|
var contextValues = {
|
|
10484
10542
|
visible: _visible,
|
|
10485
10543
|
setVisible: setVisible,
|
|
@@ -10488,10 +10546,15 @@ var CModal = React$1.forwardRef(function (_a, ref) {
|
|
|
10488
10546
|
setVisible(visible);
|
|
10489
10547
|
}, [visible]);
|
|
10490
10548
|
React$1.useEffect(function () {
|
|
10549
|
+
var _a;
|
|
10491
10550
|
if (_visible) {
|
|
10551
|
+
activeElementRef.current = document.activeElement;
|
|
10492
10552
|
document.addEventListener('mouseup', handleClickOutside);
|
|
10493
10553
|
document.addEventListener('keydown', handleKeyDown);
|
|
10494
10554
|
}
|
|
10555
|
+
else {
|
|
10556
|
+
(_a = activeElementRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
10557
|
+
}
|
|
10495
10558
|
return function () {
|
|
10496
10559
|
document.removeEventListener('mouseup', handleClickOutside);
|
|
10497
10560
|
document.removeEventListener('keydown', handleKeyDown);
|
|
@@ -10518,7 +10581,7 @@ var CModal = React$1.forwardRef(function (_a, ref) {
|
|
|
10518
10581
|
}
|
|
10519
10582
|
setTimeout(function () {
|
|
10520
10583
|
var _a;
|
|
10521
|
-
(_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
10584
|
+
focus && ((_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.focus());
|
|
10522
10585
|
}, transition ? duration : 0);
|
|
10523
10586
|
}
|
|
10524
10587
|
else {
|
|
@@ -10550,13 +10613,15 @@ var CModal = React$1.forwardRef(function (_a, ref) {
|
|
|
10550
10613
|
return (React$1.createElement(React$1.Fragment, null,
|
|
10551
10614
|
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 },
|
|
10552
10615
|
React$1.createElement(CModalContext.Provider, { value: contextValues },
|
|
10553
|
-
React$1.createElement("div", { className: classNames$1('modal', {
|
|
10616
|
+
React$1.createElement("div", __assign$1({ className: classNames$1('modal', {
|
|
10554
10617
|
'modal-static': staticBackdrop,
|
|
10555
10618
|
fade: transition,
|
|
10556
10619
|
show: state === 'entered',
|
|
10557
|
-
}, className), tabIndex: -1
|
|
10620
|
+
}, className), tabIndex: -1 }, (_visible
|
|
10621
|
+
? { 'aria-modal': true, role: 'dialog' }
|
|
10622
|
+
: { 'aria-hidden': 'true' }), { style: __assign$1({}, (state !== 'exited' && { display: 'block' })) }, rest, { ref: forkedRef }),
|
|
10558
10623
|
React$1.createElement(CModalDialog, { alignment: alignment, fullscreen: fullscreen, scrollable: scrollable, size: size },
|
|
10559
|
-
React$1.createElement(CModalContent,
|
|
10624
|
+
React$1.createElement(CModalContent, { ref: modalContentRef }, children)))))); }),
|
|
10560
10625
|
backdrop && (React$1.createElement(CConditionalPortal, { portal: portal },
|
|
10561
10626
|
React$1.createElement(CBackdrop, { visible: _visible })))));
|
|
10562
10627
|
});
|
|
@@ -10566,6 +10631,7 @@ CModal.propTypes = {
|
|
|
10566
10631
|
children: PropTypes$1.node,
|
|
10567
10632
|
className: PropTypes$1.string,
|
|
10568
10633
|
duration: PropTypes$1.number,
|
|
10634
|
+
focus: PropTypes$1.bool,
|
|
10569
10635
|
fullscreen: PropTypes$1.oneOfType([
|
|
10570
10636
|
PropTypes$1.bool,
|
|
10571
10637
|
PropTypes$1.oneOf(['sm', 'md', 'lg', 'xl', 'xxl']),
|
|
@@ -11634,7 +11700,7 @@ var CPopover = function (_a) {
|
|
|
11634
11700
|
typeof window !== 'undefined' &&
|
|
11635
11701
|
ReactDOM.createPortal(React$1.createElement(Transition$1, { in: _visible, mountOnEnter: true, nodeRef: popoverRef, onEnter: onShow, onExit: onHide, timeout: {
|
|
11636
11702
|
enter: 0,
|
|
11637
|
-
exit: 200,
|
|
11703
|
+
exit: popoverRef.current ? getTransitionDurationFromElement(popoverRef.current) + 50 : 200,
|
|
11638
11704
|
}, unmountOnExit: true }, function (state) { return (React$1.createElement("div", __assign$1({ className: classNames$1('popover', 'bs-popover-auto', {
|
|
11639
11705
|
fade: animation,
|
|
11640
11706
|
show: state === 'entered',
|
|
@@ -14338,7 +14404,7 @@ var CTooltip = function (_a) {
|
|
|
14338
14404
|
typeof window !== 'undefined' &&
|
|
14339
14405
|
ReactDOM.createPortal(React$1.createElement(Transition$1, { in: _visible, mountOnEnter: true, onEnter: onShow, onExit: onHide, timeout: {
|
|
14340
14406
|
enter: 0,
|
|
14341
|
-
exit: 200,
|
|
14407
|
+
exit: tooltipRef.current ? getTransitionDurationFromElement(tooltipRef.current) + 50 : 200,
|
|
14342
14408
|
}, unmountOnExit: true }, function (state) { return (React$1.createElement("div", __assign$1({ className: classNames$1('tooltip', 'bs-tooltip-auto', {
|
|
14343
14409
|
fade: animation,
|
|
14344
14410
|
show: state === 'entered',
|