carbon-react 104.1.1 → 104.2.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/lib/__internal__/tooltip-provider/index.d.ts +1 -0
- package/lib/__internal__/tooltip-provider/index.js +6 -3
- package/lib/components/button/button.component.d.ts +21 -1
- package/lib/components/button/button.component.js +63 -52
- package/lib/components/icon/icon.component.js +4 -2
- package/lib/components/icon-button/icon-button.component.js +11 -19
- package/lib/components/tooltip/tooltip.component.js +4 -0
- package/lib/components/tooltip/tooltip.d.ts +1 -0
- package/package.json +1 -1
|
@@ -21,14 +21,16 @@ const TooltipProvider = ({
|
|
|
21
21
|
helpAriaLabel,
|
|
22
22
|
focusable = true,
|
|
23
23
|
tooltipVisible,
|
|
24
|
-
disabled = false
|
|
24
|
+
disabled = false,
|
|
25
|
+
target
|
|
25
26
|
}) => /*#__PURE__*/_react.default.createElement(TooltipContext.Provider, {
|
|
26
27
|
value: {
|
|
27
28
|
tooltipPosition,
|
|
28
29
|
helpAriaLabel,
|
|
29
30
|
focusable,
|
|
30
31
|
tooltipVisible,
|
|
31
|
-
disabled
|
|
32
|
+
disabled,
|
|
33
|
+
target
|
|
32
34
|
}
|
|
33
35
|
}, children);
|
|
34
36
|
|
|
@@ -39,5 +41,6 @@ TooltipProvider.propTypes = {
|
|
|
39
41
|
helpAriaLabel: _propTypes.default.string,
|
|
40
42
|
focusable: _propTypes.default.bool,
|
|
41
43
|
tooltipVisible: _propTypes.default.bool,
|
|
42
|
-
disabled: _propTypes.default.bool
|
|
44
|
+
disabled: _propTypes.default.bool,
|
|
45
|
+
target: _propTypes.default.instanceOf(Element)
|
|
43
46
|
};
|
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
export default Button;
|
|
2
2
|
export const ButtonWithForwardRef: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
|
|
3
|
-
declare function Button(
|
|
3
|
+
declare function Button({ size, subtext, as, children, forwardRef, "aria-label": ariaLabel, disabled, buttonType: buttonTypeProp, iconType, iconPosition, href, m, px, noWrap, target, rel, iconTooltipMessage, iconTooltipPosition, ...rest }: {
|
|
4
|
+
[x: string]: any;
|
|
5
|
+
size: any;
|
|
6
|
+
subtext: any;
|
|
7
|
+
as: any;
|
|
8
|
+
children: any;
|
|
9
|
+
forwardRef: any;
|
|
10
|
+
"aria-label": any;
|
|
11
|
+
disabled: any;
|
|
12
|
+
buttonType: any;
|
|
13
|
+
iconType: any;
|
|
14
|
+
iconPosition: any;
|
|
15
|
+
href: any;
|
|
16
|
+
m?: number | undefined;
|
|
17
|
+
px: any;
|
|
18
|
+
noWrap: any;
|
|
19
|
+
target: any;
|
|
20
|
+
rel: any;
|
|
21
|
+
iconTooltipMessage: any;
|
|
22
|
+
iconTooltipPosition: any;
|
|
23
|
+
}): JSX.Element;
|
|
4
24
|
declare namespace Button {
|
|
5
25
|
const propTypes: any;
|
|
6
26
|
namespace defaultProps {
|
|
@@ -17,6 +17,8 @@ var _button = _interopRequireWildcard(require("./button.style"));
|
|
|
17
17
|
|
|
18
18
|
var _tags = _interopRequireDefault(require("../../__internal__/utils/helpers/tags/tags"));
|
|
19
19
|
|
|
20
|
+
var _tooltipProvider = require("../../__internal__/tooltip-provider");
|
|
21
|
+
|
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
23
|
|
|
22
24
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
@@ -35,7 +37,8 @@ function renderChildren({
|
|
|
35
37
|
disabled,
|
|
36
38
|
buttonType,
|
|
37
39
|
iconTooltipMessage,
|
|
38
|
-
iconTooltipPosition
|
|
40
|
+
iconTooltipPosition,
|
|
41
|
+
tooltipTarget
|
|
39
42
|
/* eslint-enable */
|
|
40
43
|
|
|
41
44
|
}) {
|
|
@@ -57,43 +60,54 @@ function renderChildren({
|
|
|
57
60
|
"data-element": "main-text"
|
|
58
61
|
}, children), size === "large" && /*#__PURE__*/_react.default.createElement(_button.StyledButtonSubtext, {
|
|
59
62
|
"data-element": "subtext"
|
|
60
|
-
}, subtext)), iconType && !children && /*#__PURE__*/_react.default.createElement(
|
|
63
|
+
}, subtext)), iconType && !children && /*#__PURE__*/_react.default.createElement(_tooltipProvider.TooltipProvider, {
|
|
64
|
+
disabled: disabled,
|
|
65
|
+
focusable: false,
|
|
66
|
+
target: tooltipTarget
|
|
67
|
+
}, /*#__PURE__*/_react.default.createElement(_icon.default, _extends({}, iconProps, {
|
|
61
68
|
tooltipMessage: iconTooltipMessage,
|
|
62
69
|
tooltipPosition: iconTooltipPosition
|
|
63
|
-
})), iconType && iconPosition === "after" && children && /*#__PURE__*/_react.default.createElement(_icon.default, iconProps));
|
|
70
|
+
}))), iconType && iconPosition === "after" && children && /*#__PURE__*/_react.default.createElement(_icon.default, iconProps));
|
|
64
71
|
}
|
|
65
72
|
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
73
|
+
const Button = ({
|
|
74
|
+
size,
|
|
75
|
+
subtext,
|
|
76
|
+
as,
|
|
77
|
+
children,
|
|
78
|
+
forwardRef,
|
|
79
|
+
"aria-label": ariaLabel,
|
|
80
|
+
disabled,
|
|
81
|
+
buttonType: buttonTypeProp,
|
|
82
|
+
iconType,
|
|
83
|
+
iconPosition,
|
|
84
|
+
href,
|
|
85
|
+
m = 0,
|
|
86
|
+
px,
|
|
87
|
+
noWrap,
|
|
88
|
+
target,
|
|
89
|
+
rel,
|
|
90
|
+
iconTooltipMessage,
|
|
91
|
+
iconTooltipPosition,
|
|
92
|
+
...rest
|
|
93
|
+
}) => {
|
|
94
|
+
const [internalRef, setInternalRef] = (0, _react.useState)(null);
|
|
95
|
+
const buttonType = buttonTypeProp || as;
|
|
96
|
+
|
|
97
|
+
if (subtext.length > 0 && size !== "large") {
|
|
98
|
+
throw new Error("subtext prop has no effect unless the button is large");
|
|
99
|
+
}
|
|
100
|
+
|
|
83
101
|
let paddingX;
|
|
84
102
|
|
|
85
103
|
const handleLinkKeyDown = event => {
|
|
86
104
|
// If space key click link
|
|
87
105
|
if (event.key === " ") {
|
|
88
106
|
event.preventDefault();
|
|
89
|
-
|
|
107
|
+
internalRef.click();
|
|
90
108
|
}
|
|
91
109
|
};
|
|
92
110
|
|
|
93
|
-
if (href) {
|
|
94
|
-
rest.href = href;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
111
|
switch (size) {
|
|
98
112
|
case "small":
|
|
99
113
|
paddingX = 2;
|
|
@@ -108,7 +122,7 @@ const renderStyledButton = buttonProps => {
|
|
|
108
122
|
}
|
|
109
123
|
|
|
110
124
|
return /*#__PURE__*/_react.default.createElement(_button.default, _extends({
|
|
111
|
-
"aria-label": !
|
|
125
|
+
"aria-label": !children && iconType ? ariaLabel || iconType : undefined,
|
|
112
126
|
as: !disabled && href ? "a" : "button",
|
|
113
127
|
onKeyDown: href && handleLinkKeyDown,
|
|
114
128
|
draggable: false,
|
|
@@ -121,36 +135,33 @@ const renderStyledButton = buttonProps => {
|
|
|
121
135
|
px: px ?? paddingX,
|
|
122
136
|
m: m,
|
|
123
137
|
noWrap: noWrap,
|
|
124
|
-
iconOnly: !
|
|
138
|
+
iconOnly: !children && iconType,
|
|
139
|
+
iconPosition: iconPosition,
|
|
125
140
|
target: target,
|
|
126
141
|
rel: rel
|
|
127
|
-
}, (0, _tags.default)("button",
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
142
|
+
}, (0, _tags.default)("button", rest), rest, href && {
|
|
143
|
+
href
|
|
144
|
+
}, {
|
|
145
|
+
ref: reference => {
|
|
146
|
+
if (reference) {
|
|
147
|
+
setInternalRef(reference);
|
|
148
|
+
if (!forwardRef) return;
|
|
149
|
+
if (typeof forwardRef === "object") forwardRef.current = reference;
|
|
150
|
+
if (typeof forwardRef === "function") forwardRef(reference);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}), renderChildren({
|
|
154
|
+
iconType,
|
|
155
|
+
iconPosition,
|
|
134
156
|
size,
|
|
135
|
-
subtext
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const {
|
|
139
|
-
as,
|
|
157
|
+
subtext,
|
|
158
|
+
children,
|
|
159
|
+
disabled,
|
|
140
160
|
buttonType,
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
buttonType: buttonType || as,
|
|
146
|
-
ref: forwardRef || linkRef
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
if (subtext.length > 0 && size !== "large") {
|
|
150
|
-
throw new Error("subtext prop has no effect unless the button is large");
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return renderStyledButton(propsWithoutAs);
|
|
161
|
+
iconTooltipMessage,
|
|
162
|
+
iconTooltipPosition,
|
|
163
|
+
tooltipTarget: internalRef
|
|
164
|
+
}));
|
|
154
165
|
};
|
|
155
166
|
|
|
156
167
|
Button.propTypes = {
|
|
@@ -63,7 +63,8 @@ const Icon = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
63
63
|
tooltipPosition: tooltipPositionFromContext,
|
|
64
64
|
focusable: focusableFromContext,
|
|
65
65
|
tooltipVisible: tooltipVisibleFromContext,
|
|
66
|
-
disabled: disabledFromContext
|
|
66
|
+
disabled: disabledFromContext,
|
|
67
|
+
target
|
|
67
68
|
} = (0, _react.useContext)(_tooltipProvider.TooltipContext);
|
|
68
69
|
/** Return Icon type with overrides */
|
|
69
70
|
|
|
@@ -131,7 +132,8 @@ const Icon = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
131
132
|
inputSize: inputSize,
|
|
132
133
|
bgColor: tooltipBgColor,
|
|
133
134
|
fontColor: tooltipFontColor,
|
|
134
|
-
flipOverrides: tooltipFlipOverrides
|
|
135
|
+
flipOverrides: tooltipFlipOverrides,
|
|
136
|
+
target: target
|
|
135
137
|
}, icon);
|
|
136
138
|
}
|
|
137
139
|
|
|
@@ -38,13 +38,8 @@ const IconButton = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
38
38
|
disabled,
|
|
39
39
|
...rest
|
|
40
40
|
}, ref) => {
|
|
41
|
+
const [internalRef, setInternalRef] = (0, _react.useState)(null);
|
|
41
42
|
const marginProps = (0, _utils.filterStyledSystemMarginProps)(rest);
|
|
42
|
-
const hasIconWithTooltip = !!_react.default.Children.toArray(children).find(child => {
|
|
43
|
-
var _child$props;
|
|
44
|
-
|
|
45
|
-
return child === null || child === void 0 ? void 0 : (_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.tooltipMessage;
|
|
46
|
-
});
|
|
47
|
-
const [tooltipVisible, setTooltipVisible] = (0, _react.useState)(undefined);
|
|
48
43
|
|
|
49
44
|
const onKeyDown = e => {
|
|
50
45
|
if (_events.default.isEnterKey(e) || _events.default.isSpaceKey(e)) {
|
|
@@ -59,26 +54,23 @@ const IconButton = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
59
54
|
onAction(e);
|
|
60
55
|
};
|
|
61
56
|
|
|
62
|
-
const handleTooltipVisibility = (ev, callbackName) => {
|
|
63
|
-
setTooltipVisible(["onFocus", "onMouseEnter"].includes(callbackName));
|
|
64
|
-
if (rest[callbackName]) rest[callbackName](ev);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
57
|
return /*#__PURE__*/_react.default.createElement(_iconButton.default, _extends({}, rest, {
|
|
68
58
|
"aria-label": ariaLabel,
|
|
69
59
|
onKeyDown: onKeyDown,
|
|
70
60
|
onClick: handleOnAction,
|
|
71
|
-
ref:
|
|
61
|
+
ref: reference => {
|
|
62
|
+
if (reference) {
|
|
63
|
+
setInternalRef(reference);
|
|
64
|
+
if (!ref) return;
|
|
65
|
+
if (typeof ref === "object") ref.current = reference;
|
|
66
|
+
if (typeof ref === "function") ref(reference);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
72
69
|
disabled: disabled
|
|
73
|
-
}, !disabled && hasIconWithTooltip && {
|
|
74
|
-
onFocus: ev => handleTooltipVisibility(ev, "onFocus"),
|
|
75
|
-
onBlur: ev => handleTooltipVisibility(ev, "onBlur"),
|
|
76
|
-
onMouseEnter: ev => handleTooltipVisibility(ev, "onMouseEnter"),
|
|
77
|
-
onMouseLeave: ev => handleTooltipVisibility(ev, "onMouseLeave")
|
|
78
70
|
}, marginProps), /*#__PURE__*/_react.default.createElement(_tooltipProvider.TooltipProvider, {
|
|
79
71
|
disabled: disabled,
|
|
80
|
-
|
|
81
|
-
|
|
72
|
+
focusable: false,
|
|
73
|
+
target: internalRef
|
|
82
74
|
}, children));
|
|
83
75
|
});
|
|
84
76
|
|
|
@@ -42,6 +42,7 @@ const Tooltip = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
42
42
|
bgColor,
|
|
43
43
|
fontColor,
|
|
44
44
|
flipOverrides,
|
|
45
|
+
target,
|
|
45
46
|
...rest
|
|
46
47
|
}, ref) => {
|
|
47
48
|
const tooltipRef = (0, _react.useRef)(ref || null);
|
|
@@ -81,6 +82,7 @@ const Tooltip = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
81
82
|
visible: isVisible
|
|
82
83
|
}, {
|
|
83
84
|
render: attrs => tooltip(attrs, message),
|
|
85
|
+
reference: target,
|
|
84
86
|
popperOptions: {
|
|
85
87
|
modifiers: [...(flipOverrides ? [{
|
|
86
88
|
name: "flip",
|
|
@@ -119,6 +121,8 @@ Tooltip.propTypes = {
|
|
|
119
121
|
|
|
120
122
|
/** Defines the size of the tooltip content */
|
|
121
123
|
size: _propTypes.default.oneOf(["medium", "large"]),
|
|
124
|
+
// Reference element, tooltip will be positioned in relation to this element
|
|
125
|
+
target: _propTypes.default.instanceOf(Element),
|
|
122
126
|
|
|
123
127
|
/** Override background color of the Tooltip, provide any color from palette or any valid css color value. */
|
|
124
128
|
bgColor: _propTypes.default.string,
|
|
@@ -25,6 +25,7 @@ export interface TooltipProps {
|
|
|
25
25
|
* (see https://popper.js.org/docs/v2/modifiers/flip/#fallbackplacements)
|
|
26
26
|
*/
|
|
27
27
|
flipOverrides?: ["top" | "bottom" | "left" | "right"];
|
|
28
|
+
target?: Element;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
export interface TooltipInternalProps extends TooltipProps {
|