@coreui/react 4.10.1 → 4.11.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
@@ -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.10.1.zip)
49
+ - [Download the latest release](https://github.com/coreui/coreui-react/archive/v4.11.1.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`
@@ -4,9 +4,15 @@ export interface CConditionalPortalProps {
4
4
  * @ignore
5
5
  */
6
6
  children: ReactNode;
7
+ /**
8
+ * An HTML element or function that returns a single element, with `document.body` as the default.
9
+ *
10
+ * @since v4.11.0
11
+ */
12
+ container?: Element | (() => Element | null) | null;
7
13
  /**
8
14
  * Render some children into a different part of the DOM
9
15
  */
10
- portal: boolean;
16
+ portal: boolean | any;
11
17
  }
12
18
  export declare const CConditionalPortal: FC<CConditionalPortalProps>;
@@ -38,6 +38,12 @@ export interface CDropdownProps extends HTMLAttributes<HTMLDivElement | HTMLLIEl
38
38
  * Component used for the root node. Either a string to use a HTML element or a component.
39
39
  */
40
40
  component?: string | ElementType;
41
+ /**
42
+ * Appends the react dropdown menu to a specific element. You can pass an HTML element or function that returns a single element. By default `document.body`.
43
+ *
44
+ * @since v4.11.0
45
+ */
46
+ container?: Element | (() => Element | null) | null;
41
47
  /**
42
48
  * Sets a darker color scheme to match a dark navbar.
43
49
  */
@@ -11,6 +11,12 @@ export interface CPopoverProps extends Omit<HTMLAttributes<HTMLDivElement>, 'tit
11
11
  * A string of all className you want applied to the component.
12
12
  */
13
13
  className?: string;
14
+ /**
15
+ * Appends the react popover to a specific element. You can pass an HTML element or function that returns a single element. By default `document.body`.
16
+ *
17
+ * @since v4.11.0
18
+ */
19
+ container?: Element | (() => Element | null) | null;
14
20
  /**
15
21
  * Content node for your component.
16
22
  */
@@ -11,6 +11,12 @@ export interface CTooltipProps extends Omit<HTMLAttributes<HTMLDivElement>, 'con
11
11
  * A string of all className you want applied to the component.
12
12
  */
13
13
  className?: string;
14
+ /**
15
+ * Appends the react tooltip to a specific element. You can pass an HTML element or function that returns a single element. By default `document.body`.
16
+ *
17
+ * @since v4.11.0
18
+ */
19
+ container?: Element | (() => Element | null) | null;
14
20
  /**
15
21
  * Content node for your component.
16
22
  */
package/dist/index.es.js CHANGED
@@ -5158,13 +5158,24 @@ CCarouselItem.propTypes = {
5158
5158
  };
5159
5159
  CCarouselItem.displayName = 'CCarouselItem';
5160
5160
 
5161
+ var getContainer = function (container) {
5162
+ if (container) {
5163
+ return typeof container === 'function' ? container() : container;
5164
+ }
5165
+ return document.body;
5166
+ };
5161
5167
  var CConditionalPortal = function (_a) {
5162
- var children = _a.children, portal = _a.portal;
5163
- return typeof window !== 'undefined' && portal ? (createPortal(children, document.body)) : (React.createElement(React.Fragment, null, children));
5168
+ var children = _a.children, container = _a.container, portal = _a.portal;
5169
+ var _b = useState(null), _container = _b[0], setContainer = _b[1];
5170
+ useEffect(function () {
5171
+ portal && setContainer(getContainer(container) || document.body);
5172
+ }, [container, portal]);
5173
+ return typeof window !== 'undefined' && portal && _container ? (createPortal(children, _container)) : (React.createElement(React.Fragment, null, children));
5164
5174
  };
5165
5175
  CConditionalPortal.propTypes = {
5166
5176
  children: PropTypes.node,
5167
- portal: PropTypes.bool.isRequired,
5177
+ container: PropTypes.any,
5178
+ portal: PropTypes.bool,
5168
5179
  };
5169
5180
  CConditionalPortal.displayName = 'CConditionalPortal';
5170
5181
 
@@ -5190,7 +5201,7 @@ var getPlacement = function (placement, direction, alignment, isRTL) {
5190
5201
  var CDropdownContext = createContext({});
5191
5202
  var CDropdown = forwardRef(function (_a, ref) {
5192
5203
  var _b;
5193
- var children = _a.children, alignment = _a.alignment, _c = _a.autoClose, autoClose = _c === void 0 ? true : _c, className = _a.className, dark = _a.dark, direction = _a.direction, _d = _a.offset, offset = _d === void 0 ? [0, 2] : _d, onHide = _a.onHide, onShow = _a.onShow, _e = _a.placement, placement = _e === void 0 ? 'bottom-start' : _e, _f = _a.popper, popper = _f === void 0 ? true : _f, _g = _a.portal, portal = _g === void 0 ? false : _g, _h = _a.variant, variant = _h === void 0 ? 'btn-group' : _h, _j = _a.component, component = _j === void 0 ? 'div' : _j, _k = _a.visible, visible = _k === void 0 ? false : _k, rest = __rest(_a, ["children", "alignment", "autoClose", "className", "dark", "direction", "offset", "onHide", "onShow", "placement", "popper", "portal", "variant", "component", "visible"]);
5204
+ var children = _a.children, alignment = _a.alignment, _c = _a.autoClose, autoClose = _c === void 0 ? true : _c, className = _a.className, container = _a.container, dark = _a.dark, direction = _a.direction, _d = _a.offset, offset = _d === void 0 ? [0, 2] : _d, onHide = _a.onHide, onShow = _a.onShow, _e = _a.placement, placement = _e === void 0 ? 'bottom-start' : _e, _f = _a.popper, popper = _f === void 0 ? true : _f, _g = _a.portal, portal = _g === void 0 ? false : _g, _h = _a.variant, variant = _h === void 0 ? 'btn-group' : _h, _j = _a.component, component = _j === void 0 ? 'div' : _j, _k = _a.visible, visible = _k === void 0 ? false : _k, rest = __rest(_a, ["children", "alignment", "autoClose", "className", "container", "dark", "direction", "offset", "onHide", "onShow", "placement", "popper", "portal", "variant", "component", "visible"]);
5194
5205
  var dropdownRef = useRef(null);
5195
5206
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5196
5207
  var dropdownToggleRef = useRef(null);
@@ -5205,6 +5216,7 @@ var CDropdown = forwardRef(function (_a, ref) {
5205
5216
  }
5206
5217
  var contextValues = {
5207
5218
  alignment: alignment,
5219
+ container: container,
5208
5220
  dark: dark,
5209
5221
  dropdownToggleRef: dropdownToggleRef,
5210
5222
  dropdownMenuRef: dropdownMenuRef,
@@ -5359,9 +5371,9 @@ var alignmentClassNames = function (alignment) {
5359
5371
  };
5360
5372
  var CDropdownMenu = forwardRef(function (_a, ref) {
5361
5373
  var children = _a.children, className = _a.className, _b = _a.component, Component = _b === void 0 ? 'ul' : _b, rest = __rest(_a, ["children", "className", "component"]);
5362
- var _c = useContext(CDropdownContext), alignment = _c.alignment, dark = _c.dark, dropdownMenuRef = _c.dropdownMenuRef, popper = _c.popper, portal = _c.portal, visible = _c.visible;
5374
+ var _c = useContext(CDropdownContext), alignment = _c.alignment, container = _c.container, dark = _c.dark, dropdownMenuRef = _c.dropdownMenuRef, popper = _c.popper, portal = _c.portal, visible = _c.visible;
5363
5375
  var forkedRef = useForkedRef(ref, dropdownMenuRef);
5364
- return (React.createElement(CConditionalPortal, { portal: portal !== null && portal !== void 0 ? portal : false },
5376
+ return (React.createElement(CConditionalPortal, { container: container, portal: portal !== null && portal !== void 0 ? portal : false },
5365
5377
  React.createElement(Component, __assign({ className: classNames('dropdown-menu', {
5366
5378
  'dropdown-menu-dark': dark,
5367
5379
  show: visible,
@@ -6095,8 +6107,7 @@ var CModal = forwardRef(function (_a, ref) {
6095
6107
  };
6096
6108
  }, [_visible]);
6097
6109
  var handleClickOutside = function (event) {
6098
- if (modalContentRef.current &&
6099
- !modalContentRef.current.contains(event.target)) {
6110
+ if (modalRef.current && modalRef.current == event.target) {
6100
6111
  handleDismiss();
6101
6112
  }
6102
6113
  };
@@ -6662,10 +6673,11 @@ CProgress.propTypes = {
6662
6673
  CProgress.displayName = 'CProgress';
6663
6674
 
6664
6675
  var CPopover = forwardRef(function (_a, ref) {
6665
- 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"]);
6676
+ var children = _a.children, _b = _a.animation, animation = _b === void 0 ? true : _b, className = _a.className, container = _a.container, 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; _a.onShow; var _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", "container", "content", "delay", "fallbackPlacements", "offset", "onHide", "onShow", "placement", "title", "trigger", "visible"]);
6666
6677
  var popoverRef = useRef(null);
6667
6678
  var togglerRef = useRef(null);
6668
6679
  var forkedRef = useForkedRef(ref, popoverRef);
6680
+ var uID = useRef("popover".concat(Math.floor(Math.random() * 1000000)));
6669
6681
  var _h = usePopper(), initPopper = _h.initPopper, destroyPopper = _h.destroyPopper;
6670
6682
  var _j = useState(visible), _visible = _j[0], setVisible = _j[1];
6671
6683
  var _delay = typeof delay === 'number' ? { show: delay, hide: delay } : delay;
@@ -6695,14 +6707,6 @@ var CPopover = forwardRef(function (_a, ref) {
6695
6707
  useEffect(function () {
6696
6708
  setVisible(visible);
6697
6709
  }, [visible]);
6698
- useEffect(function () {
6699
- if (_visible && togglerRef.current && popoverRef.current) {
6700
- initPopper(togglerRef.current, popoverRef.current, popperConfig);
6701
- }
6702
- return function () {
6703
- destroyPopper();
6704
- };
6705
- }, [_visible]);
6706
6710
  var toggleVisible = function (visible) {
6707
6711
  if (visible) {
6708
6712
  setTimeout(function () { return setVisible(true); }, _delay.show);
@@ -6711,7 +6715,9 @@ var CPopover = forwardRef(function (_a, ref) {
6711
6715
  setTimeout(function () { return setVisible(false); }, _delay.hide);
6712
6716
  };
6713
6717
  return (React.createElement(React.Fragment, null,
6714
- React.cloneElement(children, __assign(__assign(__assign({ ref: togglerRef }, ((trigger === 'click' || trigger.includes('click')) && {
6718
+ React.cloneElement(children, __assign(__assign(__assign(__assign(__assign({}, (_visible && {
6719
+ 'aria-describedby': uID.current,
6720
+ })), { ref: togglerRef }), ((trigger === 'click' || trigger.includes('click')) && {
6715
6721
  onClick: function () { return toggleVisible(!_visible); },
6716
6722
  })), ((trigger === 'focus' || trigger.includes('focus')) && {
6717
6723
  onFocus: function () { return toggleVisible(true); },
@@ -6720,8 +6726,18 @@ var CPopover = forwardRef(function (_a, ref) {
6720
6726
  onMouseEnter: function () { return toggleVisible(true); },
6721
6727
  onMouseLeave: function () { return toggleVisible(false); },
6722
6728
  }))),
6723
- typeof window !== 'undefined' &&
6724
- createPortal(React.createElement(Transition$1, { in: _visible, mountOnEnter: true, nodeRef: popoverRef, onEnter: onShow, onExit: onHide, timeout: {
6729
+ React.createElement(CConditionalPortal, { container: container, portal: true },
6730
+ React.createElement(Transition$1, { in: _visible, mountOnEnter: true, nodeRef: popoverRef, onEnter: function () {
6731
+ if (togglerRef.current && popoverRef.current) {
6732
+ initPopper(togglerRef.current, popoverRef.current, popperConfig);
6733
+ }
6734
+ }, onEntering: function () {
6735
+ if (togglerRef.current && popoverRef.current) {
6736
+ popoverRef.current.style.display = 'initial';
6737
+ }
6738
+ }, onExit: onHide, onExited: function () {
6739
+ destroyPopper();
6740
+ }, timeout: {
6725
6741
  enter: 0,
6726
6742
  exit: popoverRef.current
6727
6743
  ? getTransitionDurationFromElement(popoverRef.current) + 50
@@ -6729,15 +6745,18 @@ var CPopover = forwardRef(function (_a, ref) {
6729
6745
  }, unmountOnExit: true }, function (state) { return (React.createElement("div", __assign({ className: classNames('popover', 'bs-popover-auto', {
6730
6746
  fade: animation,
6731
6747
  show: state === 'entered',
6732
- }, className), ref: forkedRef, role: "tooltip" }, rest),
6748
+ }, className), id: uID.current, ref: forkedRef, role: "tooltip", style: {
6749
+ display: 'none',
6750
+ } }, rest),
6733
6751
  React.createElement("div", { className: "popover-arrow" }),
6734
6752
  React.createElement("div", { className: "popover-header" }, title),
6735
- React.createElement("div", { className: "popover-body" }, content))); }), document.body)));
6753
+ React.createElement("div", { className: "popover-body" }, content))); }))));
6736
6754
  });
6737
6755
  CPopover.propTypes = {
6738
6756
  animation: PropTypes.bool,
6739
6757
  children: PropTypes.node,
6740
6758
  className: PropTypes.string,
6759
+ container: PropTypes.any,
6741
6760
  content: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
6742
6761
  delay: PropTypes.oneOfType([
6743
6762
  PropTypes.number,
@@ -7278,10 +7297,11 @@ CToaster.propTypes = {
7278
7297
  CToaster.displayName = 'CToaster';
7279
7298
 
7280
7299
  var CTooltip = forwardRef(function (_a, ref) {
7281
- 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"]);
7300
+ var children = _a.children, _b = _a.animation, animation = _b === void 0 ? true : _b, className = _a.className, container = _a.container, 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; _a.onShow; var _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", "container", "content", "delay", "fallbackPlacements", "offset", "onHide", "onShow", "placement", "trigger", "visible"]);
7282
7301
  var tooltipRef = useRef(null);
7283
7302
  var togglerRef = useRef(null);
7284
7303
  var forkedRef = useForkedRef(ref, tooltipRef);
7304
+ var uID = useRef("tooltip".concat(Math.floor(Math.random() * 1000000)));
7285
7305
  var _h = usePopper(), initPopper = _h.initPopper, destroyPopper = _h.destroyPopper;
7286
7306
  var _j = useState(visible), _visible = _j[0], setVisible = _j[1];
7287
7307
  var _delay = typeof delay === 'number' ? { show: delay, hide: delay } : delay;
@@ -7311,14 +7331,6 @@ var CTooltip = forwardRef(function (_a, ref) {
7311
7331
  useEffect(function () {
7312
7332
  setVisible(visible);
7313
7333
  }, [visible]);
7314
- useEffect(function () {
7315
- if (_visible && togglerRef.current && tooltipRef.current) {
7316
- initPopper(togglerRef.current, tooltipRef.current, popperConfig);
7317
- }
7318
- return function () {
7319
- destroyPopper();
7320
- };
7321
- }, [_visible]);
7322
7334
  var toggleVisible = function (visible) {
7323
7335
  if (visible) {
7324
7336
  setTimeout(function () { return setVisible(true); }, _delay.show);
@@ -7327,7 +7339,9 @@ var CTooltip = forwardRef(function (_a, ref) {
7327
7339
  setTimeout(function () { return setVisible(false); }, _delay.hide);
7328
7340
  };
7329
7341
  return (React.createElement(React.Fragment, null,
7330
- React.cloneElement(children, __assign(__assign(__assign({ ref: togglerRef }, ((trigger === 'click' || trigger.includes('click')) && {
7342
+ React.cloneElement(children, __assign(__assign(__assign(__assign(__assign({}, (_visible && {
7343
+ 'aria-describedby': uID.current,
7344
+ })), { ref: togglerRef }), ((trigger === 'click' || trigger.includes('click')) && {
7331
7345
  onClick: function () { return toggleVisible(!_visible); },
7332
7346
  })), ((trigger === 'focus' || trigger.includes('focus')) && {
7333
7347
  onFocus: function () { return toggleVisible(true); },
@@ -7336,8 +7350,18 @@ var CTooltip = forwardRef(function (_a, ref) {
7336
7350
  onMouseEnter: function () { return toggleVisible(true); },
7337
7351
  onMouseLeave: function () { return toggleVisible(false); },
7338
7352
  }))),
7339
- typeof window !== 'undefined' &&
7340
- createPortal(React.createElement(Transition$1, { in: _visible, mountOnEnter: true, nodeRef: tooltipRef, onEnter: onShow, onExit: onHide, timeout: {
7353
+ React.createElement(CConditionalPortal, { container: container, portal: true },
7354
+ React.createElement(Transition$1, { in: _visible, mountOnEnter: true, nodeRef: tooltipRef, onEnter: function () {
7355
+ if (togglerRef.current && tooltipRef.current) {
7356
+ initPopper(togglerRef.current, tooltipRef.current, popperConfig);
7357
+ }
7358
+ }, onEntering: function () {
7359
+ if (togglerRef.current && tooltipRef.current) {
7360
+ tooltipRef.current.style.display = 'initial';
7361
+ }
7362
+ }, onExit: onHide, onExited: function () {
7363
+ destroyPopper();
7364
+ }, timeout: {
7341
7365
  enter: 0,
7342
7366
  exit: tooltipRef.current
7343
7367
  ? getTransitionDurationFromElement(tooltipRef.current) + 50
@@ -7345,13 +7369,16 @@ var CTooltip = forwardRef(function (_a, ref) {
7345
7369
  }, unmountOnExit: true }, function (state) { return (React.createElement("div", __assign({ className: classNames('tooltip', 'bs-tooltip-auto', {
7346
7370
  fade: animation,
7347
7371
  show: state === 'entered',
7348
- }, className), ref: forkedRef, role: "tooltip" }, rest),
7372
+ }, className), id: uID.current, ref: forkedRef, role: "tooltip", style: {
7373
+ display: 'none',
7374
+ } }, rest),
7349
7375
  React.createElement("div", { className: "tooltip-arrow" }),
7350
- React.createElement("div", { className: "tooltip-inner" }, content))); }), document.body)));
7376
+ React.createElement("div", { className: "tooltip-inner" }, content))); }))));
7351
7377
  });
7352
7378
  CTooltip.propTypes = {
7353
7379
  animation: PropTypes.bool,
7354
7380
  children: PropTypes.node,
7381
+ container: PropTypes.any,
7355
7382
  content: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
7356
7383
  delay: PropTypes.oneOfType([
7357
7384
  PropTypes.number,