@coreui/react 4.10.0 → 4.11.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 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.0.zip)
49
+ - [Download the latest release](https://github.com/coreui/coreui-react/archive/v4.11.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`
@@ -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
  */
@@ -1,4 +1,4 @@
1
- import { FC, HTMLAttributes, ReactNode } from 'react';
1
+ import React, { HTMLAttributes, ReactNode } from 'react';
2
2
  import type { Placements, Triggers } from '../../types';
3
3
  export interface CPopoverProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title' | 'content'> {
4
4
  /**
@@ -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
  */
@@ -61,4 +67,4 @@ export interface CPopoverProps extends Omit<HTMLAttributes<HTMLDivElement>, 'tit
61
67
  */
62
68
  visible?: boolean;
63
69
  }
64
- export declare const CPopover: FC<CPopoverProps>;
70
+ export declare const CPopover: React.ForwardRefExoticComponent<CPopoverProps & React.RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,60 @@
1
+ import { FC, HTMLAttributes, ReactNode } from 'react';
2
+ import type { Placements, Triggers } from '../../types';
3
+ export interface CTooltipProps extends Omit<HTMLAttributes<HTMLDivElement>, 'content'> {
4
+ /**
5
+ * Apply a CSS fade transition to the tooltip.
6
+ *
7
+ * @since 4.9.0
8
+ */
9
+ animation?: boolean;
10
+ /**
11
+ * A string of all className you want applied to the component.
12
+ */
13
+ className?: string;
14
+ /**
15
+ * Content node for your component.
16
+ */
17
+ content: ReactNode | string;
18
+ /**
19
+ * The delay for displaying and hiding the tooltip (in milliseconds). When a numerical value is provided, the delay applies to both the hide and show actions. The object structure for specifying the delay is as follows: delay: `{ 'show': 500, 'hide': 100 }`.
20
+ *
21
+ * @since 4.9.0
22
+ */
23
+ delay?: number | {
24
+ show: number;
25
+ hide: number;
26
+ };
27
+ /**
28
+ * Specify the desired order of fallback placements by providing a list of placements as an array. The placements should be prioritized based on preference.
29
+ *
30
+ * @since 4.9.0
31
+ */
32
+ fallbackPlacements?: Placements | Placements[];
33
+ /**
34
+ * Offset of the tooltip relative to its target.
35
+ */
36
+ offset?: [number, number];
37
+ /**
38
+ * Callback fired when the component requests to be hidden.
39
+ */
40
+ onHide?: () => void;
41
+ /**
42
+ * Callback fired when the component requests to be shown.
43
+ */
44
+ onShow?: () => void;
45
+ /**
46
+ * Sets which event handlers you’d like provided to your toggle prop. You can specify one trigger or an array of them.
47
+ *
48
+ * @type 'hover' | 'focus' | 'click'
49
+ */
50
+ trigger?: Triggers | Triggers[];
51
+ /**
52
+ * Describes the placement of your component after Popper.js has applied all the modifiers that may have flipped or altered the originally provided placement property.
53
+ */
54
+ placement?: 'auto' | 'top' | 'right' | 'bottom' | 'left';
55
+ /**
56
+ * Toggle the visibility of tooltip component.
57
+ */
58
+ visible?: boolean;
59
+ }
60
+ export declare const CTooltip: FC<CTooltipProps>;
@@ -1,4 +1,4 @@
1
- import { FC, HTMLAttributes, ReactNode } from 'react';
1
+ import React, { HTMLAttributes, ReactNode } from 'react';
2
2
  import type { Placements, Triggers } from '../../types';
3
3
  export interface CTooltipProps extends Omit<HTMLAttributes<HTMLDivElement>, 'content'> {
4
4
  /**
@@ -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
  */
@@ -57,4 +63,4 @@ export interface CTooltipProps extends Omit<HTMLAttributes<HTMLDivElement>, 'con
57
63
  */
58
64
  visible?: boolean;
59
65
  }
60
- export declare const CTooltip: FC<CTooltipProps>;
66
+ export declare const CTooltip: React.ForwardRefExoticComponent<CTooltipProps & React.RefAttributes<HTMLDivElement>>;
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,
@@ -6661,10 +6673,11 @@ CProgress.propTypes = {
6661
6673
  };
6662
6674
  CProgress.displayName = 'CProgress';
6663
6675
 
6664
- var CPopover = function (_a) {
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 CPopover = forwardRef(function (_a, ref) {
6677
+ 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, 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", "container", "content", "delay", "fallbackPlacements", "offset", "onHide", "onShow", "placement", "title", "trigger", "visible"]);
6666
6678
  var popoverRef = useRef(null);
6667
6679
  var togglerRef = useRef(null);
6680
+ var forkedRef = useForkedRef(ref, popoverRef);
6668
6681
  var _h = usePopper(), initPopper = _h.initPopper, destroyPopper = _h.destroyPopper;
6669
6682
  var _j = useState(visible), _visible = _j[0], setVisible = _j[1];
6670
6683
  var _delay = typeof delay === 'number' ? { show: delay, hide: delay } : delay;
@@ -6719,22 +6732,25 @@ var CPopover = function (_a) {
6719
6732
  onMouseEnter: function () { return toggleVisible(true); },
6720
6733
  onMouseLeave: function () { return toggleVisible(false); },
6721
6734
  }))),
6722
- typeof window !== 'undefined' &&
6723
- createPortal(React.createElement(Transition$1, { in: _visible, mountOnEnter: true, nodeRef: popoverRef, onEnter: onShow, onExit: onHide, timeout: {
6735
+ React.createElement(CConditionalPortal, { container: container, portal: true },
6736
+ React.createElement(Transition$1, { in: _visible, mountOnEnter: true, nodeRef: popoverRef, onEnter: onShow, onExit: onHide, timeout: {
6724
6737
  enter: 0,
6725
- exit: popoverRef.current ? getTransitionDurationFromElement(popoverRef.current) + 50 : 200,
6738
+ exit: popoverRef.current
6739
+ ? getTransitionDurationFromElement(popoverRef.current) + 50
6740
+ : 200,
6726
6741
  }, unmountOnExit: true }, function (state) { return (React.createElement("div", __assign({ className: classNames('popover', 'bs-popover-auto', {
6727
6742
  fade: animation,
6728
6743
  show: state === 'entered',
6729
- }, className), ref: popoverRef, role: "tooltip" }, rest),
6744
+ }, className), ref: forkedRef, role: "tooltip" }, rest),
6730
6745
  React.createElement("div", { className: "popover-arrow" }),
6731
6746
  React.createElement("div", { className: "popover-header" }, title),
6732
- React.createElement("div", { className: "popover-body" }, content))); }), document.body)));
6733
- };
6747
+ React.createElement("div", { className: "popover-body" }, content))); }))));
6748
+ });
6734
6749
  CPopover.propTypes = {
6735
6750
  animation: PropTypes.bool,
6736
6751
  children: PropTypes.node,
6737
6752
  className: PropTypes.string,
6753
+ container: PropTypes.any,
6738
6754
  content: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
6739
6755
  delay: PropTypes.oneOfType([
6740
6756
  PropTypes.number,
@@ -7274,10 +7290,11 @@ CToaster.propTypes = {
7274
7290
  };
7275
7291
  CToaster.displayName = 'CToaster';
7276
7292
 
7277
- var CTooltip = function (_a) {
7278
- 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"]);
7293
+ var CTooltip = forwardRef(function (_a, ref) {
7294
+ 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, 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", "container", "content", "delay", "fallbackPlacements", "offset", "onHide", "onShow", "placement", "trigger", "visible"]);
7279
7295
  var tooltipRef = useRef(null);
7280
7296
  var togglerRef = useRef(null);
7297
+ var forkedRef = useForkedRef(ref, tooltipRef);
7281
7298
  var _h = usePopper(), initPopper = _h.initPopper, destroyPopper = _h.destroyPopper;
7282
7299
  var _j = useState(visible), _visible = _j[0], setVisible = _j[1];
7283
7300
  var _delay = typeof delay === 'number' ? { show: delay, hide: delay } : delay;
@@ -7332,20 +7349,23 @@ var CTooltip = function (_a) {
7332
7349
  onMouseEnter: function () { return toggleVisible(true); },
7333
7350
  onMouseLeave: function () { return toggleVisible(false); },
7334
7351
  }))),
7335
- typeof window !== 'undefined' &&
7336
- createPortal(React.createElement(Transition$1, { in: _visible, mountOnEnter: true, onEnter: onShow, onExit: onHide, timeout: {
7352
+ React.createElement(CConditionalPortal, { container: container, portal: true },
7353
+ React.createElement(Transition$1, { in: _visible, mountOnEnter: true, nodeRef: tooltipRef, onEnter: onShow, onExit: onHide, timeout: {
7337
7354
  enter: 0,
7338
- exit: tooltipRef.current ? getTransitionDurationFromElement(tooltipRef.current) + 50 : 200,
7355
+ exit: tooltipRef.current
7356
+ ? getTransitionDurationFromElement(tooltipRef.current) + 50
7357
+ : 200,
7339
7358
  }, unmountOnExit: true }, function (state) { return (React.createElement("div", __assign({ className: classNames('tooltip', 'bs-tooltip-auto', {
7340
7359
  fade: animation,
7341
7360
  show: state === 'entered',
7342
- }, className), ref: tooltipRef, role: "tooltip" }, rest),
7361
+ }, className), ref: forkedRef, role: "tooltip" }, rest),
7343
7362
  React.createElement("div", { className: "tooltip-arrow" }),
7344
- React.createElement("div", { className: "tooltip-inner" }, content))); }), document.body)));
7345
- };
7363
+ React.createElement("div", { className: "tooltip-inner" }, content))); }))));
7364
+ });
7346
7365
  CTooltip.propTypes = {
7347
7366
  animation: PropTypes.bool,
7348
7367
  children: PropTypes.node,
7368
+ container: PropTypes.any,
7349
7369
  content: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
7350
7370
  delay: PropTypes.oneOfType([
7351
7371
  PropTypes.number,