carbon-react 114.7.0 → 114.7.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/esm/components/button/button.component.js +21 -5
- package/esm/components/button-bar/button-bar.component.d.ts +8 -3
- package/esm/components/button-bar/button-bar.component.js +14 -35
- package/esm/components/icon-button/icon-button.component.js +7 -2
- package/lib/components/button/button.component.js +22 -4
- package/lib/components/button-bar/button-bar.component.d.ts +8 -3
- package/lib/components/button-bar/button-bar.component.js +17 -43
- package/lib/components/icon-button/icon-button.component.js +7 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
|
|
3
|
-
import React, { useCallback, useState } from "react";
|
|
3
|
+
import React, { useCallback, useState, useContext } from "react";
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
5
|
import invariant from "invariant";
|
|
6
6
|
import Icon from "../icon";
|
|
@@ -8,6 +8,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
10
|
import Logger from "../../__internal__/utils/logger";
|
|
11
|
+
import { ButtonBarContext } from "../button-bar/button-bar.component";
|
|
11
12
|
|
|
12
13
|
function renderChildren({
|
|
13
14
|
/* eslint-disable react/prop-types */
|
|
@@ -75,8 +76,9 @@ renderChildren.propTypes = {
|
|
|
75
76
|
}
|
|
76
77
|
};
|
|
77
78
|
let deprecatedForwardRefWarnTriggered = false;
|
|
79
|
+
let deprecatedDashedButtonWarnTriggered = false;
|
|
78
80
|
const Button = /*#__PURE__*/React.forwardRef(({
|
|
79
|
-
size = "medium",
|
|
81
|
+
size: sizeProp = "medium",
|
|
80
82
|
subtext = "",
|
|
81
83
|
children,
|
|
82
84
|
forwardRef,
|
|
@@ -85,7 +87,7 @@ const Button = /*#__PURE__*/React.forwardRef(({
|
|
|
85
87
|
destructive = false,
|
|
86
88
|
buttonType: buttonTypeProp = "secondary",
|
|
87
89
|
iconType,
|
|
88
|
-
iconPosition = "before",
|
|
90
|
+
iconPosition: iconPositionProp = "before",
|
|
89
91
|
href,
|
|
90
92
|
m = 0,
|
|
91
93
|
px,
|
|
@@ -94,9 +96,19 @@ const Button = /*#__PURE__*/React.forwardRef(({
|
|
|
94
96
|
rel,
|
|
95
97
|
iconTooltipMessage,
|
|
96
98
|
iconTooltipPosition,
|
|
97
|
-
fullWidth = false,
|
|
99
|
+
fullWidth: fullWidthProp = false,
|
|
98
100
|
...rest
|
|
99
101
|
}, ref) => {
|
|
102
|
+
const {
|
|
103
|
+
buttonType: buttonTypeContext,
|
|
104
|
+
size: sizeContext,
|
|
105
|
+
iconPosition: iconPositionContext,
|
|
106
|
+
fullWidth: fullWidthContext
|
|
107
|
+
} = useContext(ButtonBarContext);
|
|
108
|
+
const buttonType = buttonTypeContext || buttonTypeProp;
|
|
109
|
+
const size = sizeContext || sizeProp;
|
|
110
|
+
const iconPosition = iconPositionContext || iconPositionProp;
|
|
111
|
+
const fullWidth = fullWidthContext || fullWidthProp;
|
|
100
112
|
!!!(children || iconType) ? process.env.NODE_ENV !== "production" ? invariant(false, "Either prop `iconType` must be defined or this node must have children.") : invariant(false) : void 0;
|
|
101
113
|
|
|
102
114
|
if (subtext) {
|
|
@@ -108,8 +120,12 @@ const Button = /*#__PURE__*/React.forwardRef(({
|
|
|
108
120
|
Logger.deprecate("The `forwardRef` prop in `Button` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
109
121
|
}
|
|
110
122
|
|
|
123
|
+
if (!deprecatedDashedButtonWarnTriggered && buttonType === "dashed") {
|
|
124
|
+
deprecatedDashedButtonWarnTriggered = true;
|
|
125
|
+
Logger.deprecate("The `dashed` variant of the `buttonType` prop for `Button` component is deprecated and will soon be removed.");
|
|
126
|
+
}
|
|
127
|
+
|
|
111
128
|
const [internalRef, setInternalRef] = useState();
|
|
112
|
-
const buttonType = buttonTypeProp;
|
|
113
129
|
let paddingX;
|
|
114
130
|
|
|
115
131
|
const handleLinkKeyDown = event => {
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { SpaceProps } from "styled-system";
|
|
3
|
-
export interface
|
|
4
|
-
/** Button or IconButton Elements, to be rendered inside the component */
|
|
5
|
-
children: React.ReactNode;
|
|
3
|
+
export interface ButtonBarContextProps {
|
|
6
4
|
/** Apply fullWidth style to the button bar */
|
|
7
5
|
fullWidth?: boolean;
|
|
8
6
|
/** Defines an Icon position for buttons: "before" | "after" */
|
|
9
7
|
iconPosition?: "before" | "after";
|
|
10
8
|
/** Assigns a size to the buttons: "small" | "medium" | "large" */
|
|
11
9
|
size?: "small" | "medium" | "large";
|
|
10
|
+
/** Color variants for new business themes: "primary" | "secondary" | "tertiary" | "darkBackground" */
|
|
11
|
+
buttonType?: "primary" | "secondary" | "primary";
|
|
12
|
+
}
|
|
13
|
+
export interface ButtonBarProps extends ButtonBarContextProps, SpaceProps {
|
|
14
|
+
/** Button or IconButton Elements, to be rendered inside the component */
|
|
15
|
+
children: React.ReactNode;
|
|
12
16
|
}
|
|
17
|
+
export declare const ButtonBarContext: React.Context<ButtonBarContextProps>;
|
|
13
18
|
export declare const ButtonBar: {
|
|
14
19
|
({ children, size, iconPosition, fullWidth, ...rest }: ButtonBarProps): JSX.Element;
|
|
15
20
|
displayName: string;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
|
|
3
|
-
import React
|
|
3
|
+
import React from "react";
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
|
-
import invariant from "invariant";
|
|
6
5
|
import StyledButtonBar from "./button-bar.style";
|
|
7
|
-
|
|
8
|
-
import IconButton from "../icon-button";
|
|
6
|
+
export const ButtonBarContext = /*#__PURE__*/React.createContext({});
|
|
9
7
|
|
|
10
8
|
const ButtonBar = ({
|
|
11
9
|
children,
|
|
@@ -13,39 +11,20 @@ const ButtonBar = ({
|
|
|
13
11
|
iconPosition = "before",
|
|
14
12
|
fullWidth = false,
|
|
15
13
|
...rest
|
|
16
|
-
}) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
!hasProperChildren ? process.env.NODE_ENV !== "production" ? invariant(false, "ButtonBar accepts only `Button` or `IconButton` elements.") : invariant(false) : void 0;
|
|
28
|
-
|
|
29
|
-
const getBtnProps = child => {
|
|
30
|
-
var _child$props, _child$props2, _child$props2$childre, _child$props2$childre2;
|
|
31
|
-
|
|
32
|
-
const btnProps = { ...child.props,
|
|
33
|
-
buttonType: "secondary",
|
|
34
|
-
size,
|
|
35
|
-
iconPosition,
|
|
36
|
-
fullWidth,
|
|
37
|
-
"aria-label": child.type === IconButton ? ((_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.ariaLabel) || ((_child$props2 = child.props) === null || _child$props2 === void 0 ? void 0 : (_child$props2$childre = _child$props2.children) === null || _child$props2$childre === void 0 ? void 0 : (_child$props2$childre2 = _child$props2$childre.props) === null || _child$props2$childre2 === void 0 ? void 0 : _child$props2$childre2.type) : ""
|
|
38
|
-
};
|
|
39
|
-
return btnProps;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
return /*#__PURE__*/React.createElement(StyledButtonBar, _extends({}, rest, {
|
|
43
|
-
fullWidth: fullWidth,
|
|
44
|
-
size: size
|
|
45
|
-
}), React.Children.map(children, child => /*#__PURE__*/React.createElement(child.type, getBtnProps(child))));
|
|
46
|
-
};
|
|
14
|
+
}) => /*#__PURE__*/React.createElement(StyledButtonBar, _extends({}, rest, {
|
|
15
|
+
fullWidth: fullWidth,
|
|
16
|
+
size: size
|
|
17
|
+
}), /*#__PURE__*/React.createElement(ButtonBarContext.Provider, {
|
|
18
|
+
value: {
|
|
19
|
+
buttonType: "secondary",
|
|
20
|
+
size,
|
|
21
|
+
iconPosition,
|
|
22
|
+
fullWidth
|
|
23
|
+
}
|
|
24
|
+
}, children));
|
|
47
25
|
|
|
48
26
|
ButtonBar.propTypes = {
|
|
27
|
+
"buttonType": PropTypes.oneOf(["primary", "secondary"]),
|
|
49
28
|
"children": PropTypes.node,
|
|
50
29
|
"fullWidth": PropTypes.bool,
|
|
51
30
|
"iconPosition": PropTypes.oneOf(["after", "before"]),
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
|
|
3
|
-
import React, { useState, useCallback } from "react";
|
|
3
|
+
import React, { useState, useCallback, useContext } from "react";
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
5
|
import Events from "../../__internal__/utils/helpers/events";
|
|
6
6
|
import StyledIconButton from "./icon-button.style";
|
|
7
7
|
import { TooltipProvider } from "../../__internal__/tooltip-provider";
|
|
8
|
+
import { ButtonBarContext } from "../button-bar/button-bar.component";
|
|
8
9
|
const IconButton = /*#__PURE__*/React.forwardRef(({
|
|
9
10
|
"aria-label": ariaLabel,
|
|
10
11
|
onAction,
|
|
@@ -12,7 +13,11 @@ const IconButton = /*#__PURE__*/React.forwardRef(({
|
|
|
12
13
|
disabled,
|
|
13
14
|
...rest
|
|
14
15
|
}, ref) => {
|
|
16
|
+
var _internalRef$querySel;
|
|
17
|
+
|
|
15
18
|
const [internalRef, setInternalRef] = useState();
|
|
19
|
+
const context = useContext(ButtonBarContext);
|
|
20
|
+
const ariaLabelValue = Object.keys(context).length ? ariaLabel || (internalRef === null || internalRef === void 0 ? void 0 : (_internalRef$querySel = internalRef.querySelector("[data-component='icon']")) === null || _internalRef$querySel === void 0 ? void 0 : _internalRef$querySel.getAttribute("type")) || undefined : ariaLabel;
|
|
16
21
|
|
|
17
22
|
const handleKeyDown = e => {
|
|
18
23
|
if (Events.isEnterKey(e) || Events.isSpaceKey(e)) {
|
|
@@ -36,7 +41,7 @@ const IconButton = /*#__PURE__*/React.forwardRef(({
|
|
|
36
41
|
return /*#__PURE__*/React.createElement(StyledIconButton, _extends({
|
|
37
42
|
p: 0
|
|
38
43
|
}, rest, {
|
|
39
|
-
"aria-label":
|
|
44
|
+
"aria-label": ariaLabelValue,
|
|
40
45
|
onKeyDown: handleKeyDown,
|
|
41
46
|
onClick: handleOnClick,
|
|
42
47
|
ref: setRefs,
|
|
@@ -21,6 +21,8 @@ var _tooltipProvider = require("../../__internal__/tooltip-provider");
|
|
|
21
21
|
|
|
22
22
|
var _logger = _interopRequireDefault(require("../../__internal__/utils/logger"));
|
|
23
23
|
|
|
24
|
+
var _buttonBar = require("../button-bar/button-bar.component");
|
|
25
|
+
|
|
24
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
27
|
|
|
26
28
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
@@ -95,9 +97,10 @@ renderChildren.propTypes = {
|
|
|
95
97
|
}
|
|
96
98
|
};
|
|
97
99
|
let deprecatedForwardRefWarnTriggered = false;
|
|
100
|
+
let deprecatedDashedButtonWarnTriggered = false;
|
|
98
101
|
|
|
99
102
|
const Button = /*#__PURE__*/_react.default.forwardRef(({
|
|
100
|
-
size = "medium",
|
|
103
|
+
size: sizeProp = "medium",
|
|
101
104
|
subtext = "",
|
|
102
105
|
children,
|
|
103
106
|
forwardRef,
|
|
@@ -106,7 +109,7 @@ const Button = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
106
109
|
destructive = false,
|
|
107
110
|
buttonType: buttonTypeProp = "secondary",
|
|
108
111
|
iconType,
|
|
109
|
-
iconPosition = "before",
|
|
112
|
+
iconPosition: iconPositionProp = "before",
|
|
110
113
|
href,
|
|
111
114
|
m = 0,
|
|
112
115
|
px,
|
|
@@ -115,9 +118,19 @@ const Button = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
115
118
|
rel,
|
|
116
119
|
iconTooltipMessage,
|
|
117
120
|
iconTooltipPosition,
|
|
118
|
-
fullWidth = false,
|
|
121
|
+
fullWidth: fullWidthProp = false,
|
|
119
122
|
...rest
|
|
120
123
|
}, ref) => {
|
|
124
|
+
const {
|
|
125
|
+
buttonType: buttonTypeContext,
|
|
126
|
+
size: sizeContext,
|
|
127
|
+
iconPosition: iconPositionContext,
|
|
128
|
+
fullWidth: fullWidthContext
|
|
129
|
+
} = (0, _react.useContext)(_buttonBar.ButtonBarContext);
|
|
130
|
+
const buttonType = buttonTypeContext || buttonTypeProp;
|
|
131
|
+
const size = sizeContext || sizeProp;
|
|
132
|
+
const iconPosition = iconPositionContext || iconPositionProp;
|
|
133
|
+
const fullWidth = fullWidthContext || fullWidthProp;
|
|
121
134
|
!!!(children || iconType) ? process.env.NODE_ENV !== "production" ? (0, _invariant.default)(false, "Either prop `iconType` must be defined or this node must have children.") : (0, _invariant.default)(false) : void 0;
|
|
122
135
|
|
|
123
136
|
if (subtext) {
|
|
@@ -130,8 +143,13 @@ const Button = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
130
143
|
_logger.default.deprecate("The `forwardRef` prop in `Button` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
131
144
|
}
|
|
132
145
|
|
|
146
|
+
if (!deprecatedDashedButtonWarnTriggered && buttonType === "dashed") {
|
|
147
|
+
deprecatedDashedButtonWarnTriggered = true;
|
|
148
|
+
|
|
149
|
+
_logger.default.deprecate("The `dashed` variant of the `buttonType` prop for `Button` component is deprecated and will soon be removed.");
|
|
150
|
+
}
|
|
151
|
+
|
|
133
152
|
const [internalRef, setInternalRef] = (0, _react.useState)();
|
|
134
|
-
const buttonType = buttonTypeProp;
|
|
135
153
|
let paddingX;
|
|
136
154
|
|
|
137
155
|
const handleLinkKeyDown = event => {
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { SpaceProps } from "styled-system";
|
|
3
|
-
export interface
|
|
4
|
-
/** Button or IconButton Elements, to be rendered inside the component */
|
|
5
|
-
children: React.ReactNode;
|
|
3
|
+
export interface ButtonBarContextProps {
|
|
6
4
|
/** Apply fullWidth style to the button bar */
|
|
7
5
|
fullWidth?: boolean;
|
|
8
6
|
/** Defines an Icon position for buttons: "before" | "after" */
|
|
9
7
|
iconPosition?: "before" | "after";
|
|
10
8
|
/** Assigns a size to the buttons: "small" | "medium" | "large" */
|
|
11
9
|
size?: "small" | "medium" | "large";
|
|
10
|
+
/** Color variants for new business themes: "primary" | "secondary" | "tertiary" | "darkBackground" */
|
|
11
|
+
buttonType?: "primary" | "secondary" | "primary";
|
|
12
|
+
}
|
|
13
|
+
export interface ButtonBarProps extends ButtonBarContextProps, SpaceProps {
|
|
14
|
+
/** Button or IconButton Elements, to be rendered inside the component */
|
|
15
|
+
children: React.ReactNode;
|
|
12
16
|
}
|
|
17
|
+
export declare const ButtonBarContext: React.Context<ButtonBarContextProps>;
|
|
13
18
|
export declare const ButtonBar: {
|
|
14
19
|
({ children, size, iconPosition, fullWidth, ...rest }: ButtonBarProps): JSX.Element;
|
|
15
20
|
displayName: string;
|
|
@@ -3,27 +3,21 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.ButtonBar = void 0;
|
|
6
|
+
exports.default = exports.ButtonBar = exports.ButtonBarContext = void 0;
|
|
7
7
|
|
|
8
|
-
var _react =
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
12
|
-
var _invariant = _interopRequireDefault(require("invariant"));
|
|
13
|
-
|
|
14
12
|
var _buttonBar = _interopRequireDefault(require("./button-bar.style"));
|
|
15
13
|
|
|
16
|
-
var _button = _interopRequireDefault(require("../button"));
|
|
17
|
-
|
|
18
|
-
var _iconButton = _interopRequireDefault(require("../icon-button"));
|
|
19
|
-
|
|
20
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
15
|
|
|
22
|
-
function
|
|
16
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
23
17
|
|
|
24
|
-
|
|
18
|
+
const ButtonBarContext = /*#__PURE__*/_react.default.createContext({});
|
|
25
19
|
|
|
26
|
-
|
|
20
|
+
exports.ButtonBarContext = ButtonBarContext;
|
|
27
21
|
|
|
28
22
|
const ButtonBar = ({
|
|
29
23
|
children,
|
|
@@ -31,41 +25,21 @@ const ButtonBar = ({
|
|
|
31
25
|
iconPosition = "before",
|
|
32
26
|
fullWidth = false,
|
|
33
27
|
...rest
|
|
34
|
-
}) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}, [children]);
|
|
46
|
-
!hasProperChildren ? process.env.NODE_ENV !== "production" ? (0, _invariant.default)(false, "ButtonBar accepts only `Button` or `IconButton` elements.") : (0, _invariant.default)(false) : void 0;
|
|
47
|
-
|
|
48
|
-
const getBtnProps = child => {
|
|
49
|
-
var _child$props, _child$props2, _child$props2$childre, _child$props2$childre2;
|
|
50
|
-
|
|
51
|
-
const btnProps = { ...child.props,
|
|
52
|
-
buttonType: "secondary",
|
|
53
|
-
size,
|
|
54
|
-
iconPosition,
|
|
55
|
-
fullWidth,
|
|
56
|
-
"aria-label": child.type === _iconButton.default ? ((_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.ariaLabel) || ((_child$props2 = child.props) === null || _child$props2 === void 0 ? void 0 : (_child$props2$childre = _child$props2.children) === null || _child$props2$childre === void 0 ? void 0 : (_child$props2$childre2 = _child$props2$childre.props) === null || _child$props2$childre2 === void 0 ? void 0 : _child$props2$childre2.type) : ""
|
|
57
|
-
};
|
|
58
|
-
return btnProps;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
return /*#__PURE__*/_react.default.createElement(_buttonBar.default, _extends({}, rest, {
|
|
62
|
-
fullWidth: fullWidth,
|
|
63
|
-
size: size
|
|
64
|
-
}), _react.default.Children.map(children, child => /*#__PURE__*/_react.default.createElement(child.type, getBtnProps(child))));
|
|
65
|
-
};
|
|
28
|
+
}) => /*#__PURE__*/_react.default.createElement(_buttonBar.default, _extends({}, rest, {
|
|
29
|
+
fullWidth: fullWidth,
|
|
30
|
+
size: size
|
|
31
|
+
}), /*#__PURE__*/_react.default.createElement(ButtonBarContext.Provider, {
|
|
32
|
+
value: {
|
|
33
|
+
buttonType: "secondary",
|
|
34
|
+
size,
|
|
35
|
+
iconPosition,
|
|
36
|
+
fullWidth
|
|
37
|
+
}
|
|
38
|
+
}, children));
|
|
66
39
|
|
|
67
40
|
exports.ButtonBar = ButtonBar;
|
|
68
41
|
ButtonBar.propTypes = {
|
|
42
|
+
"buttonType": _propTypes.default.oneOf(["primary", "secondary"]),
|
|
69
43
|
"children": _propTypes.default.node,
|
|
70
44
|
"fullWidth": _propTypes.default.bool,
|
|
71
45
|
"iconPosition": _propTypes.default.oneOf(["after", "before"]),
|
|
@@ -15,6 +15,8 @@ var _iconButton = _interopRequireDefault(require("./icon-button.style"));
|
|
|
15
15
|
|
|
16
16
|
var _tooltipProvider = require("../../__internal__/tooltip-provider");
|
|
17
17
|
|
|
18
|
+
var _buttonBar = require("../button-bar/button-bar.component");
|
|
19
|
+
|
|
18
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
21
|
|
|
20
22
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
@@ -30,7 +32,11 @@ const IconButton = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
30
32
|
disabled,
|
|
31
33
|
...rest
|
|
32
34
|
}, ref) => {
|
|
35
|
+
var _internalRef$querySel;
|
|
36
|
+
|
|
33
37
|
const [internalRef, setInternalRef] = (0, _react.useState)();
|
|
38
|
+
const context = (0, _react.useContext)(_buttonBar.ButtonBarContext);
|
|
39
|
+
const ariaLabelValue = Object.keys(context).length ? ariaLabel || (internalRef === null || internalRef === void 0 ? void 0 : (_internalRef$querySel = internalRef.querySelector("[data-component='icon']")) === null || _internalRef$querySel === void 0 ? void 0 : _internalRef$querySel.getAttribute("type")) || undefined : ariaLabel;
|
|
34
40
|
|
|
35
41
|
const handleKeyDown = e => {
|
|
36
42
|
if (_events.default.isEnterKey(e) || _events.default.isSpaceKey(e)) {
|
|
@@ -54,7 +60,7 @@ const IconButton = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
54
60
|
return /*#__PURE__*/_react.default.createElement(_iconButton.default, _extends({
|
|
55
61
|
p: 0
|
|
56
62
|
}, rest, {
|
|
57
|
-
"aria-label":
|
|
63
|
+
"aria-label": ariaLabelValue,
|
|
58
64
|
onKeyDown: handleKeyDown,
|
|
59
65
|
onClick: handleOnClick,
|
|
60
66
|
ref: setRefs,
|