carbon-react 109.0.2 → 109.1.2

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.
Files changed (66) hide show
  1. package/esm/__internal__/focus-trap/focus-trap.component.js +8 -11
  2. package/esm/__internal__/label/label.component.d.ts +1 -1
  3. package/esm/__internal__/label/label.component.js +2 -2
  4. package/esm/components/checkbox/checkbox-group.component.js +0 -5
  5. package/esm/components/checkbox/checkbox-group.d.ts +0 -2
  6. package/esm/components/checkbox/checkbox.component.js +1 -3
  7. package/esm/components/date/date.component.js +4 -7
  8. package/esm/components/flat-table/sort/sort.component.js +2 -1
  9. package/esm/components/flat-table/sort/sort.style.js +0 -1
  10. package/esm/components/help/help.component.d.ts +43 -0
  11. package/esm/components/help/help.component.js +194 -84
  12. package/esm/components/help/help.config.d.ts +1 -0
  13. package/esm/components/help/help.style.d.ts +4 -1
  14. package/esm/components/help/index.d.ts +2 -1
  15. package/esm/components/inline-inputs/inline-inputs.component.d.ts +5 -9
  16. package/esm/components/inline-inputs/inline-inputs.component.js +14 -2
  17. package/esm/components/inline-inputs/inline-inputs.style.d.ts +18 -3
  18. package/esm/components/inline-inputs/inline-inputs.style.js +6 -2
  19. package/esm/components/menu/__internal__/submenu/submenu.component.js +4 -6
  20. package/esm/components/multi-action-button/multi-action-button.component.js +4 -13
  21. package/esm/components/popover-container/popover-container.component.d.ts +1 -1
  22. package/esm/components/popover-container/popover-container.component.js +5 -9
  23. package/esm/components/split-button/split-button.component.js +4 -11
  24. package/esm/hooks/__internal__/useClickAwayListener/index.d.ts +1 -0
  25. package/esm/hooks/__internal__/useClickAwayListener/index.js +1 -0
  26. package/esm/hooks/__internal__/useClickAwayListener/useClickAwayListener.d.ts +3 -0
  27. package/esm/hooks/__internal__/useClickAwayListener/useClickAwayListener.js +23 -0
  28. package/lib/__internal__/focus-trap/focus-trap.component.js +8 -11
  29. package/lib/__internal__/label/label.component.d.ts +1 -1
  30. package/lib/__internal__/label/label.component.js +2 -2
  31. package/lib/components/checkbox/checkbox-group.component.js +0 -5
  32. package/lib/components/checkbox/checkbox-group.d.ts +0 -2
  33. package/lib/components/checkbox/checkbox.component.js +1 -3
  34. package/lib/components/date/date.component.js +4 -7
  35. package/lib/components/flat-table/sort/sort.component.js +2 -1
  36. package/lib/components/flat-table/sort/sort.style.js +0 -1
  37. package/lib/components/help/help.component.d.ts +43 -0
  38. package/lib/components/help/help.component.js +194 -87
  39. package/lib/components/help/help.config.d.ts +1 -0
  40. package/lib/components/help/help.style.d.ts +4 -1
  41. package/lib/components/help/index.d.ts +2 -1
  42. package/lib/components/inline-inputs/inline-inputs.component.d.ts +5 -9
  43. package/lib/components/inline-inputs/inline-inputs.component.js +15 -2
  44. package/lib/components/inline-inputs/inline-inputs.style.d.ts +18 -3
  45. package/lib/components/inline-inputs/inline-inputs.style.js +6 -2
  46. package/lib/components/menu/__internal__/submenu/submenu.component.js +4 -6
  47. package/lib/components/multi-action-button/multi-action-button.component.js +5 -13
  48. package/lib/components/popover-container/popover-container.component.d.ts +1 -1
  49. package/lib/components/popover-container/popover-container.component.js +5 -9
  50. package/lib/components/split-button/split-button.component.js +5 -11
  51. package/lib/hooks/__internal__/useClickAwayListener/index.d.ts +1 -0
  52. package/lib/{__internal__/click-away-wrapper → hooks/__internal__/useClickAwayListener}/index.js +2 -2
  53. package/lib/hooks/__internal__/useClickAwayListener/package.json +6 -0
  54. package/lib/hooks/__internal__/useClickAwayListener/useClickAwayListener.d.ts +3 -0
  55. package/lib/hooks/__internal__/useClickAwayListener/useClickAwayListener.js +33 -0
  56. package/package.json +1 -1
  57. package/esm/__internal__/click-away-wrapper/click-away-wrapper.component.d.ts +0 -12
  58. package/esm/__internal__/click-away-wrapper/click-away-wrapper.component.js +0 -43
  59. package/esm/__internal__/click-away-wrapper/index.d.ts +0 -2
  60. package/esm/__internal__/click-away-wrapper/index.js +0 -1
  61. package/esm/components/help/help.d.ts +0 -41
  62. package/lib/__internal__/click-away-wrapper/click-away-wrapper.component.d.ts +0 -12
  63. package/lib/__internal__/click-away-wrapper/click-away-wrapper.component.js +0 -59
  64. package/lib/__internal__/click-away-wrapper/index.d.ts +0 -2
  65. package/lib/__internal__/click-away-wrapper/package.json +0 -6
  66. package/lib/components/help/help.d.ts +0 -41
@@ -19,7 +19,7 @@ var _guid = _interopRequireDefault(require("../../__internal__/utils/helpers/gui
19
19
 
20
20
  var _utils = require("../../style/utils");
21
21
 
22
- var _clickAwayWrapper = _interopRequireDefault(require("../../__internal__/click-away-wrapper"));
22
+ var _useClickAwayListener = _interopRequireDefault(require("../../hooks/__internal__/useClickAwayListener"));
23
23
 
24
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
25
 
@@ -138,19 +138,15 @@ const PopoverContainer = ({
138
138
  onClick: handleCloseButtonClick,
139
139
  ref: closeButtonRef,
140
140
  "aria-label": closeButtonAriaLabel
141
- }; // TODO: Assign proper type after ClickAwayWrapper has been refactored
142
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
141
+ };
143
142
 
144
143
  const handleClickAway = e => {
145
144
  if (!isControlled) setIsOpenInternal(false);
146
145
  if (onClose) onClose(e);
147
146
  };
148
147
 
149
- return /*#__PURE__*/_react.default.createElement(_clickAwayWrapper.default, {
150
- targets: [ref],
151
- handleClickAway: handleClickAway,
152
- eventTypeId: "mousedown"
153
- }, /*#__PURE__*/_react.default.createElement(_popoverContainer.PopoverContainerWrapperStyle, {
148
+ (0, _useClickAwayListener.default)([ref], handleClickAway, "mousedown");
149
+ return /*#__PURE__*/_react.default.createElement(_popoverContainer.PopoverContainerWrapperStyle, {
154
150
  "data-component": "popover-container",
155
151
  role: "region",
156
152
  "aria-labelledby": popoverContainerId,
@@ -178,7 +174,7 @@ const PopoverContainer = ({
178
174
  }, (0, _utils.filterStyledSystemPaddingProps)(rest)), /*#__PURE__*/_react.default.createElement(_popoverContainer.PopoverContainerHeaderStyle, null, /*#__PURE__*/_react.default.createElement(_popoverContainer.PopoverContainerTitleStyle, {
179
175
  id: popoverContainerId,
180
176
  "data-element": "popover-container-title"
181
- }, title), renderCloseComponent(renderCloseComponentProps)), children))));
177
+ }, title), renderCloseComponent(renderCloseComponentProps)), children)));
182
178
  };
183
179
 
184
180
  exports.PopoverContainer = PopoverContainer;
@@ -13,6 +13,8 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
13
13
 
14
14
  var _propTypes2 = _interopRequireDefault(require("@styled-system/prop-types"));
15
15
 
16
+ var _useClickAwayListener = _interopRequireDefault(require("../../hooks/__internal__/useClickAwayListener"));
17
+
16
18
  var _icon = _interopRequireDefault(require("../icon"));
17
19
 
18
20
  var _button = _interopRequireWildcard(require("../button"));
@@ -80,13 +82,6 @@ const SplitButton = ({
80
82
  if (isToggleButtonFocused.current) return;
81
83
  setShowAdditionalButtons(false);
82
84
  }, []);
83
- const handleClickOutside = (0, _react.useCallback)(({
84
- target
85
- }) => {
86
- if (!splitButtonNode.current.contains(target) && buttonContainer.current && !buttonContainer.current.contains(target)) {
87
- hideButtons();
88
- }
89
- }, [hideButtons]);
90
85
  const handleKeyDown = (0, _react.useCallback)(ev => {
91
86
  const numOfChildren = children.length - 1;
92
87
  const currentIndex = additionalButtons.current.findIndex(node => node.current === document.activeElement);
@@ -119,19 +114,17 @@ const SplitButton = ({
119
114
  const addListeners = (0, _react.useCallback)(() => {
120
115
  /* istanbul ignore else */
121
116
  if (!listening.current) {
122
- document.addEventListener("click", handleClickOutside);
123
117
  document.addEventListener("keydown", handleKeyDown);
124
118
  listening.current = true;
125
119
  }
126
- }, [handleKeyDown, handleClickOutside]);
120
+ }, [handleKeyDown]);
127
121
  const removeListeners = (0, _react.useCallback)(() => {
128
122
  /* istanbul ignore else */
129
123
  if (listening.current) {
130
- document.removeEventListener("click", handleClickOutside);
131
124
  document.removeEventListener("keydown", handleKeyDown);
132
125
  listening.current = false;
133
126
  }
134
- }, [handleKeyDown, handleClickOutside]);
127
+ }, [handleKeyDown]);
135
128
  (0, _react.useEffect)(() => {
136
129
  if (showAdditionalButtons) {
137
130
  addListeners();
@@ -291,6 +284,7 @@ const SplitButton = ({
291
284
  }, childrenWithProps()));
292
285
  }
293
286
 
287
+ (0, _useClickAwayListener.default)([splitButtonNode], hideButtons);
294
288
  return /*#__PURE__*/_react.default.createElement(_splitButton.default, _extends({
295
289
  "aria-haspopup": "true",
296
290
  onMouseLeave: hideButtons,
@@ -0,0 +1 @@
1
+ export { default } from "./useClickAwayListener";
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", {
6
6
  Object.defineProperty(exports, "default", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _clickAwayWrapper.default;
9
+ return _useClickAwayListener.default;
10
10
  }
11
11
  });
12
12
 
13
- var _clickAwayWrapper = _interopRequireDefault(require("./click-away-wrapper.component"));
13
+ var _useClickAwayListener = _interopRequireDefault(require("./useClickAwayListener"));
14
14
 
15
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "../../../../esm/hooks/__internal__/useClickAwayListener/index.js",
4
+ "main": "./index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ declare const _default: (targets: React.RefObject<HTMLElement>[], handleClickAway: (ev: Event) => void, eventTypeId?: "mousedown" | "click") => void;
3
+ export default _default;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ var _default = (targets, handleClickAway, eventTypeId = "click") => {
11
+ const targetsRef = (0, _react.useRef)(targets);
12
+ targetsRef.current = targets;
13
+ (0, _react.useEffect)(() => {
14
+ const fnClickAway = ev => {
15
+ const clickedElements = targetsRef.current.filter(targetRef => {
16
+ var _targetRef$current;
17
+
18
+ return (_targetRef$current = targetRef.current) === null || _targetRef$current === void 0 ? void 0 : _targetRef$current.contains(ev === null || ev === void 0 ? void 0 : ev.target);
19
+ });
20
+
21
+ if (!(clickedElements !== null && clickedElements !== void 0 && clickedElements.length)) {
22
+ handleClickAway(ev);
23
+ }
24
+ };
25
+
26
+ document.addEventListener(eventTypeId, fnClickAway);
27
+ return function cleanup() {
28
+ document.removeEventListener(eventTypeId, fnClickAway);
29
+ };
30
+ }, [handleClickAway, eventTypeId]);
31
+ };
32
+
33
+ exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "109.0.2",
3
+ "version": "109.1.2",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "engineStrict": true,
6
6
  "engines": {
@@ -1,12 +0,0 @@
1
- import React from "react";
2
- export interface ClickAwayWrapperProps {
3
- children: React.ReactNode;
4
- handleClickAway: (ev: CustomEvent) => void;
5
- eventTypeId?: "mousedown" | "click";
6
- targets: React.RefObject<HTMLElement>[];
7
- }
8
- declare const ClickAwayWrapper: {
9
- ({ children, handleClickAway, eventTypeId, targets, }: ClickAwayWrapperProps): JSX.Element;
10
- displayName: string;
11
- };
12
- export default ClickAwayWrapper;
@@ -1,43 +0,0 @@
1
- import React, { useEffect } from "react";
2
- import PropTypes from "prop-types";
3
- import Events from "../utils/helpers/events";
4
-
5
- const ClickAwayWrapper = ({
6
- children,
7
- handleClickAway,
8
- eventTypeId = "click",
9
- targets
10
- }) => {
11
- useEffect(() => {
12
- const fnClickAway = ev => {
13
- const clickedElements = targets.filter(ref => (ref === null || ref === void 0 ? void 0 : ref.current) && Events.composedPath(ev).includes(ref.current));
14
-
15
- if (!clickedElements || !clickedElements.length) {
16
- handleClickAway(ev);
17
- }
18
- };
19
-
20
- document.addEventListener(eventTypeId, fnClickAway);
21
- return function cleanup() {
22
- document.removeEventListener(eventTypeId, fnClickAway);
23
- };
24
- }, [handleClickAway, targets, eventTypeId]);
25
- return /*#__PURE__*/React.createElement(React.Fragment, null, children);
26
- };
27
-
28
- ClickAwayWrapper.propTypes = {
29
- "children": PropTypes.node,
30
- "eventTypeId": PropTypes.oneOf(["click", "mousedown"]),
31
- "handleClickAway": PropTypes.func.isRequired,
32
- "targets": PropTypes.arrayOf(PropTypes.shape({
33
- "current": PropTypes.oneOfType([PropTypes.oneOf([null]), function (props, propName) {
34
- if (props[propName] == null) {
35
- return new Error("Prop '" + propName + "' is required but wasn't specified");
36
- } else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
37
- return new Error("Expected prop '" + propName + "' to be of type Element");
38
- }
39
- }]).isRequired
40
- })).isRequired
41
- };
42
- ClickAwayWrapper.displayName = "ClickAwayWrapper";
43
- export default ClickAwayWrapper;
@@ -1,2 +0,0 @@
1
- export { default } from "./click-away-wrapper.component";
2
- export type { ClickAwayWrapperProps } from "./click-away-wrapper.component";
@@ -1 +0,0 @@
1
- export { default } from "./click-away-wrapper.component";
@@ -1,41 +0,0 @@
1
- import * as React from "react";
2
- import { IconType } from "components/icon/icon-type";
3
- import { MarginProps } from "styled-system";
4
-
5
- export interface HelpProps extends MarginProps {
6
- /** Overrides the default 'as' attribute of the Help component */
7
- as?: string;
8
- /** The message to be displayed within the tooltip */
9
- children?: React.ReactNode;
10
- /** [Legacy] A custom class name for the component. */
11
- className?: string;
12
- /** The unique id of the component (used with aria-describedby for accessibility) */
13
- helpId?: string;
14
- /** A path for the anchor */
15
- href?: string;
16
- /** A boolean received from IconWrapper */
17
- isFocused?: boolean;
18
- /** Overrides the default tabindex of the component */
19
- tabIndex?: number | string;
20
- /** Override background color of the Tooltip, provide any color from palette or any valid css color value. */
21
- tooltipBgColor?: string;
22
- /** Override font color of the Tooltip, provide any color from palette or any valid css color value. */
23
- tooltipFontColor?: string;
24
- /** Overrides the default flip behaviour of the Tooltip,
25
- * must be an array containing some or all of ["top", "bottom", "left", "right"]
26
- * (see https://popper.js.org/docs/v2/modifiers/flip/#fallbackplacements)
27
- */
28
- tooltipFlipOverrides?: ["top" | "bottom" | "left" | "right"];
29
- /** Position of tooltip relative to target */
30
- tooltipPosition?: "top" | "bottom" | "left" | "right";
31
- /** Id passed to the tooltip container, used for accessibility purposes */
32
- tooltipId?: string;
33
- /** Help Icon type */
34
- type?: IconType;
35
- /** Aria label */
36
- ariaLabel?: string;
37
- }
38
-
39
- declare function Help(props: HelpProps): JSX.Element;
40
-
41
- export default Help;
@@ -1,12 +0,0 @@
1
- import React from "react";
2
- export interface ClickAwayWrapperProps {
3
- children: React.ReactNode;
4
- handleClickAway: (ev: CustomEvent) => void;
5
- eventTypeId?: "mousedown" | "click";
6
- targets: React.RefObject<HTMLElement>[];
7
- }
8
- declare const ClickAwayWrapper: {
9
- ({ children, handleClickAway, eventTypeId, targets, }: ClickAwayWrapperProps): JSX.Element;
10
- displayName: string;
11
- };
12
- export default ClickAwayWrapper;
@@ -1,59 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
- var _events = _interopRequireDefault(require("../utils/helpers/events"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
17
-
18
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
-
20
- const ClickAwayWrapper = ({
21
- children,
22
- handleClickAway,
23
- eventTypeId = "click",
24
- targets
25
- }) => {
26
- (0, _react.useEffect)(() => {
27
- const fnClickAway = ev => {
28
- const clickedElements = targets.filter(ref => (ref === null || ref === void 0 ? void 0 : ref.current) && _events.default.composedPath(ev).includes(ref.current));
29
-
30
- if (!clickedElements || !clickedElements.length) {
31
- handleClickAway(ev);
32
- }
33
- };
34
-
35
- document.addEventListener(eventTypeId, fnClickAway);
36
- return function cleanup() {
37
- document.removeEventListener(eventTypeId, fnClickAway);
38
- };
39
- }, [handleClickAway, targets, eventTypeId]);
40
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
41
- };
42
-
43
- ClickAwayWrapper.propTypes = {
44
- "children": _propTypes.default.node,
45
- "eventTypeId": _propTypes.default.oneOf(["click", "mousedown"]),
46
- "handleClickAway": _propTypes.default.func.isRequired,
47
- "targets": _propTypes.default.arrayOf(_propTypes.default.shape({
48
- "current": _propTypes.default.oneOfType([_propTypes.default.oneOf([null]), function (props, propName) {
49
- if (props[propName] == null) {
50
- return new Error("Prop '" + propName + "' is required but wasn't specified");
51
- } else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
52
- return new Error("Expected prop '" + propName + "' to be of type Element");
53
- }
54
- }]).isRequired
55
- })).isRequired
56
- };
57
- ClickAwayWrapper.displayName = "ClickAwayWrapper";
58
- var _default = ClickAwayWrapper;
59
- exports.default = _default;
@@ -1,2 +0,0 @@
1
- export { default } from "./click-away-wrapper.component";
2
- export type { ClickAwayWrapperProps } from "./click-away-wrapper.component";
@@ -1,6 +0,0 @@
1
- {
2
- "sideEffects": false,
3
- "module": "../../../esm/__internal__/click-away-wrapper/index.js",
4
- "main": "./index.js",
5
- "types": "./index.d.ts"
6
- }
@@ -1,41 +0,0 @@
1
- import * as React from "react";
2
- import { IconType } from "components/icon/icon-type";
3
- import { MarginProps } from "styled-system";
4
-
5
- export interface HelpProps extends MarginProps {
6
- /** Overrides the default 'as' attribute of the Help component */
7
- as?: string;
8
- /** The message to be displayed within the tooltip */
9
- children?: React.ReactNode;
10
- /** [Legacy] A custom class name for the component. */
11
- className?: string;
12
- /** The unique id of the component (used with aria-describedby for accessibility) */
13
- helpId?: string;
14
- /** A path for the anchor */
15
- href?: string;
16
- /** A boolean received from IconWrapper */
17
- isFocused?: boolean;
18
- /** Overrides the default tabindex of the component */
19
- tabIndex?: number | string;
20
- /** Override background color of the Tooltip, provide any color from palette or any valid css color value. */
21
- tooltipBgColor?: string;
22
- /** Override font color of the Tooltip, provide any color from palette or any valid css color value. */
23
- tooltipFontColor?: string;
24
- /** Overrides the default flip behaviour of the Tooltip,
25
- * must be an array containing some or all of ["top", "bottom", "left", "right"]
26
- * (see https://popper.js.org/docs/v2/modifiers/flip/#fallbackplacements)
27
- */
28
- tooltipFlipOverrides?: ["top" | "bottom" | "left" | "right"];
29
- /** Position of tooltip relative to target */
30
- tooltipPosition?: "top" | "bottom" | "left" | "right";
31
- /** Id passed to the tooltip container, used for accessibility purposes */
32
- tooltipId?: string;
33
- /** Help Icon type */
34
- type?: IconType;
35
- /** Aria label */
36
- ariaLabel?: string;
37
- }
38
-
39
- declare function Help(props: HelpProps): JSX.Element;
40
-
41
- export default Help;