@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
|
@@ -51,6 +51,7 @@ const Tag = _ref => {
|
|
|
51
51
|
disabled,
|
|
52
52
|
onClose,
|
|
53
53
|
size,
|
|
54
|
+
as: BaseComponent,
|
|
54
55
|
...other
|
|
55
56
|
} = _ref;
|
|
56
57
|
const prefix = usePrefix.usePrefix();
|
|
@@ -71,7 +72,8 @@ const Tag = _ref => {
|
|
|
71
72
|
}
|
|
72
73
|
};
|
|
73
74
|
if (filter) {
|
|
74
|
-
|
|
75
|
+
const ComponentTag = BaseComponent ?? 'div';
|
|
76
|
+
return /*#__PURE__*/React__default["default"].createElement(ComponentTag, _rollupPluginBabelHelpers["extends"]({
|
|
75
77
|
className: tagClasses,
|
|
76
78
|
id: tagId
|
|
77
79
|
}, other), /*#__PURE__*/React__default["default"].createElement("span", {
|
|
@@ -86,7 +88,7 @@ const Tag = _ref => {
|
|
|
86
88
|
title: title
|
|
87
89
|
}, _Close || (_Close = /*#__PURE__*/React__default["default"].createElement(iconsReact.Close, null))));
|
|
88
90
|
}
|
|
89
|
-
const ComponentTag = other.onClick ? 'button' : 'div';
|
|
91
|
+
const ComponentTag = BaseComponent ?? (other.onClick ? 'button' : 'div');
|
|
90
92
|
return /*#__PURE__*/React__default["default"].createElement(ComponentTag, _rollupPluginBabelHelpers["extends"]({
|
|
91
93
|
disabled: ComponentTag === 'button' ? disabled : null,
|
|
92
94
|
className: tagClasses,
|
|
@@ -98,6 +100,11 @@ const Tag = _ref => {
|
|
|
98
100
|
}, children !== null && children !== undefined ? children : TYPES[type]));
|
|
99
101
|
};
|
|
100
102
|
Tag.propTypes = {
|
|
103
|
+
/**
|
|
104
|
+
* Provide an alternative tag or component to use instead of the default
|
|
105
|
+
* wrapping element
|
|
106
|
+
*/
|
|
107
|
+
as: PropTypes__default["default"].elementType,
|
|
101
108
|
/**
|
|
102
109
|
* Provide content to be rendered inside of a <Tag>
|
|
103
110
|
*/
|
|
@@ -71,7 +71,7 @@ const TextArea = /*#__PURE__*/React__default["default"].forwardRef((props, forwa
|
|
|
71
71
|
if (!other.disabled && onChange) {
|
|
72
72
|
// delay textCount assignation to give the textarea element value time to catch up if is a controlled input
|
|
73
73
|
setTimeout(() => {
|
|
74
|
-
setTextCount(evt.target
|
|
74
|
+
setTextCount(evt.target?.value?.length);
|
|
75
75
|
}, 0);
|
|
76
76
|
onChange(evt);
|
|
77
77
|
}
|
|
@@ -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;
|
|
@@ -88,7 +88,7 @@ function Toggle(_ref) {
|
|
|
88
88
|
handleClick(e);
|
|
89
89
|
buttonElement.current.focus();
|
|
90
90
|
}
|
|
91
|
-
} :
|
|
91
|
+
} : undefined
|
|
92
92
|
}, /*#__PURE__*/React__default["default"].createElement("button", _rollupPluginBabelHelpers["extends"]({}, other, {
|
|
93
93
|
ref: buttonElement,
|
|
94
94
|
id: id,
|
|
@@ -100,7 +100,7 @@ function Toggle(_ref) {
|
|
|
100
100
|
disabled: disabled,
|
|
101
101
|
onClick: handleClick
|
|
102
102
|
})), /*#__PURE__*/React__default["default"].createElement(LabelComponent, {
|
|
103
|
-
htmlFor: ariaLabelledby ?
|
|
103
|
+
htmlFor: ariaLabelledby ? undefined : id,
|
|
104
104
|
className: `${prefix}--toggle__label`
|
|
105
105
|
}, labelText && /*#__PURE__*/React__default["default"].createElement("span", {
|
|
106
106
|
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 };
|
|
@@ -36,6 +36,9 @@ class HeaderMenu extends React__default["default"].Component {
|
|
|
36
36
|
constructor(props) {
|
|
37
37
|
super(props);
|
|
38
38
|
_rollupPluginBabelHelpers.defineProperty(this, "_subMenus", /*#__PURE__*/React__default["default"].createRef());
|
|
39
|
+
/**
|
|
40
|
+
* Toggle the expanded state of the menu on click.
|
|
41
|
+
*/
|
|
39
42
|
_rollupPluginBabelHelpers.defineProperty(this, "handleOnClick", e => {
|
|
40
43
|
const {
|
|
41
44
|
current: subMenusNode
|
|
@@ -47,6 +50,9 @@ class HeaderMenu extends React__default["default"].Component {
|
|
|
47
50
|
expanded: !prevState.expanded
|
|
48
51
|
}));
|
|
49
52
|
});
|
|
53
|
+
/**
|
|
54
|
+
* Keyboard event handler for the entire menu.
|
|
55
|
+
*/
|
|
50
56
|
_rollupPluginBabelHelpers.defineProperty(this, "handleOnKeyDown", event => {
|
|
51
57
|
// Handle enter or space key for toggling the expanded state of the menu.
|
|
52
58
|
if (match.matches(event, [keys.Enter, keys.Space])) {
|
|
@@ -58,6 +64,11 @@ class HeaderMenu extends React__default["default"].Component {
|
|
|
58
64
|
return;
|
|
59
65
|
}
|
|
60
66
|
});
|
|
67
|
+
/**
|
|
68
|
+
* Handle our blur event from our underlying menuitems. Will mostly be used
|
|
69
|
+
* for toggling the expansion status of our menu in response to a user
|
|
70
|
+
* clicking off of the menu or menubar.
|
|
71
|
+
*/
|
|
61
72
|
_rollupPluginBabelHelpers.defineProperty(this, "handleOnBlur", event => {
|
|
62
73
|
// Rough guess for a blur event that is triggered outside of our menu or
|
|
63
74
|
// menubar context
|
|
@@ -70,12 +81,24 @@ class HeaderMenu extends React__default["default"].Component {
|
|
|
70
81
|
selectedIndex: null
|
|
71
82
|
});
|
|
72
83
|
});
|
|
84
|
+
/**
|
|
85
|
+
* ref handler for our menu button. If we are supplied a `focusRef` prop, we also
|
|
86
|
+
* forward along the node.
|
|
87
|
+
*
|
|
88
|
+
* This is useful when this component is a child in a
|
|
89
|
+
* menu or menubar as it will allow the parent to explicitly focus the menu
|
|
90
|
+
* button node when that child should receive focus.
|
|
91
|
+
*/
|
|
73
92
|
_rollupPluginBabelHelpers.defineProperty(this, "handleMenuButtonRef", node => {
|
|
74
93
|
if (this.props.focusRef) {
|
|
75
94
|
this.props.focusRef(node);
|
|
76
95
|
}
|
|
77
96
|
this.menuButtonRef = node;
|
|
78
97
|
});
|
|
98
|
+
/**
|
|
99
|
+
* Handles individual menuitem refs. We assign them to a class instance
|
|
100
|
+
* property so that we can properly manage focus of our children.
|
|
101
|
+
*/
|
|
79
102
|
_rollupPluginBabelHelpers.defineProperty(this, "handleItemRef", index => node => {
|
|
80
103
|
this.items[index] = node;
|
|
81
104
|
});
|
|
@@ -94,6 +117,12 @@ class HeaderMenu extends React__default["default"].Component {
|
|
|
94
117
|
return;
|
|
95
118
|
}
|
|
96
119
|
});
|
|
120
|
+
/**
|
|
121
|
+
* We capture the `ref` for each child inside of `this.items` to properly
|
|
122
|
+
* manage focus. In addition to this focus management, all items receive a
|
|
123
|
+
* `tabIndex: -1` so the user won't hit a large number of items in their tab
|
|
124
|
+
* sequence when they might not want to go through all the items.
|
|
125
|
+
*/
|
|
97
126
|
_rollupPluginBabelHelpers.defineProperty(this, "_renderMenuItem", (item, index) => {
|
|
98
127
|
if ( /*#__PURE__*/React__default["default"].isValidElement(item)) {
|
|
99
128
|
return /*#__PURE__*/React__default["default"].cloneElement(item, {
|
|
@@ -110,35 +139,6 @@ class HeaderMenu extends React__default["default"].Component {
|
|
|
110
139
|
};
|
|
111
140
|
this.items = [];
|
|
112
141
|
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Toggle the expanded state of the menu on click.
|
|
116
|
-
*/
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Keyboard event handler for the entire menu.
|
|
120
|
-
*/
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Handle our blur event from our underlying menuitems. Will mostly be used
|
|
124
|
-
* for toggling the expansion status of our menu in response to a user
|
|
125
|
-
* clicking off of the menu or menubar.
|
|
126
|
-
*/
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* ref handler for our menu button. If we are supplied a `focusRef` prop, we also
|
|
130
|
-
* forward along the node.
|
|
131
|
-
*
|
|
132
|
-
* This is useful when this component is a child in a
|
|
133
|
-
* menu or menubar as it will allow the parent to explicitly focus the menu
|
|
134
|
-
* button node when that child should receive focus.
|
|
135
|
-
*/
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Handles individual menuitem refs. We assign them to a class instance
|
|
139
|
-
* property so that we can properly manage focus of our children.
|
|
140
|
-
*/
|
|
141
|
-
|
|
142
142
|
render() {
|
|
143
143
|
const prefix = this.context;
|
|
144
144
|
const {
|
|
@@ -201,13 +201,6 @@ class HeaderMenu extends React__default["default"].Component {
|
|
|
201
201
|
className: `${prefix}--header__menu`
|
|
202
202
|
}), React__default["default"].Children.map(children, this._renderMenuItem)));
|
|
203
203
|
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* We capture the `ref` for each child inside of `this.items` to properly
|
|
207
|
-
* manage focus. In addition to this focus management, all items receive a
|
|
208
|
-
* `tabIndex: -1` so the user won't hit a large number of items in their tab
|
|
209
|
-
* sequence when they might not want to go through all the items.
|
|
210
|
-
*/
|
|
211
204
|
}
|
|
212
205
|
_rollupPluginBabelHelpers.defineProperty(HeaderMenu, "propTypes", {
|
|
213
206
|
/**
|
|
@@ -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
|
|
@@ -74,6 +74,10 @@ HeaderMenuButton.propTypes = {
|
|
|
74
74
|
* Specify whether the menu button is "active".
|
|
75
75
|
*/
|
|
76
76
|
isActive: PropTypes__default["default"].bool,
|
|
77
|
+
/**
|
|
78
|
+
* Specify whether the menu button is collapsible.
|
|
79
|
+
*/
|
|
80
|
+
isCollapsible: PropTypes__default["default"].bool,
|
|
77
81
|
/**
|
|
78
82
|
* Optionally provide an onClick handler that is called when the underlying
|
|
79
83
|
* 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;
|
|
@@ -26,15 +26,13 @@ function HeaderName(_ref) {
|
|
|
26
26
|
let {
|
|
27
27
|
children,
|
|
28
28
|
className: customClassName,
|
|
29
|
-
prefix,
|
|
30
|
-
href,
|
|
29
|
+
prefix = 'IBM',
|
|
31
30
|
...rest
|
|
32
31
|
} = _ref;
|
|
33
32
|
const selectorPrefix = usePrefix.usePrefix();
|
|
34
33
|
const className = cx__default["default"](`${selectorPrefix}--header__name`, customClassName);
|
|
35
34
|
return /*#__PURE__*/React__default["default"].createElement(Link["default"], _rollupPluginBabelHelpers["extends"]({}, rest, {
|
|
36
|
-
className: className
|
|
37
|
-
href: href
|
|
35
|
+
className: className
|
|
38
36
|
}), prefix && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("span", {
|
|
39
37
|
className: `${selectorPrefix}--header__name--prefix`
|
|
40
38
|
}, prefix), "\xA0"), children);
|
|
@@ -64,8 +62,5 @@ HeaderName.propTypes = {
|
|
|
64
62
|
*/
|
|
65
63
|
prefix: PropTypes__default["default"].string
|
|
66
64
|
};
|
|
67
|
-
HeaderName.defaultProps = {
|
|
68
|
-
prefix: 'IBM'
|
|
69
|
-
};
|
|
70
65
|
|
|
71
66
|
exports["default"] = HeaderName;
|
|
@@ -49,7 +49,7 @@ const HeaderPanel = /*#__PURE__*/React__default["default"].forwardRef(function H
|
|
|
49
49
|
const eventHandlers = {};
|
|
50
50
|
if (addFocusListeners) {
|
|
51
51
|
eventHandlers.onBlur = event => {
|
|
52
|
-
if (!event.currentTarget.contains(event.relatedTarget) && !lastClickedElement
|
|
52
|
+
if (!event.currentTarget.contains(event.relatedTarget) && !lastClickedElement?.classList?.contains('cds--switcher__item-link')) {
|
|
53
53
|
setExpandedState(false);
|
|
54
54
|
setLastClickedElement(null);
|
|
55
55
|
if (expanded) {
|
|
@@ -70,7 +70,7 @@ const HeaderPanel = /*#__PURE__*/React__default["default"].forwardRef(function H
|
|
|
70
70
|
useEvent.useWindowEvent('click', () => {
|
|
71
71
|
const focusedElement = document.activeElement;
|
|
72
72
|
setLastClickedElement(focusedElement);
|
|
73
|
-
if (children.type
|
|
73
|
+
if (children.type?.displayName === 'Switcher' && !focusedElement?.closest(`.${prefix}--header-panel--expanded`) && !focusedElement?.closest(`.${prefix}--header__action`) && !headerPanelRef?.current?.classList.contains(`${prefix}--switcher`) && expanded) {
|
|
74
74
|
setExpandedState(false);
|
|
75
75
|
onHeaderPanelFocus();
|
|
76
76
|
}
|
|
@@ -67,12 +67,23 @@ const Switcher = /*#__PURE__*/React__default["default"].forwardRef(function Swit
|
|
|
67
67
|
const switcherItem = switcherRef.current.children[nextValidIndex].children[0];
|
|
68
68
|
switcherItem?.focus();
|
|
69
69
|
};
|
|
70
|
-
const childrenWithProps = React__default["default"].Children.toArray(children).map((child, index) =>
|
|
71
|
-
handleSwitcherItemFocus
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
const childrenWithProps = React__default["default"].Children.toArray(children).map((child, index) => {
|
|
71
|
+
// handleSwitcherItemFocus should only be passed down if the child is a SwitcherItem
|
|
72
|
+
// SwitcherDivider, for example, does not accept a handleSwitcherItemFocus prop
|
|
73
|
+
if (child.type?.displayName === 'SwitcherItem') {
|
|
74
|
+
return /*#__PURE__*/React__default["default"].cloneElement(child, {
|
|
75
|
+
handleSwitcherItemFocus,
|
|
76
|
+
index,
|
|
77
|
+
key: index,
|
|
78
|
+
expanded
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return /*#__PURE__*/React__default["default"].cloneElement(child, {
|
|
82
|
+
index,
|
|
83
|
+
key: index,
|
|
84
|
+
expanded
|
|
85
|
+
});
|
|
86
|
+
});
|
|
76
87
|
return /*#__PURE__*/React__default["default"].createElement("ul", _rollupPluginBabelHelpers["extends"]({
|
|
77
88
|
ref: ref,
|
|
78
89
|
className: className
|
package/lib/index.js
CHANGED
|
@@ -63,6 +63,7 @@ var TextArea_Skeleton = require('./components/TextArea/TextArea.Skeleton.js');
|
|
|
63
63
|
require('./components/TextInput/index.js');
|
|
64
64
|
var Tile = require('./components/Tile/Tile.js');
|
|
65
65
|
var index$a = require('./components/TileGroup/index.js');
|
|
66
|
+
var Toggle = require('./components/Toggle/Toggle.js');
|
|
66
67
|
var Toggle_Skeleton = require('./components/Toggle/Toggle.Skeleton.js');
|
|
67
68
|
var ToggleSmall_Skeleton = require('./components/ToggleSmall/ToggleSmall.Skeleton.js');
|
|
68
69
|
var index$b = require('./components/Toggletip/index.js');
|
|
@@ -114,7 +115,6 @@ var NumberInput_Skeleton = require('./components/NumberInput/NumberInput.Skeleto
|
|
|
114
115
|
var ProgressIndicator_Skeleton = require('./components/ProgressIndicator/ProgressIndicator.Skeleton.js');
|
|
115
116
|
var TextInput_Skeleton = require('./components/TextInput/TextInput.Skeleton.js');
|
|
116
117
|
var TextInput = require('./components/TextInput/TextInput.js');
|
|
117
|
-
var Toggle = require('./components/Toggle/Toggle.js');
|
|
118
118
|
var TreeNode = require('./components/TreeView/TreeNode.js');
|
|
119
119
|
var TreeView = require('./components/TreeView/TreeView.js');
|
|
120
120
|
var HeaderContainer = require('./components/UIShell/HeaderContainer.js');
|
|
@@ -296,6 +296,7 @@ exports.Tile = Tile.Tile;
|
|
|
296
296
|
exports.TileAboveTheFoldContent = Tile.TileAboveTheFoldContent;
|
|
297
297
|
exports.TileBelowTheFoldContent = Tile.TileBelowTheFoldContent;
|
|
298
298
|
exports.TileGroup = index$a["default"];
|
|
299
|
+
exports.Toggle = Toggle.Toggle;
|
|
299
300
|
exports.ToggleSkeleton = Toggle_Skeleton["default"];
|
|
300
301
|
exports.ToggleSmallSkeleton = ToggleSmall_Skeleton["default"];
|
|
301
302
|
exports.Toggletip = index$b.Toggletip;
|
|
@@ -360,7 +361,6 @@ exports.NumberInputSkeleton = NumberInput_Skeleton["default"];
|
|
|
360
361
|
exports.ProgressIndicatorSkeleton = ProgressIndicator_Skeleton["default"];
|
|
361
362
|
exports.TextInputSkeleton = TextInput_Skeleton["default"];
|
|
362
363
|
exports.TextInput = TextInput["default"];
|
|
363
|
-
exports.Toggle = Toggle.Toggle;
|
|
364
364
|
exports.TreeNode = TreeNode["default"];
|
|
365
365
|
exports.TreeView = TreeView["default"];
|
|
366
366
|
exports.HeaderContainer = HeaderContainer["default"];
|
|
@@ -153,6 +153,7 @@ class FloatingMenu extends React__default["default"].Component {
|
|
|
153
153
|
var _this;
|
|
154
154
|
super(...arguments);
|
|
155
155
|
_this = this;
|
|
156
|
+
// `true` if the menu body is mounted and calculation of the position is in progress.
|
|
156
157
|
_rollupPluginBabelHelpers.defineProperty(this, "_placeInProgress", false);
|
|
157
158
|
_rollupPluginBabelHelpers.defineProperty(this, "state", {
|
|
158
159
|
/**
|
|
@@ -161,10 +162,36 @@ class FloatingMenu extends React__default["default"].Component {
|
|
|
161
162
|
*/
|
|
162
163
|
floatingPosition: undefined
|
|
163
164
|
});
|
|
165
|
+
/**
|
|
166
|
+
* The cached reference to the menu container.
|
|
167
|
+
* Only used if React portal API is not available.
|
|
168
|
+
* @type {Element}
|
|
169
|
+
* @private
|
|
170
|
+
*/
|
|
164
171
|
_rollupPluginBabelHelpers.defineProperty(this, "_menuContainer", null);
|
|
172
|
+
/**
|
|
173
|
+
* The cached reference to the menu body.
|
|
174
|
+
* The reference is set via callback ref instead of object ref,
|
|
175
|
+
* in order to hook the event when the element ref gets available,
|
|
176
|
+
* which can be at a different timing from `cDM()`, presumably with SSR scenario.
|
|
177
|
+
* @type {Element}
|
|
178
|
+
* @private
|
|
179
|
+
*/
|
|
165
180
|
_rollupPluginBabelHelpers.defineProperty(this, "_menuBody", null);
|
|
181
|
+
/**
|
|
182
|
+
* Focus sentinel refs for focus trap behavior
|
|
183
|
+
*/
|
|
166
184
|
_rollupPluginBabelHelpers.defineProperty(this, "startSentinel", /*#__PURE__*/React__default["default"].createRef());
|
|
167
185
|
_rollupPluginBabelHelpers.defineProperty(this, "endSentinel", /*#__PURE__*/React__default["default"].createRef());
|
|
186
|
+
/**
|
|
187
|
+
* Calculates the position in the viewport of floating menu,
|
|
188
|
+
* once this component is mounted or updated upon change in the following props:
|
|
189
|
+
*
|
|
190
|
+
* * `menuOffset` (The adjustment that should be applied to the calculated floating menu's position)
|
|
191
|
+
* * `menuDirection` (Where the floating menu menu should be placed relative to the trigger button)
|
|
192
|
+
*
|
|
193
|
+
* @private
|
|
194
|
+
*/
|
|
168
195
|
_rollupPluginBabelHelpers.defineProperty(this, "_updateMenuSize", function () {
|
|
169
196
|
let prevProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
170
197
|
let isAdjustment = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
@@ -238,6 +265,11 @@ class FloatingMenu extends React__default["default"].Component {
|
|
|
238
265
|
}
|
|
239
266
|
}
|
|
240
267
|
});
|
|
268
|
+
/**
|
|
269
|
+
* Set focus on floating menu content after menu placement.
|
|
270
|
+
* @param {Element} menuBody The DOM element of the menu body.
|
|
271
|
+
* @private
|
|
272
|
+
*/
|
|
241
273
|
_rollupPluginBabelHelpers.defineProperty(this, "_focusMenuContent", menuBody => {
|
|
242
274
|
const primaryFocusNode = menuBody.querySelector(this.props.selectorPrimaryFocus || null);
|
|
243
275
|
const tabbableNode = menuBody.querySelector(navigation.selectorTabbable);
|
|
@@ -254,6 +286,10 @@ class FloatingMenu extends React__default["default"].Component {
|
|
|
254
286
|
process.env.NODE_ENV !== "production" ? warning.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;
|
|
255
287
|
}
|
|
256
288
|
});
|
|
289
|
+
/**
|
|
290
|
+
* A callback for called when menu body is mounted or unmounted.
|
|
291
|
+
* @param {Element} menuBody The menu body being mounted. `null` if the menu body is being unmounted.
|
|
292
|
+
*/
|
|
257
293
|
_rollupPluginBabelHelpers.defineProperty(this, "_menuRef", menuBody => {
|
|
258
294
|
const {
|
|
259
295
|
menuRef
|
|
@@ -264,6 +300,10 @@ class FloatingMenu extends React__default["default"].Component {
|
|
|
264
300
|
this._updateMenuSize();
|
|
265
301
|
}
|
|
266
302
|
});
|
|
303
|
+
/**
|
|
304
|
+
* @returns The child nodes, with styles containing the floating menu position.
|
|
305
|
+
* @private
|
|
306
|
+
*/
|
|
267
307
|
_rollupPluginBabelHelpers.defineProperty(this, "_getChildrenWithProps", () => {
|
|
268
308
|
const {
|
|
269
309
|
styles,
|
|
@@ -292,6 +332,12 @@ class FloatingMenu extends React__default["default"].Component {
|
|
|
292
332
|
}
|
|
293
333
|
});
|
|
294
334
|
});
|
|
335
|
+
/**
|
|
336
|
+
* Blur handler for when focus wrap behavior is enabled
|
|
337
|
+
* @param {Event} event
|
|
338
|
+
* @param {Element} event.target previously focused node
|
|
339
|
+
* @param {Element} event.relatedTarget current focused node
|
|
340
|
+
*/
|
|
295
341
|
_rollupPluginBabelHelpers.defineProperty(this, "handleBlur", _ref2 => {
|
|
296
342
|
let {
|
|
297
343
|
target: oldActiveNode,
|
|
@@ -313,33 +359,7 @@ class FloatingMenu extends React__default["default"].Component {
|
|
|
313
359
|
});
|
|
314
360
|
}
|
|
315
361
|
});
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* The cached reference to the menu container.
|
|
319
|
-
* Only used if React portal API is not available.
|
|
320
|
-
* @type {Element}
|
|
321
|
-
* @private
|
|
322
|
-
*/
|
|
323
|
-
/**
|
|
324
|
-
* The cached reference to the menu body.
|
|
325
|
-
* The reference is set via callback ref instead of object ref,
|
|
326
|
-
* in order to hook the event when the element ref gets available,
|
|
327
|
-
* which can be at a different timing from `cDM()`, presumably with SSR scenario.
|
|
328
|
-
* @type {Element}
|
|
329
|
-
* @private
|
|
330
|
-
*/
|
|
331
|
-
/**
|
|
332
|
-
* Focus sentinel refs for focus trap behavior
|
|
333
|
-
*/
|
|
334
|
-
/**
|
|
335
|
-
* Calculates the position in the viewport of floating menu,
|
|
336
|
-
* once this component is mounted or updated upon change in the following props:
|
|
337
|
-
*
|
|
338
|
-
* * `menuOffset` (The adjustment that should be applied to the calculated floating menu's position)
|
|
339
|
-
* * `menuDirection` (Where the floating menu menu should be placed relative to the trigger button)
|
|
340
|
-
*
|
|
341
|
-
* @private
|
|
342
|
-
*/
|
|
362
|
+
}
|
|
343
363
|
componentWillUnmount() {
|
|
344
364
|
this.hResize.release();
|
|
345
365
|
}
|
|
@@ -348,12 +368,6 @@ class FloatingMenu extends React__default["default"].Component {
|
|
|
348
368
|
this._updateMenuSize();
|
|
349
369
|
});
|
|
350
370
|
}
|
|
351
|
-
/**
|
|
352
|
-
* Set focus on floating menu content after menu placement.
|
|
353
|
-
* @param {Element} menuBody The DOM element of the menu body.
|
|
354
|
-
* @private
|
|
355
|
-
*/
|
|
356
|
-
|
|
357
371
|
componentDidUpdate(prevProps) {
|
|
358
372
|
this._updateMenuSize(prevProps);
|
|
359
373
|
const {
|
|
@@ -369,24 +383,6 @@ class FloatingMenu extends React__default["default"].Component {
|
|
|
369
383
|
}
|
|
370
384
|
}
|
|
371
385
|
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* A callback for called when menu body is mounted or unmounted.
|
|
375
|
-
* @param {Element} menuBody The menu body being mounted. `null` if the menu body is being unmounted.
|
|
376
|
-
*/
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* @returns The child nodes, with styles containing the floating menu position.
|
|
380
|
-
* @private
|
|
381
|
-
*/
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* Blur handler for when focus wrap behavior is enabled
|
|
385
|
-
* @param {Event} event
|
|
386
|
-
* @param {Element} event.target previously focused node
|
|
387
|
-
* @param {Element} event.relatedTarget current focused node
|
|
388
|
-
*/
|
|
389
|
-
|
|
390
386
|
render() {
|
|
391
387
|
const {
|
|
392
388
|
context: prefix
|