carbon-react 109.2.1 → 109.2.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.
@@ -1,9 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  declare const StyledBadgeWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
3
3
  declare const StyledCounter: import("styled-components").StyledComponent<"div", any, {}, never>;
4
- declare const StyledButton: import("styled-components").StyledComponent<{
5
- ({ size, subtext, children, forwardRef, "aria-label": ariaLabel, disabled, destructive, buttonType: buttonTypeProp, iconType, iconPosition, href, m, px, noWrap, target, rel, iconTooltipMessage, iconTooltipPosition, fullWidth, ...rest }: import("../button").ButtonProps): JSX.Element;
6
- displayName: string;
7
- }, any, {}, never>;
4
+ declare const StyledButton: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("../button").ButtonProps & import("react").RefAttributes<HTMLButtonElement>>, any, {}, never>;
8
5
  declare const StyledCrossIcon: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("../icon").IconProps & import("react").RefAttributes<HTMLSpanElement>>, any, {}, never>;
9
6
  export { StyledBadgeWrapper, StyledButton, StyledCrossIcon, StyledCounter };
@@ -58,10 +58,7 @@ export interface ButtonProps extends SpaceProps {
58
58
  /** HTML rel attribute */
59
59
  rel?: string;
60
60
  }
61
- declare const Button: {
62
- ({ size, subtext, children, forwardRef, "aria-label": ariaLabel, disabled, destructive, buttonType: buttonTypeProp, iconType, iconPosition, href, m, px, noWrap, target, rel, iconTooltipMessage, iconTooltipPosition, fullWidth, ...rest }: ButtonProps): JSX.Element;
63
- displayName: string;
64
- };
61
+ declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
65
62
  declare const ButtonWithForwardRef: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
66
63
  export { ButtonWithForwardRef };
67
64
  export default Button;
@@ -7,6 +7,7 @@ import Icon from "../icon";
7
7
  import StyledButton, { StyledButtonSubtext } from "./button.style";
8
8
  import tagComponent from "../../__internal__/utils/helpers/tags/tags";
9
9
  import { TooltipProvider } from "../../__internal__/tooltip-provider";
10
+ import Logger from "../../__internal__/utils/logger";
10
11
 
11
12
  function renderChildren({
12
13
  /* eslint-disable react/prop-types */
@@ -73,8 +74,8 @@ renderChildren.propTypes = {
73
74
  }
74
75
  }
75
76
  };
76
-
77
- const Button = ({
77
+ let deprecatedForwardRefWarnTriggered = false;
78
+ const Button = /*#__PURE__*/React.forwardRef(({
78
79
  size = "medium",
79
80
  subtext = "",
80
81
  children,
@@ -95,13 +96,18 @@ const Button = ({
95
96
  iconTooltipPosition,
96
97
  fullWidth = false,
97
98
  ...rest
98
- }) => {
99
+ }, ref) => {
99
100
  invariant(!!(children || iconType), "Either prop `iconType` must be defined or this node must have children.");
100
101
 
101
102
  if (subtext) {
102
103
  invariant(size === "large", "subtext prop has no effect unless the button is large.");
103
104
  }
104
105
 
106
+ if (!deprecatedForwardRefWarnTriggered && forwardRef) {
107
+ deprecatedForwardRefWarnTriggered = true;
108
+ Logger.deprecate("The `forwardRef` prop in `Button` component is deprecated and will soon be removed. Please use `ref` instead.");
109
+ }
110
+
105
111
  const [internalRef, setInternalRef] = useState();
106
112
  const buttonType = buttonTypeProp;
107
113
  let paddingX;
@@ -129,10 +135,11 @@ const Button = ({
129
135
 
130
136
  const setRefs = useCallback(reference => {
131
137
  setInternalRef(reference);
132
- if (!forwardRef) return;
133
- if (typeof forwardRef === "object") forwardRef.current = reference;
134
- if (typeof forwardRef === "function") forwardRef(reference);
135
- }, [forwardRef]);
138
+ const activeRef = ref || forwardRef;
139
+ if (!activeRef) return;
140
+ if (typeof activeRef === "object") activeRef.current = reference;
141
+ if (typeof activeRef === "function") activeRef(reference);
142
+ }, [ref, forwardRef]);
136
143
  return /*#__PURE__*/React.createElement(StyledButton, _extends({
137
144
  "aria-label": !children && iconType ? ariaLabel || iconType : undefined,
138
145
  as: !disabled && href ? "a" : "button",
@@ -169,8 +176,7 @@ const Button = ({
169
176
  iconTooltipPosition,
170
177
  tooltipTarget: internalRef
171
178
  }));
172
- };
173
-
179
+ });
174
180
  Button.propTypes = {
175
181
  "aria-label": PropTypes.string,
176
182
  "buttonType": PropTypes.oneOf(["darkBackground", "dashed", "primary", "secondary", "tertiary"]),
@@ -507,9 +513,17 @@ Button.propTypes = {
507
513
  "target": PropTypes.string,
508
514
  "type": PropTypes.string
509
515
  };
510
- const ButtonWithForwardRef = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement(Button, _extends({
511
- forwardRef: ref
512
- }, props)));
516
+ let deprecatedButtonForwardRefWarnTriggered = false;
517
+ const ButtonWithForwardRef = /*#__PURE__*/React.forwardRef((props, ref) => {
518
+ if (!deprecatedButtonForwardRefWarnTriggered) {
519
+ deprecatedButtonForwardRefWarnTriggered = true;
520
+ Logger.deprecate("The `ButtonWithForwardRef` component is deprecated and will soon be removed. Please use a basic `Button` component with `ref` instead.");
521
+ }
522
+
523
+ return /*#__PURE__*/React.createElement(Button, _extends({
524
+ ref: ref
525
+ }, props));
526
+ });
513
527
  ButtonWithForwardRef.propTypes = {
514
528
  "aria-label": PropTypes.string,
515
529
  "buttonType": PropTypes.oneOf(["darkBackground", "dashed", "primary", "secondary", "tertiary"]),
@@ -1,5 +1,5 @@
1
1
  import styled, { css } from "styled-components";
2
- import { ButtonWithForwardRef } from "../../button";
2
+ import Button from "../../button";
3
3
  import { StyledButton } from "../picklist-item/picklist-item.style";
4
4
  const StyledGroupWrapper = styled.li`
5
5
  ${({
@@ -25,7 +25,7 @@ const StyledPicklistGroup = styled.li`
25
25
  width: 100%;
26
26
  margin-bottom: 4px;
27
27
  `;
28
- const StyledGroupButton = styled(ButtonWithForwardRef)`
28
+ const StyledGroupButton = styled(Button)`
29
29
  ${({
30
30
  iconType
31
31
  }) => css`
@@ -1,5 +1,5 @@
1
1
  import styled, { css } from "styled-components";
2
- import { ButtonWithForwardRef } from "../../button";
2
+ import Button from "../../button";
3
3
  import Icon from "../../icon";
4
4
  import StyledIcon from "../../icon/icon.style";
5
5
  const StyledPicklistItem = styled.li`
@@ -30,7 +30,7 @@ const StyledPicklistItem = styled.li`
30
30
  }
31
31
  `}
32
32
  `;
33
- const StyledButton = styled(ButtonWithForwardRef)`
33
+ const StyledButton = styled(Button)`
34
34
  ${({
35
35
  iconType
36
36
  }) => css`
@@ -4,7 +4,7 @@ import React, { useCallback, useEffect, useState, useRef, useMemo } from "react"
4
4
  import PropTypes from "prop-types";
5
5
  import useClickAwayListener from "../../hooks/__internal__/useClickAwayListener";
6
6
  import { StyledMultiActionButton, StyledButtonChildrenContainer } from "./multi-action-button.style";
7
- import Button, { ButtonWithForwardRef } from "../button";
7
+ import Button from "../button";
8
8
  import Events from "../../__internal__/utils/helpers/events";
9
9
  import Popover from "../../__internal__/popover";
10
10
  import { filterStyledSystemMarginProps, filterOutStyledSystemSpacingProps } from "../../style/utils";
@@ -67,11 +67,6 @@ const MultiActionButton = ({
67
67
  (_buttonRef$current = buttonRef.current) === null || _buttonRef$current === void 0 ? void 0 : _buttonRef$current.focus();
68
68
  }
69
69
  };
70
-
71
- if (child.type === Button) {
72
- return /*#__PURE__*/React.createElement(ButtonWithForwardRef, _extends({}, child.props, props));
73
- }
74
-
75
70
  return /*#__PURE__*/React.cloneElement(child, props);
76
71
  });
77
72
  };
@@ -6,7 +6,7 @@ import PropTypes from "prop-types";
6
6
  import styledSystemPropTypes from "@styled-system/prop-types";
7
7
  import useClickAwayListener from "../../hooks/__internal__/useClickAwayListener";
8
8
  import Icon from "../icon";
9
- import Button, { ButtonWithForwardRef } from "../button";
9
+ import Button from "../button";
10
10
  import StyledSplitButton from "./split-button.style";
11
11
  import StyledSplitButtonToggle from "./split-button-toggle.style";
12
12
  import StyledSplitButtonChildrenContainer from "./split-button-children.style";
@@ -217,11 +217,6 @@ const SplitButton = ({
217
217
  (_toggleButton$current = toggleButton.current) === null || _toggleButton$current === void 0 ? void 0 : _toggleButton$current.focus();
218
218
  }
219
219
  };
220
-
221
- if (child.type === Button) {
222
- return /*#__PURE__*/React.createElement(ButtonWithForwardRef, _extends({}, child.props, childProps));
223
- }
224
-
225
220
  return /*#__PURE__*/React.cloneElement(child, childProps);
226
221
  });
227
222
  }
@@ -1,9 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  declare const StyledBadgeWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
3
3
  declare const StyledCounter: import("styled-components").StyledComponent<"div", any, {}, never>;
4
- declare const StyledButton: import("styled-components").StyledComponent<{
5
- ({ size, subtext, children, forwardRef, "aria-label": ariaLabel, disabled, destructive, buttonType: buttonTypeProp, iconType, iconPosition, href, m, px, noWrap, target, rel, iconTooltipMessage, iconTooltipPosition, fullWidth, ...rest }: import("../button").ButtonProps): JSX.Element;
6
- displayName: string;
7
- }, any, {}, never>;
4
+ declare const StyledButton: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("../button").ButtonProps & import("react").RefAttributes<HTMLButtonElement>>, any, {}, never>;
8
5
  declare const StyledCrossIcon: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("../icon").IconProps & import("react").RefAttributes<HTMLSpanElement>>, any, {}, never>;
9
6
  export { StyledBadgeWrapper, StyledButton, StyledCrossIcon, StyledCounter };
@@ -58,10 +58,7 @@ export interface ButtonProps extends SpaceProps {
58
58
  /** HTML rel attribute */
59
59
  rel?: string;
60
60
  }
61
- declare const Button: {
62
- ({ size, subtext, children, forwardRef, "aria-label": ariaLabel, disabled, destructive, buttonType: buttonTypeProp, iconType, iconPosition, href, m, px, noWrap, target, rel, iconTooltipMessage, iconTooltipPosition, fullWidth, ...rest }: ButtonProps): JSX.Element;
63
- displayName: string;
64
- };
61
+ declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
65
62
  declare const ButtonWithForwardRef: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
66
63
  export { ButtonWithForwardRef };
67
64
  export default Button;
@@ -19,6 +19,8 @@ var _tags = _interopRequireDefault(require("../../__internal__/utils/helpers/tag
19
19
 
20
20
  var _tooltipProvider = require("../../__internal__/tooltip-provider");
21
21
 
22
+ var _logger = _interopRequireDefault(require("../../__internal__/utils/logger"));
23
+
22
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
25
 
24
26
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
@@ -92,8 +94,9 @@ renderChildren.propTypes = {
92
94
  }
93
95
  }
94
96
  };
97
+ let deprecatedForwardRefWarnTriggered = false;
95
98
 
96
- const Button = ({
99
+ const Button = /*#__PURE__*/_react.default.forwardRef(({
97
100
  size = "medium",
98
101
  subtext = "",
99
102
  children,
@@ -114,13 +117,19 @@ const Button = ({
114
117
  iconTooltipPosition,
115
118
  fullWidth = false,
116
119
  ...rest
117
- }) => {
120
+ }, ref) => {
118
121
  (0, _invariant.default)(!!(children || iconType), "Either prop `iconType` must be defined or this node must have children.");
119
122
 
120
123
  if (subtext) {
121
124
  (0, _invariant.default)(size === "large", "subtext prop has no effect unless the button is large.");
122
125
  }
123
126
 
127
+ if (!deprecatedForwardRefWarnTriggered && forwardRef) {
128
+ deprecatedForwardRefWarnTriggered = true;
129
+
130
+ _logger.default.deprecate("The `forwardRef` prop in `Button` component is deprecated and will soon be removed. Please use `ref` instead.");
131
+ }
132
+
124
133
  const [internalRef, setInternalRef] = (0, _react.useState)();
125
134
  const buttonType = buttonTypeProp;
126
135
  let paddingX;
@@ -148,10 +157,11 @@ const Button = ({
148
157
 
149
158
  const setRefs = (0, _react.useCallback)(reference => {
150
159
  setInternalRef(reference);
151
- if (!forwardRef) return;
152
- if (typeof forwardRef === "object") forwardRef.current = reference;
153
- if (typeof forwardRef === "function") forwardRef(reference);
154
- }, [forwardRef]);
160
+ const activeRef = ref || forwardRef;
161
+ if (!activeRef) return;
162
+ if (typeof activeRef === "object") activeRef.current = reference;
163
+ if (typeof activeRef === "function") activeRef(reference);
164
+ }, [ref, forwardRef]);
155
165
  return /*#__PURE__*/_react.default.createElement(_button.default, _extends({
156
166
  "aria-label": !children && iconType ? ariaLabel || iconType : undefined,
157
167
  as: !disabled && href ? "a" : "button",
@@ -188,7 +198,7 @@ const Button = ({
188
198
  iconTooltipPosition,
189
199
  tooltipTarget: internalRef
190
200
  }));
191
- };
201
+ });
192
202
 
193
203
  Button.propTypes = {
194
204
  "aria-label": _propTypes.default.string,
@@ -526,10 +536,19 @@ Button.propTypes = {
526
536
  "target": _propTypes.default.string,
527
537
  "type": _propTypes.default.string
528
538
  };
539
+ let deprecatedButtonForwardRefWarnTriggered = false;
540
+
541
+ const ButtonWithForwardRef = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
542
+ if (!deprecatedButtonForwardRefWarnTriggered) {
543
+ deprecatedButtonForwardRefWarnTriggered = true;
529
544
 
530
- const ButtonWithForwardRef = /*#__PURE__*/_react.default.forwardRef((props, ref) => /*#__PURE__*/_react.default.createElement(Button, _extends({
531
- forwardRef: ref
532
- }, props)));
545
+ _logger.default.deprecate("The `ButtonWithForwardRef` component is deprecated and will soon be removed. Please use a basic `Button` component with `ref` instead.");
546
+ }
547
+
548
+ return /*#__PURE__*/_react.default.createElement(Button, _extends({
549
+ ref: ref
550
+ }, props));
551
+ });
533
552
 
534
553
  exports.ButtonWithForwardRef = ButtonWithForwardRef;
535
554
  ButtonWithForwardRef.propTypes = {
@@ -7,10 +7,12 @@ exports.StyledGroupButton = exports.StyledPicklistGroup = exports.StyledPicklist
7
7
 
8
8
  var _styledComponents = _interopRequireWildcard(require("styled-components"));
9
9
 
10
- var _button = require("../../button");
10
+ var _button = _interopRequireDefault(require("../../button"));
11
11
 
12
12
  var _picklistItem = require("../picklist-item/picklist-item.style");
13
13
 
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
14
16
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
15
17
 
16
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; }
@@ -42,7 +44,7 @@ const StyledPicklistGroup = _styledComponents.default.li`
42
44
  margin-bottom: 4px;
43
45
  `;
44
46
  exports.StyledPicklistGroup = StyledPicklistGroup;
45
- const StyledGroupButton = (0, _styledComponents.default)(_button.ButtonWithForwardRef)`
47
+ const StyledGroupButton = (0, _styledComponents.default)(_button.default)`
46
48
  ${({
47
49
  iconType
48
50
  }) => (0, _styledComponents.css)`
@@ -7,7 +7,7 @@ exports.StyledLockIcon = exports.StyledButton = exports.StyledPicklistItem = voi
7
7
 
8
8
  var _styledComponents = _interopRequireWildcard(require("styled-components"));
9
9
 
10
- var _button = require("../../button");
10
+ var _button = _interopRequireDefault(require("../../button"));
11
11
 
12
12
  var _icon = _interopRequireDefault(require("../../icon"));
13
13
 
@@ -48,7 +48,7 @@ const StyledPicklistItem = _styledComponents.default.li`
48
48
  `}
49
49
  `;
50
50
  exports.StyledPicklistItem = StyledPicklistItem;
51
- const StyledButton = (0, _styledComponents.default)(_button.ButtonWithForwardRef)`
51
+ const StyledButton = (0, _styledComponents.default)(_button.default)`
52
52
  ${({
53
53
  iconType
54
54
  }) => (0, _styledComponents.css)`
@@ -13,7 +13,7 @@ var _useClickAwayListener = _interopRequireDefault(require("../../hooks/__intern
13
13
 
14
14
  var _multiActionButton = require("./multi-action-button.style");
15
15
 
16
- var _button = _interopRequireWildcard(require("../button"));
16
+ var _button = _interopRequireDefault(require("../button"));
17
17
 
18
18
  var _events = _interopRequireDefault(require("../../__internal__/utils/helpers/events"));
19
19
 
@@ -88,11 +88,6 @@ const MultiActionButton = ({
88
88
  (_buttonRef$current = buttonRef.current) === null || _buttonRef$current === void 0 ? void 0 : _buttonRef$current.focus();
89
89
  }
90
90
  };
91
-
92
- if (child.type === _button.default) {
93
- return /*#__PURE__*/_react.default.createElement(_button.ButtonWithForwardRef, _extends({}, child.props, props));
94
- }
95
-
96
91
  return /*#__PURE__*/_react.default.cloneElement(child, props);
97
92
  });
98
93
  };
@@ -17,7 +17,7 @@ var _useClickAwayListener = _interopRequireDefault(require("../../hooks/__intern
17
17
 
18
18
  var _icon = _interopRequireDefault(require("../icon"));
19
19
 
20
- var _button = _interopRequireWildcard(require("../button"));
20
+ var _button = _interopRequireDefault(require("../button"));
21
21
 
22
22
  var _splitButton = _interopRequireDefault(require("./split-button.style"));
23
23
 
@@ -249,11 +249,6 @@ const SplitButton = ({
249
249
  (_toggleButton$current = toggleButton.current) === null || _toggleButton$current === void 0 ? void 0 : _toggleButton$current.focus();
250
250
  }
251
251
  };
252
-
253
- if (child.type === _button.default) {
254
- return /*#__PURE__*/_react.default.createElement(_button.ButtonWithForwardRef, _extends({}, child.props, childProps));
255
- }
256
-
257
252
  return /*#__PURE__*/_react.default.cloneElement(child, childProps);
258
253
  });
259
254
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "109.2.1",
3
+ "version": "109.2.2",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "engineStrict": true,
6
6
  "engines": {