@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/README.md
CHANGED
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
|
|
47
47
|
Several quick start options are available:
|
|
48
48
|
|
|
49
|
-
- [Download the latest release](https://github.com/coreui/coreui-react/archive/v4.
|
|
49
|
+
- [Download the latest release](https://github.com/coreui/coreui-react/archive/v4.10.0.zip)
|
|
50
50
|
- Clone the repo: `git clone https://github.com/coreui/coreui-react.git`
|
|
51
51
|
- Install with [npm](https://www.npmjs.com/): `npm install @coreui/react`
|
|
52
52
|
- 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
|
@@ -4309,14 +4309,103 @@ var createPopper = /*#__PURE__*/popperGenerator({
|
|
|
4309
4309
|
defaultModifiers: defaultModifiers
|
|
4310
4310
|
}); // eslint-disable-next-line import/no-unused-modules
|
|
4311
4311
|
|
|
4312
|
+
var getTransitionDurationFromElement = function (element) {
|
|
4313
|
+
if (!element) {
|
|
4314
|
+
return 0;
|
|
4315
|
+
}
|
|
4316
|
+
// Get transition-duration of the element
|
|
4317
|
+
var _a = window.getComputedStyle(element), transitionDuration = _a.transitionDuration, transitionDelay = _a.transitionDelay;
|
|
4318
|
+
var floatTransitionDuration = Number.parseFloat(transitionDuration);
|
|
4319
|
+
var floatTransitionDelay = Number.parseFloat(transitionDelay);
|
|
4320
|
+
// Return 0 if element or transition duration is not found
|
|
4321
|
+
if (!floatTransitionDuration && !floatTransitionDelay) {
|
|
4322
|
+
return 0;
|
|
4323
|
+
}
|
|
4324
|
+
// If multiple durations are defined, take the first
|
|
4325
|
+
transitionDuration = transitionDuration.split(',')[0];
|
|
4326
|
+
transitionDelay = transitionDelay.split(',')[0];
|
|
4327
|
+
return (Number.parseFloat(transitionDuration) + Number.parseFloat(transitionDelay)) * 1000;
|
|
4328
|
+
};
|
|
4329
|
+
|
|
4330
|
+
var execute = function (callback) {
|
|
4331
|
+
if (typeof callback === 'function') {
|
|
4332
|
+
callback();
|
|
4333
|
+
}
|
|
4334
|
+
};
|
|
4335
|
+
var triggerTransitionEnd = function (element) {
|
|
4336
|
+
element.dispatchEvent(new Event('transitionend'));
|
|
4337
|
+
};
|
|
4338
|
+
var executeAfterTransition = function (callback, transitionElement, waitForTransition) {
|
|
4339
|
+
if (waitForTransition === void 0) { waitForTransition = true; }
|
|
4340
|
+
if (!waitForTransition) {
|
|
4341
|
+
execute(callback);
|
|
4342
|
+
return;
|
|
4343
|
+
}
|
|
4344
|
+
var durationPadding = 5;
|
|
4345
|
+
var emulatedDuration = getTransitionDurationFromElement(transitionElement) + durationPadding;
|
|
4346
|
+
var called = false;
|
|
4347
|
+
var handler = function (_a) {
|
|
4348
|
+
var target = _a.target;
|
|
4349
|
+
if (target !== transitionElement) {
|
|
4350
|
+
return;
|
|
4351
|
+
}
|
|
4352
|
+
called = true;
|
|
4353
|
+
transitionElement.removeEventListener('transitionend', handler);
|
|
4354
|
+
execute(callback);
|
|
4355
|
+
};
|
|
4356
|
+
transitionElement.addEventListener('transitionend', handler);
|
|
4357
|
+
setTimeout(function () {
|
|
4358
|
+
if (!called) {
|
|
4359
|
+
triggerTransitionEnd(transitionElement);
|
|
4360
|
+
}
|
|
4361
|
+
}, emulatedDuration);
|
|
4362
|
+
};
|
|
4363
|
+
|
|
4364
|
+
var isRTL = function (element) {
|
|
4365
|
+
if (typeof document !== 'undefined' && document.documentElement.dir === 'rtl') {
|
|
4366
|
+
return true;
|
|
4367
|
+
}
|
|
4368
|
+
if (element) {
|
|
4369
|
+
return element.closest('[dir="rtl"]') !== null;
|
|
4370
|
+
}
|
|
4371
|
+
return false;
|
|
4372
|
+
};
|
|
4373
|
+
|
|
4374
|
+
var getRTLPlacement = function (placement, element) {
|
|
4375
|
+
switch (placement) {
|
|
4376
|
+
case 'right': {
|
|
4377
|
+
return isRTL(element) ? 'left' : 'right';
|
|
4378
|
+
}
|
|
4379
|
+
case 'left': {
|
|
4380
|
+
return isRTL(element) ? 'right' : 'left';
|
|
4381
|
+
}
|
|
4382
|
+
default: {
|
|
4383
|
+
return placement;
|
|
4384
|
+
}
|
|
4385
|
+
}
|
|
4386
|
+
};
|
|
4387
|
+
|
|
4388
|
+
var isInViewport = function (element) {
|
|
4389
|
+
var rect = element.getBoundingClientRect();
|
|
4390
|
+
return (Math.floor(rect.top) >= 0 &&
|
|
4391
|
+
Math.floor(rect.left) >= 0 &&
|
|
4392
|
+
Math.floor(rect.bottom) <= (window.innerHeight || document.documentElement.clientHeight) &&
|
|
4393
|
+
Math.floor(rect.right) <= (window.innerWidth || document.documentElement.clientWidth));
|
|
4394
|
+
};
|
|
4395
|
+
|
|
4312
4396
|
var usePopper = function () {
|
|
4313
4397
|
var _popper = useRef();
|
|
4398
|
+
var el = useRef();
|
|
4314
4399
|
var initPopper = function (reference, popper, options) {
|
|
4315
4400
|
_popper.current = createPopper(reference, popper, options);
|
|
4401
|
+
el.current = popper;
|
|
4316
4402
|
};
|
|
4317
4403
|
var destroyPopper = function () {
|
|
4318
|
-
|
|
4319
|
-
|
|
4404
|
+
var popperInstance = _popper.current;
|
|
4405
|
+
if (popperInstance && el.current) {
|
|
4406
|
+
executeAfterTransition(function () {
|
|
4407
|
+
popperInstance.destroy();
|
|
4408
|
+
}, el.current);
|
|
4320
4409
|
}
|
|
4321
4410
|
_popper.current = undefined;
|
|
4322
4411
|
};
|
|
@@ -4832,38 +4921,6 @@ CCardTitle.propTypes = {
|
|
|
4832
4921
|
};
|
|
4833
4922
|
CCardTitle.displayName = 'CCardTitle';
|
|
4834
4923
|
|
|
4835
|
-
var isRTL = function (element) {
|
|
4836
|
-
if (typeof document !== 'undefined' && document.documentElement.dir === 'rtl') {
|
|
4837
|
-
return true;
|
|
4838
|
-
}
|
|
4839
|
-
if (element) {
|
|
4840
|
-
return element.closest('[dir="rtl"]') !== null;
|
|
4841
|
-
}
|
|
4842
|
-
return false;
|
|
4843
|
-
};
|
|
4844
|
-
|
|
4845
|
-
var getRTLPlacement = function (placement, element) {
|
|
4846
|
-
switch (placement) {
|
|
4847
|
-
case 'right': {
|
|
4848
|
-
return isRTL(element) ? 'left' : 'right';
|
|
4849
|
-
}
|
|
4850
|
-
case 'left': {
|
|
4851
|
-
return isRTL(element) ? 'right' : 'left';
|
|
4852
|
-
}
|
|
4853
|
-
default: {
|
|
4854
|
-
return placement;
|
|
4855
|
-
}
|
|
4856
|
-
}
|
|
4857
|
-
};
|
|
4858
|
-
|
|
4859
|
-
var isInViewport = function (element) {
|
|
4860
|
-
var rect = element.getBoundingClientRect();
|
|
4861
|
-
return (Math.floor(rect.top) >= 0 &&
|
|
4862
|
-
Math.floor(rect.left) >= 0 &&
|
|
4863
|
-
Math.floor(rect.bottom) <= (window.innerHeight || document.documentElement.clientHeight) &&
|
|
4864
|
-
Math.floor(rect.right) <= (window.innerWidth || document.documentElement.clientWidth));
|
|
4865
|
-
};
|
|
4866
|
-
|
|
4867
4924
|
var CCarouselContext = createContext({});
|
|
4868
4925
|
var CCarousel = forwardRef(function (_a, ref) {
|
|
4869
4926
|
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"]);
|
|
@@ -5969,12 +6026,13 @@ CModalDialog.displayName = 'CModalDialog';
|
|
|
5969
6026
|
|
|
5970
6027
|
var CModalContext = createContext({});
|
|
5971
6028
|
var CModal = forwardRef(function (_a, ref) {
|
|
5972
|
-
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,
|
|
6029
|
+
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"]);
|
|
6030
|
+
var activeElementRef = useRef(null);
|
|
5973
6031
|
var modalRef = useRef(null);
|
|
5974
6032
|
var modalContentRef = useRef(null);
|
|
5975
6033
|
var forkedRef = useForkedRef(ref, modalRef);
|
|
5976
|
-
var
|
|
5977
|
-
var
|
|
6034
|
+
var _j = useState(visible), _visible = _j[0], setVisible = _j[1];
|
|
6035
|
+
var _k = useState(false), staticBackdrop = _k[0], setStaticBackdrop = _k[1];
|
|
5978
6036
|
var contextValues = {
|
|
5979
6037
|
visible: _visible,
|
|
5980
6038
|
setVisible: setVisible,
|
|
@@ -5983,10 +6041,15 @@ var CModal = forwardRef(function (_a, ref) {
|
|
|
5983
6041
|
setVisible(visible);
|
|
5984
6042
|
}, [visible]);
|
|
5985
6043
|
useEffect(function () {
|
|
6044
|
+
var _a;
|
|
5986
6045
|
if (_visible) {
|
|
6046
|
+
activeElementRef.current = document.activeElement;
|
|
5987
6047
|
document.addEventListener('mouseup', handleClickOutside);
|
|
5988
6048
|
document.addEventListener('keydown', handleKeyDown);
|
|
5989
6049
|
}
|
|
6050
|
+
else {
|
|
6051
|
+
(_a = activeElementRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
6052
|
+
}
|
|
5990
6053
|
return function () {
|
|
5991
6054
|
document.removeEventListener('mouseup', handleClickOutside);
|
|
5992
6055
|
document.removeEventListener('keydown', handleKeyDown);
|
|
@@ -6013,7 +6076,7 @@ var CModal = forwardRef(function (_a, ref) {
|
|
|
6013
6076
|
}
|
|
6014
6077
|
setTimeout(function () {
|
|
6015
6078
|
var _a;
|
|
6016
|
-
(_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
6079
|
+
focus && ((_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.focus());
|
|
6017
6080
|
}, transition ? duration : 0);
|
|
6018
6081
|
}
|
|
6019
6082
|
else {
|
|
@@ -6045,13 +6108,15 @@ var CModal = forwardRef(function (_a, ref) {
|
|
|
6045
6108
|
return (React.createElement(React.Fragment, null,
|
|
6046
6109
|
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 },
|
|
6047
6110
|
React.createElement(CModalContext.Provider, { value: contextValues },
|
|
6048
|
-
React.createElement("div", { className: classNames('modal', {
|
|
6111
|
+
React.createElement("div", __assign({ className: classNames('modal', {
|
|
6049
6112
|
'modal-static': staticBackdrop,
|
|
6050
6113
|
fade: transition,
|
|
6051
6114
|
show: state === 'entered',
|
|
6052
|
-
}, className), tabIndex: -1
|
|
6115
|
+
}, className), tabIndex: -1 }, (_visible
|
|
6116
|
+
? { 'aria-modal': true, role: 'dialog' }
|
|
6117
|
+
: { 'aria-hidden': 'true' }), { style: __assign({}, (state !== 'exited' && { display: 'block' })) }, rest, { ref: forkedRef }),
|
|
6053
6118
|
React.createElement(CModalDialog, { alignment: alignment, fullscreen: fullscreen, scrollable: scrollable, size: size },
|
|
6054
|
-
React.createElement(CModalContent,
|
|
6119
|
+
React.createElement(CModalContent, { ref: modalContentRef }, children)))))); }),
|
|
6055
6120
|
backdrop && (React.createElement(CConditionalPortal, { portal: portal },
|
|
6056
6121
|
React.createElement(CBackdrop, { visible: _visible })))));
|
|
6057
6122
|
});
|
|
@@ -6061,6 +6126,7 @@ CModal.propTypes = {
|
|
|
6061
6126
|
children: PropTypes.node,
|
|
6062
6127
|
className: PropTypes.string,
|
|
6063
6128
|
duration: PropTypes.number,
|
|
6129
|
+
focus: PropTypes.bool,
|
|
6064
6130
|
fullscreen: PropTypes.oneOfType([
|
|
6065
6131
|
PropTypes.bool,
|
|
6066
6132
|
PropTypes.oneOf(['sm', 'md', 'lg', 'xl', 'xxl']),
|
|
@@ -6656,7 +6722,7 @@ var CPopover = function (_a) {
|
|
|
6656
6722
|
typeof window !== 'undefined' &&
|
|
6657
6723
|
createPortal(React.createElement(Transition$1, { in: _visible, mountOnEnter: true, nodeRef: popoverRef, onEnter: onShow, onExit: onHide, timeout: {
|
|
6658
6724
|
enter: 0,
|
|
6659
|
-
exit: 200,
|
|
6725
|
+
exit: popoverRef.current ? getTransitionDurationFromElement(popoverRef.current) + 50 : 200,
|
|
6660
6726
|
}, unmountOnExit: true }, function (state) { return (React.createElement("div", __assign({ className: classNames('popover', 'bs-popover-auto', {
|
|
6661
6727
|
fade: animation,
|
|
6662
6728
|
show: state === 'entered',
|
|
@@ -7269,7 +7335,7 @@ var CTooltip = function (_a) {
|
|
|
7269
7335
|
typeof window !== 'undefined' &&
|
|
7270
7336
|
createPortal(React.createElement(Transition$1, { in: _visible, mountOnEnter: true, onEnter: onShow, onExit: onHide, timeout: {
|
|
7271
7337
|
enter: 0,
|
|
7272
|
-
exit: 200,
|
|
7338
|
+
exit: tooltipRef.current ? getTransitionDurationFromElement(tooltipRef.current) + 50 : 200,
|
|
7273
7339
|
}, unmountOnExit: true }, function (state) { return (React.createElement("div", __assign({ className: classNames('tooltip', 'bs-tooltip-auto', {
|
|
7274
7340
|
fade: animation,
|
|
7275
7341
|
show: state === 'entered',
|