@carbon/react 1.32.0 → 1.33.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/README.md +22 -7
- package/es/components/ComboBox/ComboBox.js +43 -10
- package/es/components/ContentSwitcher/ContentSwitcher.js +5 -5
- package/es/components/DataTable/DataTable.js +110 -130
- package/es/components/DataTable/Table.js +1 -1
- package/es/components/DataTableSkeleton/DataTableSkeleton.d.ts +17 -16
- package/es/components/DatePicker/DatePicker.d.ts +14 -13
- package/es/components/DatePicker/DatePicker.js +3 -0
- package/es/components/DatePickerInput/DatePickerInput.d.ts +2 -2
- package/es/components/Dropdown/Dropdown.js +31 -6
- package/es/components/FileUploader/FileUploader.Skeleton.d.ts +29 -0
- package/es/components/FileUploader/FileUploader.d.ts +175 -0
- package/es/components/FileUploader/FileUploader.js +3 -3
- package/es/components/FileUploader/FileUploaderButton.d.ts +140 -0
- package/es/components/FileUploader/FileUploaderButton.js +11 -7
- package/es/components/FileUploader/FileUploaderDropContainer.d.ts +139 -0
- package/es/components/FileUploader/FileUploaderDropContainer.js +3 -3
- package/es/components/FileUploader/FileUploaderItem.d.ts +110 -0
- package/es/components/FileUploader/Filename.d.ts +71 -0
- package/es/components/FileUploader/Filename.js +6 -4
- package/es/components/InlineCheckbox/InlineCheckbox.js +3 -1
- package/es/components/Loading/Loading.d.ts +65 -0
- package/es/components/Notification/Notification.d.ts +4 -4
- package/es/components/Notification/Notification.js +3 -3
- package/es/components/OverflowMenu/OverflowMenu.js +36 -41
- package/es/components/Slider/Slider.js +59 -68
- package/es/components/Tag/Tag.js +9 -2
- package/es/components/TextArea/TextArea.js +1 -1
- package/es/components/Toggle/Toggle.d.ts +129 -0
- package/es/components/Toggle/Toggle.js +2 -2
- package/es/components/Toggle/index.d.ts +11 -0
- package/es/components/UIShell/HeaderMenu.js +29 -36
- package/es/components/UIShell/HeaderMenuButton.d.ts +4 -0
- package/es/components/UIShell/HeaderMenuButton.js +4 -0
- package/es/components/UIShell/HeaderName.d.ts +39 -0
- package/es/components/UIShell/HeaderName.js +2 -7
- package/es/components/UIShell/HeaderPanel.js +2 -2
- package/es/components/UIShell/Link.js +2 -1
- package/es/components/UIShell/Switcher.js +17 -6
- package/es/index.js +1 -1
- package/es/internal/FloatingMenu.js +47 -51
- package/es/internal/useControllableState.js +1 -1
- package/es/internal/useId.js +10 -1
- package/lib/components/ComboBox/ComboBox.js +43 -10
- package/lib/components/ContentSwitcher/ContentSwitcher.js +5 -5
- package/lib/components/DataTable/DataTable.js +110 -130
- package/lib/components/DataTable/Table.js +1 -1
- package/lib/components/DataTableSkeleton/DataTableSkeleton.d.ts +17 -16
- package/lib/components/DatePicker/DatePicker.d.ts +14 -13
- package/lib/components/DatePicker/DatePicker.js +3 -0
- package/lib/components/DatePickerInput/DatePickerInput.d.ts +2 -2
- package/lib/components/Dropdown/Dropdown.js +30 -5
- package/lib/components/FileUploader/FileUploader.Skeleton.d.ts +29 -0
- package/lib/components/FileUploader/FileUploader.d.ts +175 -0
- package/lib/components/FileUploader/FileUploader.js +3 -3
- package/lib/components/FileUploader/FileUploaderButton.d.ts +140 -0
- package/lib/components/FileUploader/FileUploaderButton.js +11 -7
- package/lib/components/FileUploader/FileUploaderDropContainer.d.ts +139 -0
- package/lib/components/FileUploader/FileUploaderDropContainer.js +3 -3
- package/lib/components/FileUploader/FileUploaderItem.d.ts +110 -0
- package/lib/components/FileUploader/Filename.d.ts +71 -0
- package/lib/components/FileUploader/Filename.js +6 -4
- package/lib/components/InlineCheckbox/InlineCheckbox.js +3 -1
- package/lib/components/Loading/Loading.d.ts +65 -0
- package/lib/components/Notification/Notification.d.ts +4 -4
- package/lib/components/Notification/Notification.js +3 -3
- package/lib/components/OverflowMenu/OverflowMenu.js +36 -41
- package/lib/components/Slider/Slider.js +59 -68
- package/lib/components/Tag/Tag.js +9 -2
- package/lib/components/TextArea/TextArea.js +1 -1
- package/lib/components/Toggle/Toggle.d.ts +129 -0
- package/lib/components/Toggle/Toggle.js +2 -2
- package/lib/components/Toggle/index.d.ts +11 -0
- package/lib/components/UIShell/HeaderMenu.js +29 -36
- package/lib/components/UIShell/HeaderMenuButton.d.ts +4 -0
- package/lib/components/UIShell/HeaderMenuButton.js +4 -0
- package/lib/components/UIShell/HeaderName.d.ts +39 -0
- package/lib/components/UIShell/HeaderName.js +2 -7
- package/lib/components/UIShell/HeaderPanel.js +2 -2
- package/lib/components/UIShell/Link.js +2 -1
- package/lib/components/UIShell/Switcher.js +17 -6
- package/lib/index.js +2 -2
- package/lib/internal/FloatingMenu.js +47 -51
- package/lib/internal/useControllableState.js +1 -1
- package/lib/internal/useId.js +9 -0
- package/package.json +22 -19
package/es/components/Tag/Tag.js
CHANGED
|
@@ -41,6 +41,7 @@ const Tag = _ref => {
|
|
|
41
41
|
disabled,
|
|
42
42
|
onClose,
|
|
43
43
|
size,
|
|
44
|
+
as: BaseComponent,
|
|
44
45
|
...other
|
|
45
46
|
} = _ref;
|
|
46
47
|
const prefix = usePrefix();
|
|
@@ -61,7 +62,8 @@ const Tag = _ref => {
|
|
|
61
62
|
}
|
|
62
63
|
};
|
|
63
64
|
if (filter) {
|
|
64
|
-
|
|
65
|
+
const ComponentTag = BaseComponent ?? 'div';
|
|
66
|
+
return /*#__PURE__*/React__default.createElement(ComponentTag, _extends({
|
|
65
67
|
className: tagClasses,
|
|
66
68
|
id: tagId
|
|
67
69
|
}, other), /*#__PURE__*/React__default.createElement("span", {
|
|
@@ -76,7 +78,7 @@ const Tag = _ref => {
|
|
|
76
78
|
title: title
|
|
77
79
|
}, _Close || (_Close = /*#__PURE__*/React__default.createElement(Close, null))));
|
|
78
80
|
}
|
|
79
|
-
const ComponentTag = other.onClick ? 'button' : 'div';
|
|
81
|
+
const ComponentTag = BaseComponent ?? (other.onClick ? 'button' : 'div');
|
|
80
82
|
return /*#__PURE__*/React__default.createElement(ComponentTag, _extends({
|
|
81
83
|
disabled: ComponentTag === 'button' ? disabled : null,
|
|
82
84
|
className: tagClasses,
|
|
@@ -88,6 +90,11 @@ const Tag = _ref => {
|
|
|
88
90
|
}, children !== null && children !== undefined ? children : TYPES[type]));
|
|
89
91
|
};
|
|
90
92
|
Tag.propTypes = {
|
|
93
|
+
/**
|
|
94
|
+
* Provide an alternative tag or component to use instead of the default
|
|
95
|
+
* wrapping element
|
|
96
|
+
*/
|
|
97
|
+
as: PropTypes.elementType,
|
|
91
98
|
/**
|
|
92
99
|
* Provide content to be rendered inside of a <Tag>
|
|
93
100
|
*/
|
|
@@ -61,7 +61,7 @@ const TextArea = /*#__PURE__*/React__default.forwardRef((props, forwardRef) => {
|
|
|
61
61
|
if (!other.disabled && onChange) {
|
|
62
62
|
// delay textCount assignation to give the textarea element value time to catch up if is a controlled input
|
|
63
63
|
setTimeout(() => {
|
|
64
|
-
setTextCount(evt.target
|
|
64
|
+
setTextCount(evt.target?.value?.length);
|
|
65
65
|
}, 0);
|
|
66
66
|
onChange(evt);
|
|
67
67
|
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2021, 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, { KeyboardEventHandler, MouseEventHandler } from 'react';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
type ExcludedAttributes = 'aria-labelledby' | 'aria-checked' | 'type' | 'role' | 'id' | 'size' | 'onClick';
|
|
10
|
+
export interface ToggleProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, ExcludedAttributes> {
|
|
11
|
+
/**
|
|
12
|
+
* Specify another element's id to be used as the label for this toggle
|
|
13
|
+
*/
|
|
14
|
+
'aria-labelledby'?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Provide an id that unique represents the underlying `<button>`
|
|
17
|
+
*/
|
|
18
|
+
id: string;
|
|
19
|
+
/**
|
|
20
|
+
* Specify the label for the "off" position
|
|
21
|
+
*/
|
|
22
|
+
labelA?: string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Specify the label for the "on" position
|
|
25
|
+
*/
|
|
26
|
+
labelB?: string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Provide the text that will be read by a screen reader when visiting this
|
|
29
|
+
* control. This should be provided unless 'aria-labelledby' is set instead
|
|
30
|
+
* or you use an external <label> element with its "for" attribute set to the
|
|
31
|
+
* toggle's id.
|
|
32
|
+
*/
|
|
33
|
+
labelText?: string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* If true, the side labels (props.labelA and props.labelB) will be replaced by
|
|
36
|
+
* props.labelText (if passed), so that the toggle doesn't render a top label.
|
|
37
|
+
*/
|
|
38
|
+
hideLabel?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Provide an event listener that is called when the control is toggled
|
|
41
|
+
*/
|
|
42
|
+
onClick: MouseEventHandler<HTMLDivElement> | KeyboardEventHandler<HTMLDivElement> | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Provide an event listener that is called when the control is toggled
|
|
45
|
+
*/
|
|
46
|
+
onToggle?(checked: boolean): void;
|
|
47
|
+
/**
|
|
48
|
+
* Specify the size of the Toggle. Currently only supports 'sm' or 'md' (default)
|
|
49
|
+
*/
|
|
50
|
+
size?: 'sm' | 'md' | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Whether the toggle should be read-only
|
|
53
|
+
*/
|
|
54
|
+
readOnly?: boolean | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Specify whether the toggle should be on by default
|
|
57
|
+
*/
|
|
58
|
+
defaultToggled?: boolean | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Specify whether the control is toggled
|
|
61
|
+
*/
|
|
62
|
+
toggled?: boolean | undefined;
|
|
63
|
+
}
|
|
64
|
+
export declare function Toggle({ 'aria-labelledby': ariaLabelledby, className, defaultToggled, disabled, hideLabel, id, labelA, labelB, labelText, onClick, onToggle, readOnly, size, toggled, ...other }: ToggleProps): JSX.Element;
|
|
65
|
+
export declare namespace Toggle {
|
|
66
|
+
var propTypes: {
|
|
67
|
+
/**
|
|
68
|
+
* Specify another element's id to be used as the label for this toggle
|
|
69
|
+
*/
|
|
70
|
+
'aria-labelledby': PropTypes.Requireable<string>;
|
|
71
|
+
/**
|
|
72
|
+
* Specify a custom className to apply to the form-item node
|
|
73
|
+
*/
|
|
74
|
+
className: PropTypes.Requireable<string>;
|
|
75
|
+
/**
|
|
76
|
+
* Specify whether the toggle should be on by default
|
|
77
|
+
*/
|
|
78
|
+
defaultToggled: PropTypes.Requireable<boolean>;
|
|
79
|
+
/**
|
|
80
|
+
* Whether this control should be disabled
|
|
81
|
+
*/
|
|
82
|
+
disabled: PropTypes.Requireable<boolean>;
|
|
83
|
+
/**
|
|
84
|
+
* If true, the side labels (props.labelA and props.labelB) will be replaced by
|
|
85
|
+
* props.labelText (if passed), so that the toggle doesn't render a top label.
|
|
86
|
+
*/
|
|
87
|
+
hideLabel: PropTypes.Requireable<boolean>;
|
|
88
|
+
/**
|
|
89
|
+
* Provide an id that unique represents the underlying `<button>`
|
|
90
|
+
*/
|
|
91
|
+
id: PropTypes.Validator<string>;
|
|
92
|
+
/**
|
|
93
|
+
* Specify the label for the "off" position
|
|
94
|
+
*/
|
|
95
|
+
labelA: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
96
|
+
/**
|
|
97
|
+
* Specify the label for the "on" position
|
|
98
|
+
*/
|
|
99
|
+
labelB: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
100
|
+
/**
|
|
101
|
+
* Provide the text that will be read by a screen reader when visiting this
|
|
102
|
+
* control. This should be provided unless 'aria-labelledby' is set instead
|
|
103
|
+
* or you use an external <label> element with its "for" attribute set to the
|
|
104
|
+
* toggle's id.
|
|
105
|
+
*/
|
|
106
|
+
labelText: PropTypes.Requireable<string>;
|
|
107
|
+
/**
|
|
108
|
+
* Provide an event listener that is called when the control is clicked
|
|
109
|
+
*/
|
|
110
|
+
onClick: PropTypes.Requireable<(...args: any[]) => any>;
|
|
111
|
+
/**
|
|
112
|
+
* Provide an event listener that is called when the control is toggled
|
|
113
|
+
*/
|
|
114
|
+
onToggle: PropTypes.Requireable<(...args: any[]) => any>;
|
|
115
|
+
/**
|
|
116
|
+
* Whether the toggle should be read-only
|
|
117
|
+
*/
|
|
118
|
+
readOnly: PropTypes.Requireable<boolean>;
|
|
119
|
+
/**
|
|
120
|
+
* Specify the size of the Toggle. Currently only supports 'sm' or 'md' (default)
|
|
121
|
+
*/
|
|
122
|
+
size: PropTypes.Requireable<string>;
|
|
123
|
+
/**
|
|
124
|
+
* Specify whether the control is toggled
|
|
125
|
+
*/
|
|
126
|
+
toggled: PropTypes.Requireable<boolean>;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
export default Toggle;
|
|
@@ -78,7 +78,7 @@ function Toggle(_ref) {
|
|
|
78
78
|
handleClick(e);
|
|
79
79
|
buttonElement.current.focus();
|
|
80
80
|
}
|
|
81
|
-
} :
|
|
81
|
+
} : undefined
|
|
82
82
|
}, /*#__PURE__*/React__default.createElement("button", _extends({}, other, {
|
|
83
83
|
ref: buttonElement,
|
|
84
84
|
id: id,
|
|
@@ -90,7 +90,7 @@ function Toggle(_ref) {
|
|
|
90
90
|
disabled: disabled,
|
|
91
91
|
onClick: handleClick
|
|
92
92
|
})), /*#__PURE__*/React__default.createElement(LabelComponent, {
|
|
93
|
-
htmlFor: ariaLabelledby ?
|
|
93
|
+
htmlFor: ariaLabelledby ? undefined : id,
|
|
94
94
|
className: `${prefix}--toggle__label`
|
|
95
95
|
}, labelText && /*#__PURE__*/React__default.createElement("span", {
|
|
96
96
|
className: labelTextClasses
|
|
@@ -0,0 +1,11 @@
|
|
|
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 { default as Toggle, ToggleProps } from './Toggle';
|
|
8
|
+
export * from './Toggle.Skeleton';
|
|
9
|
+
export default Toggle;
|
|
10
|
+
export { Toggle };
|
|
11
|
+
export type { ToggleProps };
|
|
@@ -26,6 +26,9 @@ class HeaderMenu extends React__default.Component {
|
|
|
26
26
|
constructor(props) {
|
|
27
27
|
super(props);
|
|
28
28
|
_defineProperty(this, "_subMenus", /*#__PURE__*/React__default.createRef());
|
|
29
|
+
/**
|
|
30
|
+
* Toggle the expanded state of the menu on click.
|
|
31
|
+
*/
|
|
29
32
|
_defineProperty(this, "handleOnClick", e => {
|
|
30
33
|
const {
|
|
31
34
|
current: subMenusNode
|
|
@@ -37,6 +40,9 @@ class HeaderMenu extends React__default.Component {
|
|
|
37
40
|
expanded: !prevState.expanded
|
|
38
41
|
}));
|
|
39
42
|
});
|
|
43
|
+
/**
|
|
44
|
+
* Keyboard event handler for the entire menu.
|
|
45
|
+
*/
|
|
40
46
|
_defineProperty(this, "handleOnKeyDown", event => {
|
|
41
47
|
// Handle enter or space key for toggling the expanded state of the menu.
|
|
42
48
|
if (matches(event, [Enter, Space])) {
|
|
@@ -48,6 +54,11 @@ class HeaderMenu extends React__default.Component {
|
|
|
48
54
|
return;
|
|
49
55
|
}
|
|
50
56
|
});
|
|
57
|
+
/**
|
|
58
|
+
* Handle our blur event from our underlying menuitems. Will mostly be used
|
|
59
|
+
* for toggling the expansion status of our menu in response to a user
|
|
60
|
+
* clicking off of the menu or menubar.
|
|
61
|
+
*/
|
|
51
62
|
_defineProperty(this, "handleOnBlur", event => {
|
|
52
63
|
// Rough guess for a blur event that is triggered outside of our menu or
|
|
53
64
|
// menubar context
|
|
@@ -60,12 +71,24 @@ class HeaderMenu extends React__default.Component {
|
|
|
60
71
|
selectedIndex: null
|
|
61
72
|
});
|
|
62
73
|
});
|
|
74
|
+
/**
|
|
75
|
+
* ref handler for our menu button. If we are supplied a `focusRef` prop, we also
|
|
76
|
+
* forward along the node.
|
|
77
|
+
*
|
|
78
|
+
* This is useful when this component is a child in a
|
|
79
|
+
* menu or menubar as it will allow the parent to explicitly focus the menu
|
|
80
|
+
* button node when that child should receive focus.
|
|
81
|
+
*/
|
|
63
82
|
_defineProperty(this, "handleMenuButtonRef", node => {
|
|
64
83
|
if (this.props.focusRef) {
|
|
65
84
|
this.props.focusRef(node);
|
|
66
85
|
}
|
|
67
86
|
this.menuButtonRef = node;
|
|
68
87
|
});
|
|
88
|
+
/**
|
|
89
|
+
* Handles individual menuitem refs. We assign them to a class instance
|
|
90
|
+
* property so that we can properly manage focus of our children.
|
|
91
|
+
*/
|
|
69
92
|
_defineProperty(this, "handleItemRef", index => node => {
|
|
70
93
|
this.items[index] = node;
|
|
71
94
|
});
|
|
@@ -84,6 +107,12 @@ class HeaderMenu extends React__default.Component {
|
|
|
84
107
|
return;
|
|
85
108
|
}
|
|
86
109
|
});
|
|
110
|
+
/**
|
|
111
|
+
* We capture the `ref` for each child inside of `this.items` to properly
|
|
112
|
+
* manage focus. In addition to this focus management, all items receive a
|
|
113
|
+
* `tabIndex: -1` so the user won't hit a large number of items in their tab
|
|
114
|
+
* sequence when they might not want to go through all the items.
|
|
115
|
+
*/
|
|
87
116
|
_defineProperty(this, "_renderMenuItem", (item, index) => {
|
|
88
117
|
if ( /*#__PURE__*/React__default.isValidElement(item)) {
|
|
89
118
|
return /*#__PURE__*/React__default.cloneElement(item, {
|
|
@@ -100,35 +129,6 @@ class HeaderMenu extends React__default.Component {
|
|
|
100
129
|
};
|
|
101
130
|
this.items = [];
|
|
102
131
|
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Toggle the expanded state of the menu on click.
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Keyboard event handler for the entire menu.
|
|
110
|
-
*/
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Handle our blur event from our underlying menuitems. Will mostly be used
|
|
114
|
-
* for toggling the expansion status of our menu in response to a user
|
|
115
|
-
* clicking off of the menu or menubar.
|
|
116
|
-
*/
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* ref handler for our menu button. If we are supplied a `focusRef` prop, we also
|
|
120
|
-
* forward along the node.
|
|
121
|
-
*
|
|
122
|
-
* This is useful when this component is a child in a
|
|
123
|
-
* menu or menubar as it will allow the parent to explicitly focus the menu
|
|
124
|
-
* button node when that child should receive focus.
|
|
125
|
-
*/
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Handles individual menuitem refs. We assign them to a class instance
|
|
129
|
-
* property so that we can properly manage focus of our children.
|
|
130
|
-
*/
|
|
131
|
-
|
|
132
132
|
render() {
|
|
133
133
|
const prefix = this.context;
|
|
134
134
|
const {
|
|
@@ -191,13 +191,6 @@ class HeaderMenu extends React__default.Component {
|
|
|
191
191
|
className: `${prefix}--header__menu`
|
|
192
192
|
}), React__default.Children.map(children, this._renderMenuItem)));
|
|
193
193
|
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* We capture the `ref` for each child inside of `this.items` to properly
|
|
197
|
-
* manage focus. In addition to this focus management, all items receive a
|
|
198
|
-
* `tabIndex: -1` so the user won't hit a large number of items in their tab
|
|
199
|
-
* sequence when they might not want to go through all the items.
|
|
200
|
-
*/
|
|
201
194
|
}
|
|
202
195
|
_defineProperty(HeaderMenu, "propTypes", {
|
|
203
196
|
/**
|
|
@@ -28,6 +28,10 @@ declare namespace HeaderMenuButton {
|
|
|
28
28
|
* Specify whether the menu button is "active".
|
|
29
29
|
*/
|
|
30
30
|
isActive: PropTypes.Requireable<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Specify whether the menu button is collapsible.
|
|
33
|
+
*/
|
|
34
|
+
isCollapsible: PropTypes.Requireable<boolean>;
|
|
31
35
|
/**
|
|
32
36
|
* Optionally provide an onClick handler that is called when the underlying
|
|
33
37
|
* button fires it's onclick event
|
|
@@ -64,6 +64,10 @@ HeaderMenuButton.propTypes = {
|
|
|
64
64
|
* Specify whether the menu button is "active".
|
|
65
65
|
*/
|
|
66
66
|
isActive: PropTypes.bool,
|
|
67
|
+
/**
|
|
68
|
+
* Specify whether the menu button is collapsible.
|
|
69
|
+
*/
|
|
70
|
+
isCollapsible: PropTypes.bool,
|
|
67
71
|
/**
|
|
68
72
|
* Optionally provide an onClick handler that is called when the underlying
|
|
69
73
|
* button fires it's onclick event
|
|
@@ -0,0 +1,39 @@
|
|
|
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 { type ElementType } from 'react';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import { type LinkProps } from './Link';
|
|
10
|
+
type HeaderNameProps<E extends ElementType> = LinkProps<E> & {
|
|
11
|
+
prefix?: string | undefined;
|
|
12
|
+
};
|
|
13
|
+
declare function HeaderName<E extends ElementType = 'a'>({ children, className: customClassName, prefix, ...rest }: HeaderNameProps<E>): JSX.Element;
|
|
14
|
+
declare namespace HeaderName {
|
|
15
|
+
var propTypes: {
|
|
16
|
+
/**
|
|
17
|
+
* Pass in children that are either a string or can be read as a string by
|
|
18
|
+
* screen readers
|
|
19
|
+
*/
|
|
20
|
+
children: PropTypes.Validator<NonNullable<PropTypes.ReactNodeLike>>;
|
|
21
|
+
/**
|
|
22
|
+
* Optionally provide a custom class to apply to the underlying `<li>` node
|
|
23
|
+
*/
|
|
24
|
+
className: PropTypes.Requireable<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Provide an href for the name to link to
|
|
27
|
+
*/
|
|
28
|
+
href: PropTypes.Requireable<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Optionally specify a prefix to your header name. Useful for companies, for
|
|
31
|
+
* example: IBM [Product Name] versus solely [Product Name]
|
|
32
|
+
*/
|
|
33
|
+
prefix: PropTypes.Requireable<string>;
|
|
34
|
+
as: PropTypes.Requireable<PropTypes.ReactComponentLike>;
|
|
35
|
+
element: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
|
|
36
|
+
isSideNavExpanded: PropTypes.Requireable<boolean>;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export default HeaderName;
|
|
@@ -16,15 +16,13 @@ function HeaderName(_ref) {
|
|
|
16
16
|
let {
|
|
17
17
|
children,
|
|
18
18
|
className: customClassName,
|
|
19
|
-
prefix,
|
|
20
|
-
href,
|
|
19
|
+
prefix = 'IBM',
|
|
21
20
|
...rest
|
|
22
21
|
} = _ref;
|
|
23
22
|
const selectorPrefix = usePrefix();
|
|
24
23
|
const className = cx(`${selectorPrefix}--header__name`, customClassName);
|
|
25
24
|
return /*#__PURE__*/React__default.createElement(Link, _extends({}, rest, {
|
|
26
|
-
className: className
|
|
27
|
-
href: href
|
|
25
|
+
className: className
|
|
28
26
|
}), prefix && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("span", {
|
|
29
27
|
className: `${selectorPrefix}--header__name--prefix`
|
|
30
28
|
}, prefix), "\xA0"), children);
|
|
@@ -54,8 +52,5 @@ HeaderName.propTypes = {
|
|
|
54
52
|
*/
|
|
55
53
|
prefix: PropTypes.string
|
|
56
54
|
};
|
|
57
|
-
HeaderName.defaultProps = {
|
|
58
|
-
prefix: 'IBM'
|
|
59
|
-
};
|
|
60
55
|
|
|
61
56
|
export { HeaderName as default };
|
|
@@ -39,7 +39,7 @@ const HeaderPanel = /*#__PURE__*/React__default.forwardRef(function HeaderPanel(
|
|
|
39
39
|
const eventHandlers = {};
|
|
40
40
|
if (addFocusListeners) {
|
|
41
41
|
eventHandlers.onBlur = event => {
|
|
42
|
-
if (!event.currentTarget.contains(event.relatedTarget) && !lastClickedElement
|
|
42
|
+
if (!event.currentTarget.contains(event.relatedTarget) && !lastClickedElement?.classList?.contains('cds--switcher__item-link')) {
|
|
43
43
|
setExpandedState(false);
|
|
44
44
|
setLastClickedElement(null);
|
|
45
45
|
if (expanded) {
|
|
@@ -60,7 +60,7 @@ const HeaderPanel = /*#__PURE__*/React__default.forwardRef(function HeaderPanel(
|
|
|
60
60
|
useWindowEvent('click', () => {
|
|
61
61
|
const focusedElement = document.activeElement;
|
|
62
62
|
setLastClickedElement(focusedElement);
|
|
63
|
-
if (children.type
|
|
63
|
+
if (children.type?.displayName === 'Switcher' && !focusedElement?.closest(`.${prefix}--header-panel--expanded`) && !focusedElement?.closest(`.${prefix}--header__action`) && !headerPanelRef?.current?.classList.contains(`${prefix}--switcher`) && expanded) {
|
|
64
64
|
setExpandedState(false);
|
|
65
65
|
onHeaderPanelFocus();
|
|
66
66
|
}
|
|
@@ -57,12 +57,23 @@ const Switcher = /*#__PURE__*/React__default.forwardRef(function Switcher(props,
|
|
|
57
57
|
const switcherItem = switcherRef.current.children[nextValidIndex].children[0];
|
|
58
58
|
switcherItem?.focus();
|
|
59
59
|
};
|
|
60
|
-
const childrenWithProps = React__default.Children.toArray(children).map((child, index) =>
|
|
61
|
-
handleSwitcherItemFocus
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
const childrenWithProps = React__default.Children.toArray(children).map((child, index) => {
|
|
61
|
+
// handleSwitcherItemFocus should only be passed down if the child is a SwitcherItem
|
|
62
|
+
// SwitcherDivider, for example, does not accept a handleSwitcherItemFocus prop
|
|
63
|
+
if (child.type?.displayName === 'SwitcherItem') {
|
|
64
|
+
return /*#__PURE__*/React__default.cloneElement(child, {
|
|
65
|
+
handleSwitcherItemFocus,
|
|
66
|
+
index,
|
|
67
|
+
key: index,
|
|
68
|
+
expanded
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return /*#__PURE__*/React__default.cloneElement(child, {
|
|
72
|
+
index,
|
|
73
|
+
key: index,
|
|
74
|
+
expanded
|
|
75
|
+
});
|
|
76
|
+
});
|
|
66
77
|
return /*#__PURE__*/React__default.createElement("ul", _extends({
|
|
67
78
|
ref: ref,
|
|
68
79
|
className: className
|
package/es/index.js
CHANGED
|
@@ -59,6 +59,7 @@ export { default as TextAreaSkeleton } from './components/TextArea/TextArea.Skel
|
|
|
59
59
|
import './components/TextInput/index.js';
|
|
60
60
|
export { ClickableTile, ExpandableTile, SelectableTile, Tile, TileAboveTheFoldContent, TileBelowTheFoldContent } from './components/Tile/Tile.js';
|
|
61
61
|
export { default as TileGroup } from './components/TileGroup/index.js';
|
|
62
|
+
export { Toggle } from './components/Toggle/Toggle.js';
|
|
62
63
|
export { default as ToggleSkeleton } from './components/Toggle/Toggle.Skeleton.js';
|
|
63
64
|
export { default as ToggleSmallSkeleton } from './components/ToggleSmall/ToggleSmall.Skeleton.js';
|
|
64
65
|
export { Toggletip, ToggletipActions, ToggletipButton, ToggletipContent, ToggletipLabel } from './components/Toggletip/index.js';
|
|
@@ -110,7 +111,6 @@ export { default as NumberInputSkeleton } from './components/NumberInput/NumberI
|
|
|
110
111
|
export { default as ProgressIndicatorSkeleton } from './components/ProgressIndicator/ProgressIndicator.Skeleton.js';
|
|
111
112
|
export { default as TextInputSkeleton } from './components/TextInput/TextInput.Skeleton.js';
|
|
112
113
|
export { default as TextInput } from './components/TextInput/TextInput.js';
|
|
113
|
-
export { Toggle } from './components/Toggle/Toggle.js';
|
|
114
114
|
export { default as TreeNode } from './components/TreeView/TreeNode.js';
|
|
115
115
|
export { default as TreeView } from './components/TreeView/TreeView.js';
|
|
116
116
|
export { default as HeaderContainer } from './components/UIShell/HeaderContainer.js';
|
|
@@ -142,6 +142,7 @@ class FloatingMenu extends React__default.Component {
|
|
|
142
142
|
var _this;
|
|
143
143
|
super(...arguments);
|
|
144
144
|
_this = this;
|
|
145
|
+
// `true` if the menu body is mounted and calculation of the position is in progress.
|
|
145
146
|
_defineProperty(this, "_placeInProgress", false);
|
|
146
147
|
_defineProperty(this, "state", {
|
|
147
148
|
/**
|
|
@@ -150,10 +151,36 @@ class FloatingMenu extends React__default.Component {
|
|
|
150
151
|
*/
|
|
151
152
|
floatingPosition: undefined
|
|
152
153
|
});
|
|
154
|
+
/**
|
|
155
|
+
* The cached reference to the menu container.
|
|
156
|
+
* Only used if React portal API is not available.
|
|
157
|
+
* @type {Element}
|
|
158
|
+
* @private
|
|
159
|
+
*/
|
|
153
160
|
_defineProperty(this, "_menuContainer", null);
|
|
161
|
+
/**
|
|
162
|
+
* The cached reference to the menu body.
|
|
163
|
+
* The reference is set via callback ref instead of object ref,
|
|
164
|
+
* in order to hook the event when the element ref gets available,
|
|
165
|
+
* which can be at a different timing from `cDM()`, presumably with SSR scenario.
|
|
166
|
+
* @type {Element}
|
|
167
|
+
* @private
|
|
168
|
+
*/
|
|
154
169
|
_defineProperty(this, "_menuBody", null);
|
|
170
|
+
/**
|
|
171
|
+
* Focus sentinel refs for focus trap behavior
|
|
172
|
+
*/
|
|
155
173
|
_defineProperty(this, "startSentinel", /*#__PURE__*/React__default.createRef());
|
|
156
174
|
_defineProperty(this, "endSentinel", /*#__PURE__*/React__default.createRef());
|
|
175
|
+
/**
|
|
176
|
+
* Calculates the position in the viewport of floating menu,
|
|
177
|
+
* once this component is mounted or updated upon change in the following props:
|
|
178
|
+
*
|
|
179
|
+
* * `menuOffset` (The adjustment that should be applied to the calculated floating menu's position)
|
|
180
|
+
* * `menuDirection` (Where the floating menu menu should be placed relative to the trigger button)
|
|
181
|
+
*
|
|
182
|
+
* @private
|
|
183
|
+
*/
|
|
157
184
|
_defineProperty(this, "_updateMenuSize", function () {
|
|
158
185
|
let prevProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
159
186
|
let isAdjustment = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
@@ -227,6 +254,11 @@ class FloatingMenu extends React__default.Component {
|
|
|
227
254
|
}
|
|
228
255
|
}
|
|
229
256
|
});
|
|
257
|
+
/**
|
|
258
|
+
* Set focus on floating menu content after menu placement.
|
|
259
|
+
* @param {Element} menuBody The DOM element of the menu body.
|
|
260
|
+
* @private
|
|
261
|
+
*/
|
|
230
262
|
_defineProperty(this, "_focusMenuContent", menuBody => {
|
|
231
263
|
const primaryFocusNode = menuBody.querySelector(this.props.selectorPrimaryFocus || null);
|
|
232
264
|
const tabbableNode = menuBody.querySelector(selectorTabbable);
|
|
@@ -243,6 +275,10 @@ class FloatingMenu extends React__default.Component {
|
|
|
243
275
|
process.env.NODE_ENV !== "production" ? warning(focusableNode === null, 'Floating Menus must have at least a programmatically focusable child. ' + 'This can be accomplished by adding tabIndex="-1" to the content element.') : void 0;
|
|
244
276
|
}
|
|
245
277
|
});
|
|
278
|
+
/**
|
|
279
|
+
* A callback for called when menu body is mounted or unmounted.
|
|
280
|
+
* @param {Element} menuBody The menu body being mounted. `null` if the menu body is being unmounted.
|
|
281
|
+
*/
|
|
246
282
|
_defineProperty(this, "_menuRef", menuBody => {
|
|
247
283
|
const {
|
|
248
284
|
menuRef
|
|
@@ -253,6 +289,10 @@ class FloatingMenu extends React__default.Component {
|
|
|
253
289
|
this._updateMenuSize();
|
|
254
290
|
}
|
|
255
291
|
});
|
|
292
|
+
/**
|
|
293
|
+
* @returns The child nodes, with styles containing the floating menu position.
|
|
294
|
+
* @private
|
|
295
|
+
*/
|
|
256
296
|
_defineProperty(this, "_getChildrenWithProps", () => {
|
|
257
297
|
const {
|
|
258
298
|
styles,
|
|
@@ -281,6 +321,12 @@ class FloatingMenu extends React__default.Component {
|
|
|
281
321
|
}
|
|
282
322
|
});
|
|
283
323
|
});
|
|
324
|
+
/**
|
|
325
|
+
* Blur handler for when focus wrap behavior is enabled
|
|
326
|
+
* @param {Event} event
|
|
327
|
+
* @param {Element} event.target previously focused node
|
|
328
|
+
* @param {Element} event.relatedTarget current focused node
|
|
329
|
+
*/
|
|
284
330
|
_defineProperty(this, "handleBlur", _ref2 => {
|
|
285
331
|
let {
|
|
286
332
|
target: oldActiveNode,
|
|
@@ -302,33 +348,7 @@ class FloatingMenu extends React__default.Component {
|
|
|
302
348
|
});
|
|
303
349
|
}
|
|
304
350
|
});
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* The cached reference to the menu container.
|
|
308
|
-
* Only used if React portal API is not available.
|
|
309
|
-
* @type {Element}
|
|
310
|
-
* @private
|
|
311
|
-
*/
|
|
312
|
-
/**
|
|
313
|
-
* The cached reference to the menu body.
|
|
314
|
-
* The reference is set via callback ref instead of object ref,
|
|
315
|
-
* in order to hook the event when the element ref gets available,
|
|
316
|
-
* which can be at a different timing from `cDM()`, presumably with SSR scenario.
|
|
317
|
-
* @type {Element}
|
|
318
|
-
* @private
|
|
319
|
-
*/
|
|
320
|
-
/**
|
|
321
|
-
* Focus sentinel refs for focus trap behavior
|
|
322
|
-
*/
|
|
323
|
-
/**
|
|
324
|
-
* Calculates the position in the viewport of floating menu,
|
|
325
|
-
* once this component is mounted or updated upon change in the following props:
|
|
326
|
-
*
|
|
327
|
-
* * `menuOffset` (The adjustment that should be applied to the calculated floating menu's position)
|
|
328
|
-
* * `menuDirection` (Where the floating menu menu should be placed relative to the trigger button)
|
|
329
|
-
*
|
|
330
|
-
* @private
|
|
331
|
-
*/
|
|
351
|
+
}
|
|
332
352
|
componentWillUnmount() {
|
|
333
353
|
this.hResize.release();
|
|
334
354
|
}
|
|
@@ -337,12 +357,6 @@ class FloatingMenu extends React__default.Component {
|
|
|
337
357
|
this._updateMenuSize();
|
|
338
358
|
});
|
|
339
359
|
}
|
|
340
|
-
/**
|
|
341
|
-
* Set focus on floating menu content after menu placement.
|
|
342
|
-
* @param {Element} menuBody The DOM element of the menu body.
|
|
343
|
-
* @private
|
|
344
|
-
*/
|
|
345
|
-
|
|
346
360
|
componentDidUpdate(prevProps) {
|
|
347
361
|
this._updateMenuSize(prevProps);
|
|
348
362
|
const {
|
|
@@ -358,24 +372,6 @@ class FloatingMenu extends React__default.Component {
|
|
|
358
372
|
}
|
|
359
373
|
}
|
|
360
374
|
}
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* A callback for called when menu body is mounted or unmounted.
|
|
364
|
-
* @param {Element} menuBody The menu body being mounted. `null` if the menu body is being unmounted.
|
|
365
|
-
*/
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* @returns The child nodes, with styles containing the floating menu position.
|
|
369
|
-
* @private
|
|
370
|
-
*/
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* Blur handler for when focus wrap behavior is enabled
|
|
374
|
-
* @param {Event} event
|
|
375
|
-
* @param {Element} event.target previously focused node
|
|
376
|
-
* @param {Element} event.relatedTarget current focused node
|
|
377
|
-
*/
|
|
378
|
-
|
|
379
375
|
render() {
|
|
380
376
|
const {
|
|
381
377
|
context: prefix
|
|
@@ -22,7 +22,7 @@ import { warning } from './warning.js';
|
|
|
22
22
|
* @param {string} [config.name] - the name of the custom component
|
|
23
23
|
* @param {any} config.defaultValue - the default value used for the state. This will be
|
|
24
24
|
* the fallback value used if `value` is not defined.
|
|
25
|
-
* @param {Function} config.onChange - an optional function that is called when
|
|
25
|
+
* @param {Function|undefined} config.onChange - an optional function that is called when
|
|
26
26
|
* the value of the state changes. This is useful for communicating to parents of
|
|
27
27
|
* controlled components that the value is requesting to be changed.
|
|
28
28
|
* @param {any} config.value - a controlled value. Omitting this means that the state is
|