@coreui/react 4.9.2 → 4.10.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 +109 -43
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +109 -43
- 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 +9 -1
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
|
-
|
|
4321
|
-
|
|
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,
|
|
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
|
|
5979
|
-
var
|
|
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
|
|
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,
|
|
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']),
|
|
@@ -6658,7 +6724,7 @@ var CPopover = function (_a) {
|
|
|
6658
6724
|
typeof window !== 'undefined' &&
|
|
6659
6725
|
ReactDOM.createPortal(React.createElement(Transition$1, { in: _visible, mountOnEnter: true, nodeRef: popoverRef, onEnter: onShow, onExit: onHide, timeout: {
|
|
6660
6726
|
enter: 0,
|
|
6661
|
-
exit: 200,
|
|
6727
|
+
exit: popoverRef.current ? getTransitionDurationFromElement(popoverRef.current) + 50 : 200,
|
|
6662
6728
|
}, unmountOnExit: true }, function (state) { return (React.createElement("div", __assign({ className: classNames('popover', 'bs-popover-auto', {
|
|
6663
6729
|
fade: animation,
|
|
6664
6730
|
show: state === 'entered',
|
|
@@ -7271,7 +7337,7 @@ var CTooltip = function (_a) {
|
|
|
7271
7337
|
typeof window !== 'undefined' &&
|
|
7272
7338
|
ReactDOM.createPortal(React.createElement(Transition$1, { in: _visible, mountOnEnter: true, onEnter: onShow, onExit: onHide, timeout: {
|
|
7273
7339
|
enter: 0,
|
|
7274
|
-
exit: 200,
|
|
7340
|
+
exit: tooltipRef.current ? getTransitionDurationFromElement(tooltipRef.current) + 50 : 200,
|
|
7275
7341
|
}, unmountOnExit: true }, function (state) { return (React.createElement("div", __assign({ className: classNames('tooltip', 'bs-tooltip-auto', {
|
|
7276
7342
|
fade: animation,
|
|
7277
7343
|
show: state === 'entered',
|