carbon-react 101.0.3 → 101.2.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/lib/__internal__/tooltip-provider/index.d.ts +3 -0
- package/lib/__internal__/tooltip-provider/index.js +12 -3
- package/lib/components/icon/icon.component.js +11 -7
- package/lib/components/icon-button/icon-button.component.js +35 -4
- package/lib/components/icon-button/icon-button.d.ts +2 -0
- package/lib/components/icon-button/icon-button.style.js +4 -1
- package/lib/components/select/multi-select/multi-select.component.js +9 -12
- package/lib/components/text-editor/__internal__/decorators/link-decorator.js +9 -2
- package/package.json +1 -1
|
@@ -11,6 +11,9 @@ export interface TooltipProviderProps {
|
|
|
11
11
|
children: React.ReactNode;
|
|
12
12
|
/** Aria label for rendered help component */
|
|
13
13
|
helpAriaLabel?: string;
|
|
14
|
+
focusable?: boolean;
|
|
15
|
+
tooltipVisible?: boolean;
|
|
16
|
+
disabled?: boolean;
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
declare const ToolbarContext: React.Context<ToolbarContextProps>;
|
|
@@ -18,11 +18,17 @@ exports.TooltipContext = TooltipContext;
|
|
|
18
18
|
const TooltipProvider = ({
|
|
19
19
|
children,
|
|
20
20
|
tooltipPosition,
|
|
21
|
-
helpAriaLabel
|
|
21
|
+
helpAriaLabel,
|
|
22
|
+
focusable = true,
|
|
23
|
+
tooltipVisible,
|
|
24
|
+
disabled = false
|
|
22
25
|
}) => /*#__PURE__*/_react.default.createElement(TooltipContext.Provider, {
|
|
23
26
|
value: {
|
|
24
27
|
tooltipPosition,
|
|
25
|
-
helpAriaLabel
|
|
28
|
+
helpAriaLabel,
|
|
29
|
+
focusable,
|
|
30
|
+
tooltipVisible,
|
|
31
|
+
disabled
|
|
26
32
|
}
|
|
27
33
|
}, children);
|
|
28
34
|
|
|
@@ -30,5 +36,8 @@ exports.TooltipProvider = TooltipProvider;
|
|
|
30
36
|
TooltipProvider.propTypes = {
|
|
31
37
|
children: _propTypes.default.node.isRequired,
|
|
32
38
|
tooltipPosition: _propTypes.default.oneOf(["top", "bottom", "left", "right"]),
|
|
33
|
-
helpAriaLabel: _propTypes.default.string
|
|
39
|
+
helpAriaLabel: _propTypes.default.string,
|
|
40
|
+
focusable: _propTypes.default.bool,
|
|
41
|
+
tooltipVisible: _propTypes.default.bool,
|
|
42
|
+
disabled: _propTypes.default.bool
|
|
34
43
|
};
|
|
@@ -57,6 +57,12 @@ const Icon = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
57
57
|
...rest
|
|
58
58
|
}, ref) => {
|
|
59
59
|
const isInteractive = !!tooltipMessage && !disabled;
|
|
60
|
+
const {
|
|
61
|
+
tooltipPosition: tooltipPositionFromContext,
|
|
62
|
+
focusable: focusableFromContext,
|
|
63
|
+
tooltipVisible: tooltipVisibleFromContext,
|
|
64
|
+
disabled: disabledFromContext
|
|
65
|
+
} = (0, _react.useContext)(_tooltipProvider.TooltipContext);
|
|
60
66
|
/** Return Icon type with overrides */
|
|
61
67
|
|
|
62
68
|
const iconType = () => {
|
|
@@ -83,13 +89,14 @@ const Icon = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
83
89
|
}
|
|
84
90
|
};
|
|
85
91
|
|
|
86
|
-
const
|
|
92
|
+
const isFocusable = focusableFromContext !== undefined ? focusableFromContext : focusable;
|
|
93
|
+
const hasTooltip = !disabled && !disabledFromContext && tooltipMessage && isFocusable;
|
|
87
94
|
const styleProps = {
|
|
88
95
|
bg,
|
|
89
96
|
bgSize,
|
|
90
97
|
bgShape,
|
|
91
98
|
color,
|
|
92
|
-
disabled,
|
|
99
|
+
disabled: disabledFromContext || disabled,
|
|
93
100
|
fontSize,
|
|
94
101
|
isInteractive,
|
|
95
102
|
type: iconType(),
|
|
@@ -108,12 +115,9 @@ const Icon = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
108
115
|
role: hasTooltip && role === undefined ? "tooltip" : role
|
|
109
116
|
}));
|
|
110
117
|
|
|
111
|
-
const {
|
|
112
|
-
tooltipPosition: tooltipPositionFromContext
|
|
113
|
-
} = (0, _react.useContext)(_tooltipProvider.TooltipContext);
|
|
114
|
-
|
|
115
118
|
if (tooltipMessage) {
|
|
116
|
-
const
|
|
119
|
+
const showTooltip = tooltipVisibleFromContext !== undefined ? tooltipVisibleFromContext : tooltipVisible;
|
|
120
|
+
const visible = disabled ? false : showTooltip;
|
|
117
121
|
return /*#__PURE__*/_react.default.createElement(_tooltip.default, {
|
|
118
122
|
message: tooltipMessage,
|
|
119
123
|
position: tooltipPositionFromContext || tooltipPosition,
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _react =
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
@@ -19,8 +19,14 @@ var _icon = _interopRequireDefault(require("../icon"));
|
|
|
19
19
|
|
|
20
20
|
var _utils = require("../../style/utils");
|
|
21
21
|
|
|
22
|
+
var _tooltipProvider = require("../../__internal__/tooltip-provider");
|
|
23
|
+
|
|
22
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
25
|
|
|
26
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
27
|
+
|
|
28
|
+
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; }
|
|
29
|
+
|
|
24
30
|
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); }
|
|
25
31
|
|
|
26
32
|
const marginPropTypes = (0, _utils.filterStyledSystemMarginProps)(_propTypes2.default.space);
|
|
@@ -29,9 +35,16 @@ const IconButton = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
29
35
|
"aria-label": ariaLabel,
|
|
30
36
|
onAction,
|
|
31
37
|
children,
|
|
38
|
+
disabled,
|
|
32
39
|
...rest
|
|
33
40
|
}, ref) => {
|
|
34
41
|
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);
|
|
35
48
|
|
|
36
49
|
const onKeyDown = e => {
|
|
37
50
|
if (_events.default.isEnterKey(e) || _events.default.isSpaceKey(e)) {
|
|
@@ -46,12 +59,27 @@ const IconButton = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
46
59
|
onAction(e);
|
|
47
60
|
};
|
|
48
61
|
|
|
62
|
+
const handleTooltipVisibility = (ev, callbackName) => {
|
|
63
|
+
setTooltipVisible(["onFocus", "onMouseEnter"].includes(callbackName));
|
|
64
|
+
if (rest[callbackName]) rest[callbackName](ev);
|
|
65
|
+
};
|
|
66
|
+
|
|
49
67
|
return /*#__PURE__*/_react.default.createElement(_iconButton.default, _extends({}, rest, {
|
|
50
68
|
"aria-label": ariaLabel,
|
|
51
69
|
onKeyDown: onKeyDown,
|
|
52
70
|
onClick: handleOnAction,
|
|
53
|
-
ref: ref
|
|
54
|
-
|
|
71
|
+
ref: ref,
|
|
72
|
+
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
|
+
}, marginProps), /*#__PURE__*/_react.default.createElement(_tooltipProvider.TooltipProvider, {
|
|
79
|
+
disabled: disabled,
|
|
80
|
+
tooltipVisible: tooltipVisible,
|
|
81
|
+
focusable: false
|
|
82
|
+
}, children));
|
|
55
83
|
});
|
|
56
84
|
|
|
57
85
|
IconButton.propTypes = { ...marginPropTypes,
|
|
@@ -65,7 +93,10 @@ IconButton.propTypes = { ...marginPropTypes,
|
|
|
65
93
|
onAction: _propTypes.default.func.isRequired,
|
|
66
94
|
|
|
67
95
|
/** Prop to specify the aria-label of the icon-button component */
|
|
68
|
-
"aria-label": _propTypes.default.string
|
|
96
|
+
"aria-label": _propTypes.default.string,
|
|
97
|
+
|
|
98
|
+
/** Set the button to disabled */
|
|
99
|
+
disabled: _propTypes.default.bool
|
|
69
100
|
};
|
|
70
101
|
var _default = IconButton;
|
|
71
102
|
exports.default = _default;
|
|
@@ -7,6 +7,8 @@ export interface IconButtonProps extends MarginProps {
|
|
|
7
7
|
children: React.ReactElement<IconProps>;
|
|
8
8
|
/** Callback */
|
|
9
9
|
onAction: React.MouseEventHandler<HTMLButtonElement>;
|
|
10
|
+
/** Set the button to disabled */
|
|
11
|
+
disabled?: boolean;
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
declare function IconButton(
|
|
@@ -47,7 +47,10 @@ const StyledIconButton = _styledComponents.default.button.attrs({
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
${_icon.default} {
|
|
50
|
-
${disabled &&
|
|
50
|
+
${disabled && (0, _styledComponents.css)`
|
|
51
|
+
color: ${theme.icon.disabled};
|
|
52
|
+
background-color: transparent;
|
|
53
|
+
`};
|
|
51
54
|
position: relative;
|
|
52
55
|
|
|
53
56
|
&:focus {
|
|
@@ -344,7 +344,7 @@ const MultiSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
344
344
|
} = optionData;
|
|
345
345
|
|
|
346
346
|
if (selectionType === "navigationKey") {
|
|
347
|
-
setHighlightedValue(
|
|
347
|
+
setHighlightedValue(newValue);
|
|
348
348
|
return;
|
|
349
349
|
}
|
|
350
350
|
|
|
@@ -353,26 +353,23 @@ const MultiSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
353
353
|
}
|
|
354
354
|
|
|
355
355
|
setTextValue("");
|
|
356
|
+
const isAlreadySelected = selectedValue.findIndex(val => (0, _isExpectedValue.default)(val, newValue)) !== -1;
|
|
357
|
+
|
|
358
|
+
if (!isAlreadySelected && isControlled.current && onChange) {
|
|
359
|
+
onChange(createCustomEvent([...selectedValue, newValue]));
|
|
360
|
+
}
|
|
361
|
+
|
|
356
362
|
setSelectedValue(previousValue => {
|
|
357
363
|
textboxRef.focus();
|
|
358
364
|
isMouseDownReported.current = false;
|
|
359
|
-
const isAlreadySelected = previousValue.findIndex(val => (0, _isExpectedValue.default)(val, newValue)) !== -1;
|
|
360
365
|
|
|
361
366
|
if (isAlreadySelected) {
|
|
362
367
|
return previousValue;
|
|
363
368
|
}
|
|
364
369
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
if (isControlled.current && onChange) {
|
|
368
|
-
onChange(createCustomEvent(valueList));
|
|
369
|
-
return previousValue;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
return valueList;
|
|
370
|
+
return [...previousValue, newValue];
|
|
373
371
|
});
|
|
374
|
-
},
|
|
375
|
-
[createCustomEvent, onChange, textboxRef]);
|
|
372
|
+
}, [createCustomEvent, onChange, textboxRef, selectedValue]);
|
|
376
373
|
|
|
377
374
|
function onSelectListClose() {
|
|
378
375
|
setOpenState(false);
|
|
@@ -29,8 +29,15 @@ function findWithRegex(regex, contentBlock, callback) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
const linkStrategy = (contentBlock, callback) => {
|
|
32
|
-
const
|
|
33
|
-
|
|
32
|
+
const combineRegex = (...regex) => new RegExp(regex.map(r => r.source).join(""), "g");
|
|
33
|
+
|
|
34
|
+
const urlRegex = combineRegex(/\b/, /(http:\/\/|https:\/\/|www\.)/, // prefix
|
|
35
|
+
/([\w-]+:([\w-]+@))?/, // userinfo
|
|
36
|
+
/([\w-]+\.)+\w+/, // domain
|
|
37
|
+
/(:\d+)?/, // port
|
|
38
|
+
/(\/[\w#!:.?+=&%@!-/]+)?/, // paths, queries, fragments
|
|
39
|
+
/\b/);
|
|
40
|
+
findWithRegex(urlRegex, contentBlock, callback);
|
|
34
41
|
};
|
|
35
42
|
|
|
36
43
|
var _default = {
|