@carbon/react 1.54.0-rc.0 → 1.54.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/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +822 -822
- package/es/components/Button/Button.d.ts +1 -1
- package/es/components/Button/Button.js +13 -89
- package/es/components/Button/ButtonBase.d.ts +10 -0
- package/es/components/Button/ButtonBase.js +110 -0
- package/es/components/CodeSnippet/CodeSnippet.js +1 -0
- package/es/components/IconButton/index.js +2 -3
- package/es/components/Menu/Menu.js +2 -0
- package/es/components/ModalWrapper/ModalWrapper.d.ts +1 -1
- package/es/components/Slider/Slider.Skeleton.js +6 -2
- package/es/components/StructuredList/StructuredList.d.ts +8 -0
- package/es/components/StructuredList/StructuredList.js +28 -10
- package/es/feature-flags.js +2 -1
- package/es/internal/environment.js +5 -1
- package/es/internal/keyboard/navigation.js +6 -2
- package/es/internal/useOutsideClick.js +31 -0
- package/lib/components/Button/Button.d.ts +1 -1
- package/lib/components/Button/Button.js +13 -90
- package/lib/components/Button/ButtonBase.d.ts +10 -0
- package/lib/components/Button/ButtonBase.js +119 -0
- package/lib/components/CodeSnippet/CodeSnippet.js +1 -0
- package/lib/components/IconButton/index.js +2 -3
- package/lib/components/Menu/Menu.js +2 -0
- package/lib/components/ModalWrapper/ModalWrapper.d.ts +1 -1
- package/lib/components/Slider/Slider.Skeleton.js +5 -1
- package/lib/components/StructuredList/StructuredList.d.ts +8 -0
- package/lib/components/StructuredList/StructuredList.js +27 -9
- package/lib/feature-flags.js +2 -1
- package/lib/internal/environment.js +5 -1
- package/lib/internal/keyboard/navigation.js +6 -2
- package/lib/internal/useOutsideClick.js +35 -0
- package/package.json +6 -6
|
@@ -12,17 +12,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
12
12
|
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
|
|
13
13
|
var PropTypes = require('prop-types');
|
|
14
14
|
var React = require('react');
|
|
15
|
-
var cx = require('classnames');
|
|
16
15
|
var index = require('../IconButton/index.js');
|
|
17
16
|
var events = require('../../tools/events.js');
|
|
18
|
-
var
|
|
19
|
-
var useId = require('../../internal/useId.js');
|
|
17
|
+
var ButtonBase = require('./ButtonBase.js');
|
|
20
18
|
|
|
21
19
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
22
20
|
|
|
23
21
|
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
24
22
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
25
|
-
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
|
|
26
23
|
|
|
27
24
|
const ButtonKinds = ['primary', 'secondary', 'danger', 'ghost', 'danger--primary', 'danger--ghost', 'danger--tertiary', 'tertiary'];
|
|
28
25
|
const ButtonSizes = ['sm', 'md', 'lg', 'xl', '2xl'];
|
|
@@ -34,18 +31,13 @@ function isIconOnlyButton(hasIconOnly, _kind) {
|
|
|
34
31
|
}
|
|
35
32
|
return false;
|
|
36
33
|
}
|
|
37
|
-
const Button = /*#__PURE__*/React__default["default"].forwardRef(function Button(
|
|
38
|
-
|
|
34
|
+
const Button = /*#__PURE__*/React__default["default"].forwardRef(function Button(props, ref) {
|
|
35
|
+
const tooltipRef = React.useRef(null);
|
|
36
|
+
const {
|
|
39
37
|
as,
|
|
40
38
|
children,
|
|
41
|
-
className,
|
|
42
|
-
dangerDescription = 'danger',
|
|
43
|
-
disabled = false,
|
|
44
39
|
hasIconOnly = false,
|
|
45
|
-
href,
|
|
46
40
|
iconDescription,
|
|
47
|
-
isExpressive = false,
|
|
48
|
-
isSelected,
|
|
49
41
|
kind = 'primary',
|
|
50
42
|
onBlur,
|
|
51
43
|
onClick,
|
|
@@ -54,92 +46,21 @@ const Button = /*#__PURE__*/React__default["default"].forwardRef(function Button
|
|
|
54
46
|
onMouseLeave,
|
|
55
47
|
renderIcon: ButtonImageElement,
|
|
56
48
|
size,
|
|
57
|
-
tabIndex,
|
|
58
49
|
tooltipAlignment = 'center',
|
|
59
50
|
tooltipPosition = 'top',
|
|
60
|
-
type = 'button',
|
|
61
51
|
...rest
|
|
62
|
-
} =
|
|
63
|
-
const tooltipRef = React.useRef(null);
|
|
64
|
-
const prefix = usePrefix.usePrefix();
|
|
52
|
+
} = props;
|
|
65
53
|
const handleClick = evt => {
|
|
66
54
|
// Prevent clicks on the tooltip from triggering the button click event
|
|
67
55
|
if (evt.target === tooltipRef.current) {
|
|
68
56
|
evt.preventDefault();
|
|
69
57
|
}
|
|
70
58
|
};
|
|
71
|
-
const buttonClasses = cx__default["default"](className, {
|
|
72
|
-
[`${prefix}--btn`]: true,
|
|
73
|
-
[`${prefix}--btn--sm`]: size === 'sm' && !isExpressive,
|
|
74
|
-
// TODO: V12 - Remove this class
|
|
75
|
-
[`${prefix}--btn--md`]: size === 'md' && !isExpressive,
|
|
76
|
-
// TODO: V12 - Remove this class
|
|
77
|
-
[`${prefix}--btn--xl`]: size === 'xl',
|
|
78
|
-
// TODO: V12 - Remove this class
|
|
79
|
-
[`${prefix}--btn--2xl`]: size === '2xl',
|
|
80
|
-
// TODO: V12 - Remove this class
|
|
81
|
-
[`${prefix}--layout--size-${size}`]: size,
|
|
82
|
-
[`${prefix}--btn--${kind}`]: kind,
|
|
83
|
-
[`${prefix}--btn--disabled`]: disabled,
|
|
84
|
-
[`${prefix}--btn--expressive`]: isExpressive,
|
|
85
|
-
[`${prefix}--btn--icon-only`]: hasIconOnly,
|
|
86
|
-
[`${prefix}--btn--selected`]: hasIconOnly && isSelected && kind === 'ghost'
|
|
87
|
-
});
|
|
88
|
-
const commonProps = {
|
|
89
|
-
tabIndex,
|
|
90
|
-
className: buttonClasses,
|
|
91
|
-
ref
|
|
92
|
-
};
|
|
93
|
-
const buttonImage = !ButtonImageElement ? null : /*#__PURE__*/React__default["default"].createElement(ButtonImageElement, {
|
|
94
|
-
"aria-label": iconDescription,
|
|
95
|
-
className: `${prefix}--btn__icon`,
|
|
96
|
-
"aria-hidden": "true"
|
|
97
|
-
});
|
|
98
59
|
const iconOnlyImage = !ButtonImageElement ? null : /*#__PURE__*/React__default["default"].createElement(ButtonImageElement, null);
|
|
99
|
-
const dangerButtonVariants = ['danger', 'danger--tertiary', 'danger--ghost'];
|
|
100
|
-
let component = 'button';
|
|
101
|
-
const assistiveId = useId.useId('danger-description');
|
|
102
|
-
const {
|
|
103
|
-
'aria-pressed': ariaPressed,
|
|
104
|
-
'aria-describedby': ariaDescribedBy
|
|
105
|
-
} = rest;
|
|
106
|
-
let otherProps = {
|
|
107
|
-
disabled,
|
|
108
|
-
type,
|
|
109
|
-
'aria-describedby': dangerButtonVariants.includes(kind) ? assistiveId : ariaDescribedBy || undefined,
|
|
110
|
-
'aria-pressed': ariaPressed ?? (hasIconOnly && kind === 'ghost' ? isSelected : undefined)
|
|
111
|
-
};
|
|
112
|
-
const anchorProps = {
|
|
113
|
-
href
|
|
114
|
-
};
|
|
115
|
-
let assistiveText = null;
|
|
116
|
-
if (dangerButtonVariants.includes(kind)) {
|
|
117
|
-
assistiveText = /*#__PURE__*/React__default["default"].createElement("span", {
|
|
118
|
-
id: assistiveId,
|
|
119
|
-
className: `${prefix}--visually-hidden`
|
|
120
|
-
}, dangerDescription);
|
|
121
|
-
}
|
|
122
|
-
if (as) {
|
|
123
|
-
component = as;
|
|
124
|
-
otherProps = {
|
|
125
|
-
...otherProps,
|
|
126
|
-
...anchorProps
|
|
127
|
-
};
|
|
128
|
-
} else if (href && !disabled) {
|
|
129
|
-
component = 'a';
|
|
130
|
-
otherProps = anchorProps;
|
|
131
|
-
}
|
|
132
60
|
if (!isIconOnlyButton(hasIconOnly)) {
|
|
133
|
-
return /*#__PURE__*/React__default["default"].createElement(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
onFocus,
|
|
137
|
-
onBlur,
|
|
138
|
-
onClick,
|
|
139
|
-
...rest,
|
|
140
|
-
...commonProps,
|
|
141
|
-
...otherProps
|
|
142
|
-
}, assistiveText, children, buttonImage);
|
|
61
|
+
return /*#__PURE__*/React__default["default"].createElement(ButtonBase["default"], _rollupPluginBabelHelpers["extends"]({
|
|
62
|
+
ref: ref
|
|
63
|
+
}, props));
|
|
143
64
|
} else {
|
|
144
65
|
let align = undefined;
|
|
145
66
|
if (tooltipPosition === 'top' || tooltipPosition === 'bottom') {
|
|
@@ -156,7 +77,8 @@ const Button = /*#__PURE__*/React__default["default"].forwardRef(function Button
|
|
|
156
77
|
if (tooltipPosition === 'right' || tooltipPosition === 'left') {
|
|
157
78
|
align = tooltipPosition;
|
|
158
79
|
}
|
|
159
|
-
return /*#__PURE__*/React__default["default"].createElement(index.IconButton, _rollupPluginBabelHelpers["extends"]({
|
|
80
|
+
return /*#__PURE__*/React__default["default"].createElement(index.IconButton, _rollupPluginBabelHelpers["extends"]({}, rest, {
|
|
81
|
+
ref: ref,
|
|
160
82
|
as: as,
|
|
161
83
|
align: align,
|
|
162
84
|
label: iconDescription,
|
|
@@ -166,8 +88,9 @@ const Button = /*#__PURE__*/React__default["default"].forwardRef(function Button
|
|
|
166
88
|
onMouseLeave: onMouseLeave,
|
|
167
89
|
onFocus: onFocus,
|
|
168
90
|
onBlur: onBlur,
|
|
169
|
-
onClick: events.composeEventHandlers([onClick, handleClick])
|
|
170
|
-
|
|
91
|
+
onClick: events.composeEventHandlers([onClick, handleClick]),
|
|
92
|
+
renderIcon: iconOnlyImage ? null : ButtonImageElement // avoid doubling the icon.
|
|
93
|
+
}), iconOnlyImage ?? children);
|
|
171
94
|
}
|
|
172
95
|
});
|
|
173
96
|
Button.displayName = 'Button';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { ButtonProps } from './Button';
|
|
9
|
+
declare const ButtonBase: React.ForwardRefExoticComponent<Omit<ButtonProps<React.ElementType<any>>, "ref"> & React.RefAttributes<unknown>>;
|
|
10
|
+
export default ButtonBase;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
|
+
|
|
12
|
+
var React = require('react');
|
|
13
|
+
var cx = require('classnames');
|
|
14
|
+
var usePrefix = require('../../internal/usePrefix.js');
|
|
15
|
+
var useId = require('../../internal/useId.js');
|
|
16
|
+
|
|
17
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
18
|
+
|
|
19
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
20
|
+
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
|
|
21
|
+
|
|
22
|
+
const ButtonBase = /*#__PURE__*/React__default["default"].forwardRef(function ButtonBase(_ref, ref) {
|
|
23
|
+
let {
|
|
24
|
+
as,
|
|
25
|
+
children,
|
|
26
|
+
className,
|
|
27
|
+
dangerDescription = 'danger',
|
|
28
|
+
disabled = false,
|
|
29
|
+
hasIconOnly = false,
|
|
30
|
+
href,
|
|
31
|
+
iconDescription,
|
|
32
|
+
isExpressive = false,
|
|
33
|
+
isSelected,
|
|
34
|
+
kind = 'primary',
|
|
35
|
+
onBlur,
|
|
36
|
+
onClick,
|
|
37
|
+
onFocus,
|
|
38
|
+
onMouseEnter,
|
|
39
|
+
onMouseLeave,
|
|
40
|
+
renderIcon: ButtonImageElement,
|
|
41
|
+
size,
|
|
42
|
+
tabIndex,
|
|
43
|
+
type = 'button',
|
|
44
|
+
...rest
|
|
45
|
+
} = _ref;
|
|
46
|
+
const prefix = usePrefix.usePrefix();
|
|
47
|
+
const buttonClasses = cx__default["default"](className, {
|
|
48
|
+
[`${prefix}--btn`]: true,
|
|
49
|
+
[`${prefix}--btn--sm`]: size === 'sm' && !isExpressive,
|
|
50
|
+
// TODO: V12 - Remove this class
|
|
51
|
+
[`${prefix}--btn--md`]: size === 'md' && !isExpressive,
|
|
52
|
+
// TODO: V12 - Remove this class
|
|
53
|
+
[`${prefix}--btn--xl`]: size === 'xl',
|
|
54
|
+
// TODO: V12 - Remove this class
|
|
55
|
+
[`${prefix}--btn--2xl`]: size === '2xl',
|
|
56
|
+
// TODO: V12 - Remove this class
|
|
57
|
+
[`${prefix}--layout--size-${size}`]: size,
|
|
58
|
+
[`${prefix}--btn--${kind}`]: kind,
|
|
59
|
+
[`${prefix}--btn--disabled`]: disabled,
|
|
60
|
+
[`${prefix}--btn--expressive`]: isExpressive,
|
|
61
|
+
[`${prefix}--btn--icon-only`]: hasIconOnly && !className?.includes(`${prefix}--btn--icon-only`),
|
|
62
|
+
[`${prefix}--btn--selected`]: hasIconOnly && isSelected && kind === 'ghost'
|
|
63
|
+
});
|
|
64
|
+
const commonProps = {
|
|
65
|
+
tabIndex,
|
|
66
|
+
className: buttonClasses,
|
|
67
|
+
ref
|
|
68
|
+
};
|
|
69
|
+
const buttonImage = !ButtonImageElement ? null : /*#__PURE__*/React__default["default"].createElement(ButtonImageElement, {
|
|
70
|
+
"aria-label": iconDescription,
|
|
71
|
+
className: `${prefix}--btn__icon`,
|
|
72
|
+
"aria-hidden": "true"
|
|
73
|
+
});
|
|
74
|
+
const dangerButtonVariants = ['danger', 'danger--tertiary', 'danger--ghost'];
|
|
75
|
+
let component = 'button';
|
|
76
|
+
const assistiveId = useId.useId('danger-description');
|
|
77
|
+
const {
|
|
78
|
+
'aria-pressed': ariaPressed,
|
|
79
|
+
'aria-describedby': ariaDescribedBy
|
|
80
|
+
} = rest;
|
|
81
|
+
let otherProps = {
|
|
82
|
+
disabled,
|
|
83
|
+
type,
|
|
84
|
+
'aria-describedby': dangerButtonVariants.includes(kind) ? assistiveId : ariaDescribedBy || undefined,
|
|
85
|
+
'aria-pressed': ariaPressed ?? (hasIconOnly && kind === 'ghost' ? isSelected : undefined)
|
|
86
|
+
};
|
|
87
|
+
const anchorProps = {
|
|
88
|
+
href
|
|
89
|
+
};
|
|
90
|
+
let assistiveText = null;
|
|
91
|
+
if (dangerButtonVariants.includes(kind)) {
|
|
92
|
+
assistiveText = /*#__PURE__*/React__default["default"].createElement("span", {
|
|
93
|
+
id: assistiveId,
|
|
94
|
+
className: `${prefix}--visually-hidden`
|
|
95
|
+
}, dangerDescription);
|
|
96
|
+
}
|
|
97
|
+
if (as) {
|
|
98
|
+
component = as;
|
|
99
|
+
otherProps = {
|
|
100
|
+
...otherProps,
|
|
101
|
+
...anchorProps
|
|
102
|
+
};
|
|
103
|
+
} else if (href && !disabled) {
|
|
104
|
+
component = 'a';
|
|
105
|
+
otherProps = anchorProps;
|
|
106
|
+
}
|
|
107
|
+
return /*#__PURE__*/React__default["default"].createElement(component, {
|
|
108
|
+
onMouseEnter,
|
|
109
|
+
onMouseLeave,
|
|
110
|
+
onFocus,
|
|
111
|
+
onBlur,
|
|
112
|
+
onClick,
|
|
113
|
+
...rest,
|
|
114
|
+
...commonProps,
|
|
115
|
+
...otherProps
|
|
116
|
+
}, assistiveText, children, buttonImage);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
exports["default"] = ButtonBase;
|
|
@@ -12,12 +12,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
12
12
|
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
|
|
13
13
|
var PropTypes = require('prop-types');
|
|
14
14
|
var React = require('react');
|
|
15
|
-
var Button = require('../Button/Button.js');
|
|
16
|
-
require('../Button/Button.Skeleton.js');
|
|
17
15
|
var cx = require('classnames');
|
|
18
16
|
require('../Tooltip/DefinitionTooltip.js');
|
|
19
17
|
var Tooltip = require('../Tooltip/Tooltip.js');
|
|
20
18
|
var usePrefix = require('../../internal/usePrefix.js');
|
|
19
|
+
var ButtonBase = require('../Button/ButtonBase.js');
|
|
21
20
|
|
|
22
21
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
23
22
|
|
|
@@ -55,7 +54,7 @@ const IconButton = /*#__PURE__*/React__default["default"].forwardRef(function Ic
|
|
|
55
54
|
enterDelayMs: enterDelayMs,
|
|
56
55
|
label: label,
|
|
57
56
|
leaveDelayMs: leaveDelayMs
|
|
58
|
-
}, /*#__PURE__*/React__default["default"].createElement(
|
|
57
|
+
}, /*#__PURE__*/React__default["default"].createElement(ButtonBase["default"], _rollupPluginBabelHelpers["extends"]({}, rest, {
|
|
59
58
|
disabled: disabled,
|
|
60
59
|
kind: kind,
|
|
61
60
|
ref: ref,
|
|
@@ -59,7 +59,7 @@ export default class ModalWrapper extends React.Component<ModalWrapperProps, Mod
|
|
|
59
59
|
shouldCloseAfterSubmit: PropTypes.Requireable<boolean>;
|
|
60
60
|
status: PropTypes.Requireable<string>;
|
|
61
61
|
triggerButtonIconDescription: PropTypes.Requireable<string>;
|
|
62
|
-
triggerButtonKind: PropTypes.Requireable<"primary" | "secondary" | "
|
|
62
|
+
triggerButtonKind: PropTypes.Requireable<"primary" | "secondary" | "danger" | "ghost" | "danger--primary" | "danger--ghost" | "danger--tertiary" | "tertiary">;
|
|
63
63
|
withHeader: PropTypes.Requireable<boolean>;
|
|
64
64
|
};
|
|
65
65
|
triggerButton: React.RefObject<HTMLButtonElement>;
|
|
@@ -14,6 +14,7 @@ var PropTypes = require('prop-types');
|
|
|
14
14
|
var React = require('react');
|
|
15
15
|
var cx = require('classnames');
|
|
16
16
|
var usePrefix = require('../../internal/usePrefix.js');
|
|
17
|
+
var useIsomorphicEffect = require('../../internal/useIsomorphicEffect.js');
|
|
17
18
|
var SliderHandles = require('./SliderHandles.js');
|
|
18
19
|
|
|
19
20
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -31,7 +32,10 @@ const SliderSkeleton = _ref => {
|
|
|
31
32
|
...rest
|
|
32
33
|
} = _ref;
|
|
33
34
|
const prefix = usePrefix.usePrefix();
|
|
34
|
-
const isRtl =
|
|
35
|
+
const [isRtl, setIsRtl] = React.useState(false);
|
|
36
|
+
useIsomorphicEffect["default"](() => {
|
|
37
|
+
setIsRtl(document ? document.dir === 'rtl' : false);
|
|
38
|
+
}, []);
|
|
35
39
|
const containerClasses = cx__default["default"](`${prefix}--slider-container`, `${prefix}--skeleton`, {
|
|
36
40
|
[`${prefix}--slider-container--two-handles`]: twoHandles,
|
|
37
41
|
[`${prefix}--slider-container--rtl`]: isRtl
|
|
@@ -144,6 +144,10 @@ export interface StructuredListRowProps extends DivAttrs {
|
|
|
144
144
|
* Provide a handler that is invoked on the key down event for the control
|
|
145
145
|
*/
|
|
146
146
|
onKeyDown?(event: KeyboardEvent): void;
|
|
147
|
+
/**
|
|
148
|
+
* Mark if this row should be selectable
|
|
149
|
+
*/
|
|
150
|
+
selection?: boolean;
|
|
147
151
|
}
|
|
148
152
|
export declare function StructuredListRow(props: StructuredListRowProps): import("react/jsx-runtime").JSX.Element;
|
|
149
153
|
export declare namespace StructuredListRow {
|
|
@@ -172,6 +176,10 @@ export declare namespace StructuredListRow {
|
|
|
172
176
|
* Provide a handler that is invoked on the key down event for the control,
|
|
173
177
|
*/
|
|
174
178
|
onKeyDown: PropTypes.Requireable<(...args: any[]) => any>;
|
|
179
|
+
/**
|
|
180
|
+
* Mark if this row should be selectable
|
|
181
|
+
*/
|
|
182
|
+
selection: PropTypes.Requireable<boolean>;
|
|
175
183
|
};
|
|
176
184
|
}
|
|
177
185
|
export interface StructuredListInputProps extends DivAttrs {
|
|
@@ -17,6 +17,8 @@ var useId = require('../../internal/useId.js');
|
|
|
17
17
|
var deprecate = require('../../prop-types/deprecate.js');
|
|
18
18
|
var usePrefix = require('../../internal/usePrefix.js');
|
|
19
19
|
require('../Text/index.js');
|
|
20
|
+
var iconsReact = require('@carbon/icons-react');
|
|
21
|
+
var useOutsideClick = require('../../internal/useOutsideClick.js');
|
|
20
22
|
var Text = require('../Text/Text.js');
|
|
21
23
|
|
|
22
24
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -25,6 +27,7 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
|
25
27
|
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
26
28
|
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
|
|
27
29
|
|
|
30
|
+
var _StructuredListCell, _RadioButtonChecked, _RadioButton;
|
|
28
31
|
const GridSelectedRowStateContext = /*#__PURE__*/React__default["default"].createContext(null);
|
|
29
32
|
const GridSelectedRowDispatchContext = /*#__PURE__*/React__default["default"].createContext(null);
|
|
30
33
|
function StructuredListWrapper(props) {
|
|
@@ -147,6 +150,7 @@ function StructuredListRow(props) {
|
|
|
147
150
|
className,
|
|
148
151
|
head,
|
|
149
152
|
onClick,
|
|
153
|
+
selection,
|
|
150
154
|
...other
|
|
151
155
|
} = props;
|
|
152
156
|
const [hasFocusWithin, setHasFocusWithin] = React.useState(false);
|
|
@@ -159,25 +163,35 @@ function StructuredListRow(props) {
|
|
|
159
163
|
};
|
|
160
164
|
const classes = cx__default["default"](`${prefix}--structured-list-row`, {
|
|
161
165
|
[`${prefix}--structured-list-row--header-row`]: head,
|
|
162
|
-
[`${prefix}--structured-list-row--focused-within`]: hasFocusWithin,
|
|
166
|
+
[`${prefix}--structured-list-row--focused-within`]: hasFocusWithin && !selection || hasFocusWithin && selection && (selectedRow === id || selectedRow === null),
|
|
167
|
+
// Ensure focus on the first item when navigating through Tab keys and no row is selected (selectedRow === null)
|
|
163
168
|
[`${prefix}--structured-list-row--selected`]: selectedRow === id
|
|
164
169
|
}, className);
|
|
170
|
+
const itemRef = React.useRef(null);
|
|
171
|
+
const handleClick = () => {
|
|
172
|
+
setHasFocusWithin(false);
|
|
173
|
+
};
|
|
174
|
+
useOutsideClick.useOutsideClick(itemRef, handleClick);
|
|
165
175
|
return head ? /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({
|
|
166
176
|
role: "row"
|
|
167
177
|
}, other, {
|
|
168
|
-
className: classes
|
|
169
|
-
|
|
170
|
-
|
|
178
|
+
className: classes
|
|
179
|
+
}), selection && (_StructuredListCell || (_StructuredListCell = /*#__PURE__*/React__default["default"].createElement(StructuredListCell, {
|
|
180
|
+
head: true
|
|
181
|
+
}))), children) :
|
|
171
182
|
/*#__PURE__*/
|
|
172
183
|
// eslint-disable-next-line jsx-a11y/interactive-supports-focus
|
|
173
|
-
React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({
|
|
174
|
-
"aria-busy": "true"
|
|
175
|
-
}, other, {
|
|
184
|
+
React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({}, other, {
|
|
176
185
|
role: "row",
|
|
177
186
|
className: classes,
|
|
187
|
+
ref: itemRef,
|
|
178
188
|
onClick: event => {
|
|
179
189
|
setSelectedRow?.(id);
|
|
180
190
|
onClick && onClick(event);
|
|
191
|
+
if (selection) {
|
|
192
|
+
// focus items only when selection is enabled
|
|
193
|
+
setHasFocusWithin(true);
|
|
194
|
+
}
|
|
181
195
|
},
|
|
182
196
|
onFocus: () => {
|
|
183
197
|
setHasFocusWithin(true);
|
|
@@ -188,7 +202,7 @@ function StructuredListRow(props) {
|
|
|
188
202
|
onKeyDown: onKeyDown
|
|
189
203
|
}), /*#__PURE__*/React__default["default"].createElement(GridRowContext.Provider, {
|
|
190
204
|
value: value
|
|
191
|
-
}, children));
|
|
205
|
+
}, selection && /*#__PURE__*/React__default["default"].createElement(StructuredListCell, null, selectedRow === id ? _RadioButtonChecked || (_RadioButtonChecked = /*#__PURE__*/React__default["default"].createElement(iconsReact.RadioButtonChecked, null)) : _RadioButton || (_RadioButton = /*#__PURE__*/React__default["default"].createElement(iconsReact.RadioButton, null))), children));
|
|
192
206
|
}
|
|
193
207
|
StructuredListRow.propTypes = {
|
|
194
208
|
/**
|
|
@@ -214,7 +228,11 @@ StructuredListRow.propTypes = {
|
|
|
214
228
|
/**
|
|
215
229
|
* Provide a handler that is invoked on the key down event for the control,
|
|
216
230
|
*/
|
|
217
|
-
onKeyDown: PropTypes__default["default"].func
|
|
231
|
+
onKeyDown: PropTypes__default["default"].func,
|
|
232
|
+
/**
|
|
233
|
+
* Mark if this row should be selectable
|
|
234
|
+
*/
|
|
235
|
+
selection: PropTypes__default["default"].bool
|
|
218
236
|
};
|
|
219
237
|
function StructuredListInput(props) {
|
|
220
238
|
const defaultId = useId.useId('structureListInput');
|
package/lib/feature-flags.js
CHANGED
|
@@ -34,5 +34,6 @@ FeatureFlags__namespace.merge({
|
|
|
34
34
|
'enable-css-grid': true,
|
|
35
35
|
'enable-v11-release': true,
|
|
36
36
|
'enable-experimental-tile-contrast': false,
|
|
37
|
-
'enable-v12-tile-radio-icons': false
|
|
37
|
+
'enable-v12-tile-radio-icons': false,
|
|
38
|
+
'enable-v12-structured-list-visible-icons': false
|
|
38
39
|
});
|
|
@@ -14,6 +14,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
14
14
|
*
|
|
15
15
|
* @see https://github.com/facebook/fbjs/blob/4d1751311d3f67af2dcce2e40df8512a23c7b9c6/packages/fbjs/src/core/ExecutionEnvironment.js#L12
|
|
16
16
|
*/
|
|
17
|
-
const canUseDOM = !!(typeof window !== 'undefined' &&
|
|
17
|
+
const canUseDOM = !!(typeof window !== 'undefined' &&
|
|
18
|
+
// eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
|
|
19
|
+
window.document &&
|
|
20
|
+
// eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
|
|
21
|
+
window.document.createElement);
|
|
18
22
|
|
|
19
23
|
exports.canUseDOM = canUseDOM;
|
|
@@ -43,7 +43,9 @@ const getNextIndex = (key, index, arrayLength) => {
|
|
|
43
43
|
*/
|
|
44
44
|
const DOCUMENT_POSITION_BROAD_PRECEDING =
|
|
45
45
|
// Checks `typeof Node` for `react-docgen`
|
|
46
|
-
typeof Node !== 'undefined' &&
|
|
46
|
+
typeof Node !== 'undefined' &&
|
|
47
|
+
// eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
|
|
48
|
+
Node.DOCUMENT_POSITION_PRECEDING | Node.DOCUMENT_POSITION_CONTAINS;
|
|
47
49
|
|
|
48
50
|
/**
|
|
49
51
|
* A flag `node.compareDocumentPosition(target)` returns,
|
|
@@ -51,7 +53,9 @@ typeof Node !== 'undefined' && Node.DOCUMENT_POSITION_PRECEDING | Node.DOCUMENT_
|
|
|
51
53
|
*/
|
|
52
54
|
const DOCUMENT_POSITION_BROAD_FOLLOWING =
|
|
53
55
|
// Checks `typeof Node` for `react-docgen`
|
|
54
|
-
typeof Node !== 'undefined' &&
|
|
56
|
+
typeof Node !== 'undefined' &&
|
|
57
|
+
// eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
|
|
58
|
+
Node.DOCUMENT_POSITION_FOLLOWING | Node.DOCUMENT_POSITION_CONTAINED_BY;
|
|
55
59
|
|
|
56
60
|
/**
|
|
57
61
|
* CSS selector that selects major nodes that are sequential-focusable.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
|
+
|
|
12
|
+
var React = require('react');
|
|
13
|
+
var useEvent = require('./useEvent.js');
|
|
14
|
+
var environment = require('./environment.js');
|
|
15
|
+
|
|
16
|
+
function useOutsideClick(ref, callback) {
|
|
17
|
+
const savedCallback = React.useRef(callback);
|
|
18
|
+
React.useEffect(() => {
|
|
19
|
+
savedCallback.current = callback;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// We conditionally guard the `useEvent` hook for SSR. `canUseDOM` can be
|
|
23
|
+
// treated as a constant as it will be false when executed in a Node.js
|
|
24
|
+
// environment and true when executed in the browser
|
|
25
|
+
if (environment.canUseDOM) {
|
|
26
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
27
|
+
useEvent.useEvent(window, 'click', event => {
|
|
28
|
+
if (ref.current && !ref.current.contains(event.target)) {
|
|
29
|
+
savedCallback.current(event);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
exports.useOutsideClick = useOutsideClick;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carbon/react",
|
|
3
3
|
"description": "React components for the Carbon Design System",
|
|
4
|
-
"version": "1.54.0
|
|
4
|
+
"version": "1.54.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "es/index.js",
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@babel/runtime": "^7.18.3",
|
|
51
|
-
"@carbon/feature-flags": "^0.19.0
|
|
52
|
-
"@carbon/icons-react": "^11.39.0
|
|
51
|
+
"@carbon/feature-flags": "^0.19.0",
|
|
52
|
+
"@carbon/icons-react": "^11.39.0",
|
|
53
53
|
"@carbon/layout": "^11.21.0",
|
|
54
|
-
"@carbon/styles": "^1.54.0
|
|
54
|
+
"@carbon/styles": "^1.54.0",
|
|
55
55
|
"@floating-ui/react": "^0.25.4",
|
|
56
56
|
"@ibm/telemetry-js": "^1.2.1",
|
|
57
57
|
"classnames": "2.5.1",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"@babel/preset-react": "^7.22.3",
|
|
82
82
|
"@babel/preset-typescript": "^7.21.5",
|
|
83
83
|
"@carbon/test-utils": "^10.30.0",
|
|
84
|
-
"@carbon/themes": "^11.34.0
|
|
84
|
+
"@carbon/themes": "^11.34.0",
|
|
85
85
|
"@rollup/plugin-babel": "^6.0.0",
|
|
86
86
|
"@rollup/plugin-commonjs": "^25.0.0",
|
|
87
87
|
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
@@ -141,5 +141,5 @@
|
|
|
141
141
|
"**/*.scss",
|
|
142
142
|
"**/*.css"
|
|
143
143
|
],
|
|
144
|
-
"gitHead": "
|
|
144
|
+
"gitHead": "4bdd6802dd612af764ef76162141333d35bd84f4"
|
|
145
145
|
}
|