@carbon/react 1.55.0-rc.0 → 1.55.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.
@@ -0,0 +1,219 @@
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 PropTypes from 'prop-types';
9
+ /**
10
+ * `HeaderMenu` is used to render submenu's in the `Header`. Most often children
11
+ * will be a `HeaderMenuItem`. It handles certain keyboard events to help
12
+ * with managing focus. It also passes along refs to each child so that it can
13
+ * help manage focus state of its children.
14
+ */
15
+ interface HeaderMenuProps {
16
+ /**
17
+ * Required props for the accessibility label of the menu
18
+ */
19
+ 'aria-label'?: string;
20
+ 'aria-labelledby'?: string;
21
+ /**
22
+ * Optionally provide a custom class to apply to the underlying `<li>` node
23
+ */
24
+ className?: string;
25
+ /**
26
+ * Provide a custom ref handler for the menu button
27
+ */
28
+ focusRef?: React.Ref<any>;
29
+ /**
30
+ * Applies selected styles to the item if a user sets this to true and `aria-current !== 'page'`.
31
+ */
32
+ isActive?: boolean;
33
+ /**
34
+ * Applies selected styles to the item if a user sets this to true and `aria-current !== 'page'`.
35
+ * @deprecated Please use `isActive` instead. This will be removed in the next major release.
36
+ */
37
+ isCurrentPage?: boolean;
38
+ /**
39
+ * Provide a label for the link text
40
+ */
41
+ menuLinkName: string;
42
+ /**
43
+ * Optionally provide an onBlur handler that is called when the underlying
44
+ * button fires it's onblur event
45
+ */
46
+ onBlur?: (event: React.FocusEvent<HTMLLIElement>) => void;
47
+ /**
48
+ * Optionally provide an onClick handler that is called when the underlying
49
+ * button fires it's onclick event
50
+ */
51
+ onClick?: (event: React.MouseEvent<HTMLLIElement, MouseEvent>) => void;
52
+ /**
53
+ * Optionally provide an onKeyDown handler that is called when the underlying
54
+ * button fires it's onkeydown event
55
+ */
56
+ onKeyDown?: (event: React.KeyboardEvent<HTMLLIElement>) => void;
57
+ /**
58
+ * Optional component to render instead of string
59
+ */
60
+ renderMenuContent?: () => JSX.Element;
61
+ /**
62
+ * Optionally provide a tabIndex for the underlying menu button
63
+ */
64
+ tabIndex?: number;
65
+ /**
66
+ * The children should be a series of `HeaderMenuItem` components.
67
+ */
68
+ children?: React.ReactNode;
69
+ }
70
+ interface HeaderMenuState {
71
+ expanded: boolean;
72
+ selectedIndex: number | null;
73
+ }
74
+ declare class HeaderMenu extends React.Component<HeaderMenuProps, HeaderMenuState> {
75
+ static propTypes: {
76
+ /**
77
+ * Optionally provide a custom class to apply to the underlying `<li>` node
78
+ */
79
+ className: PropTypes.Requireable<string>;
80
+ /**
81
+ * Provide a custom ref handler for the menu button
82
+ */
83
+ focusRef: PropTypes.Requireable<(...args: any[]) => any>;
84
+ /**
85
+ * Applies selected styles to the item if a user sets this to true and `aria-current !== 'page'`.
86
+ */
87
+ isActive: PropTypes.Requireable<boolean>;
88
+ /**
89
+ * Applies selected styles to the item if a user sets this to true and `aria-current !== 'page'`.
90
+ * @deprecated Please use `isActive` instead. This will be removed in the next major release.
91
+ */
92
+ isCurrentPage: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
93
+ /**
94
+ * Provide a label for the link text
95
+ */
96
+ menuLinkName: PropTypes.Validator<string>;
97
+ /**
98
+ * Optionally provide an onBlur handler that is called when the underlying
99
+ * button fires it's onblur event
100
+ */
101
+ onBlur: PropTypes.Requireable<(...args: any[]) => any>;
102
+ /**
103
+ * Optionally provide an onClick handler that is called when the underlying
104
+ * button fires it's onclick event
105
+ */
106
+ onClick: PropTypes.Requireable<(...args: any[]) => any>;
107
+ /**
108
+ * Optionally provide an onKeyDown handler that is called when the underlying
109
+ * button fires it's onkeydown event
110
+ */
111
+ onKeyDown: PropTypes.Requireable<(...args: any[]) => any>;
112
+ /**
113
+ * Optional component to render instead of string
114
+ */
115
+ renderMenuContent: PropTypes.Requireable<(...args: any[]) => any>;
116
+ /**
117
+ * Optionally provide a tabIndex for the underlying menu button
118
+ */
119
+ tabIndex: PropTypes.Requireable<number>;
120
+ 0: string;
121
+ length: 1;
122
+ toString(): string;
123
+ toLocaleString(): string;
124
+ pop(): string | undefined;
125
+ push(...items: string[]): number;
126
+ concat(...items: ConcatArray<string>[]): string[];
127
+ concat(...items: (string | ConcatArray<string>)[]): string[];
128
+ join(separator?: string | undefined): string;
129
+ reverse(): string[];
130
+ shift(): string | undefined;
131
+ slice(start?: number | undefined, end?: number | undefined): string[];
132
+ sort(compareFn?: ((a: string, b: string) => number) | undefined): [key: string];
133
+ splice(start: number, deleteCount?: number | undefined): string[];
134
+ splice(start: number, deleteCount: number, ...items: string[]): string[];
135
+ unshift(...items: string[]): number;
136
+ indexOf(searchElement: string, fromIndex?: number | undefined): number;
137
+ lastIndexOf(searchElement: string, fromIndex?: number | undefined): number;
138
+ every<S extends string>(predicate: (value: string, index: number, array: string[]) => value is S, thisArg?: any): this is S[];
139
+ every(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): boolean;
140
+ some(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): boolean;
141
+ forEach(callbackfn: (value: string, index: number, array: string[]) => void, thisArg?: any): void;
142
+ map<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): U[];
143
+ filter<S_1 extends string>(predicate: (value: string, index: number, array: string[]) => value is S_1, thisArg?: any): S_1[];
144
+ filter(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): string[];
145
+ reduce(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string;
146
+ reduce(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string;
147
+ reduce<U_1>(callbackfn: (previousValue: U_1, currentValue: string, currentIndex: number, array: string[]) => U_1, initialValue: U_1): U_1;
148
+ reduceRight(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string;
149
+ reduceRight(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string;
150
+ reduceRight<U_2>(callbackfn: (previousValue: U_2, currentValue: string, currentIndex: number, array: string[]) => U_2, initialValue: U_2): U_2;
151
+ find<S_2 extends string>(predicate: (this: void, value: string, index: number, obj: string[]) => value is S_2, thisArg?: any): S_2 | undefined;
152
+ find(predicate: (value: string, index: number, obj: string[]) => unknown, thisArg?: any): string | undefined;
153
+ findIndex(predicate: (value: string, index: number, obj: string[]) => unknown, thisArg?: any): number;
154
+ fill(value: string, start?: number | undefined, end?: number | undefined): [key: string];
155
+ copyWithin(target: number, start: number, end?: number | undefined): [key: string];
156
+ entries(): IterableIterator<[number, string]>;
157
+ keys(): IterableIterator<number>;
158
+ values(): IterableIterator<string>;
159
+ includes(searchElement: string, fromIndex?: number | undefined): boolean;
160
+ flatMap<U_3, This = undefined>(callback: (this: This, value: string, index: number, array: string[]) => U_3 | readonly U_3[], thisArg?: This | undefined): U_3[];
161
+ flat<A, D extends number = 1>(this: A, depth?: D | undefined): FlatArray<A, D>[];
162
+ at(index: number): string | undefined;
163
+ [Symbol.iterator](): IterableIterator<string>;
164
+ [Symbol.unscopables](): {
165
+ copyWithin: boolean;
166
+ entries: boolean;
167
+ fill: boolean;
168
+ find: boolean;
169
+ findIndex: boolean;
170
+ keys: boolean;
171
+ values: boolean;
172
+ };
173
+ };
174
+ static contextType: React.Context<string>;
175
+ _subMenus: React.RefObject<HTMLUListElement>;
176
+ private items;
177
+ private menuButtonRef;
178
+ constructor(props: any);
179
+ /**
180
+ * Toggle the expanded state of the menu on click.
181
+ */
182
+ handleOnClick: (e: any) => void;
183
+ /**
184
+ * Keyboard event handler for the entire menu.
185
+ */
186
+ handleOnKeyDown: (event: any) => void;
187
+ /**
188
+ * Handle our blur event from our underlying menuitems. Will mostly be used
189
+ * for closing our menu in response to a user clicking off or tabbing out of
190
+ * the menu or menubar.
191
+ */
192
+ handleOnBlur: (event: any) => void;
193
+ /**
194
+ * ref handler for our menu button. If we are supplied a `focusRef` prop, we also
195
+ * forward along the node.
196
+ *
197
+ * This is useful when this component is a child in a
198
+ * menu or menubar as it will allow the parent to explicitly focus the menu
199
+ * button node when that child should receive focus.
200
+ */
201
+ handleMenuButtonRef: (node: any) => void;
202
+ /**
203
+ * Handles individual menuitem refs. We assign them to a class instance
204
+ * property so that we can properly manage focus of our children.
205
+ */
206
+ handleItemRef: (index: any) => (node: any) => void;
207
+ handleMenuClose: (event: any) => void;
208
+ render(): import("react/jsx-runtime").JSX.Element;
209
+ /**
210
+ * We capture the `ref` for each child inside of `this.items` to properly
211
+ * manage focus. In addition to this focus management, all items receive a
212
+ * `tabIndex: -1` so the user won't hit a large number of items in their tab
213
+ * sequence when they might not want to go through all the items.
214
+ */
215
+ _renderMenuItem: (item: React.ReactNode, index: number) => React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
216
+ }
217
+ declare const HeaderMenuForwardRef: React.ForwardRefExoticComponent<React.RefAttributes<unknown>>;
218
+ export { HeaderMenu };
219
+ export default HeaderMenuForwardRef;
@@ -33,10 +33,13 @@ var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
33
33
  * with managing focus. It also passes along refs to each child so that it can
34
34
  * help manage focus state of its children.
35
35
  */
36
+
36
37
  class HeaderMenu extends React__default["default"].Component {
37
38
  constructor(props) {
38
39
  super(props);
39
40
  _rollupPluginBabelHelpers.defineProperty(this, "_subMenus", /*#__PURE__*/React__default["default"].createRef());
41
+ _rollupPluginBabelHelpers.defineProperty(this, "items", []);
42
+ _rollupPluginBabelHelpers.defineProperty(this, "menuButtonRef", null);
40
43
  /**
41
44
  * Toggle the expanded state of the menu on click.
42
45
  */
@@ -91,8 +94,12 @@ class HeaderMenu extends React__default["default"].Component {
91
94
  * button node when that child should receive focus.
92
95
  */
93
96
  _rollupPluginBabelHelpers.defineProperty(this, "handleMenuButtonRef", node => {
94
- if (this.props.focusRef) {
95
- this.props.focusRef(node);
97
+ const {
98
+ focusRef
99
+ } = this.props;
100
+ // Check if focusRef is a function before calling it
101
+ if (typeof focusRef === 'function') {
102
+ focusRef(node);
96
103
  }
97
104
  this.menuButtonRef = node;
98
105
  });
@@ -114,7 +121,9 @@ class HeaderMenu extends React__default["default"].Component {
114
121
  }));
115
122
 
116
123
  // Return focus to menu button when the user hits ESC.
117
- this.menuButtonRef.focus();
124
+ if (this.menuButtonRef !== null) {
125
+ this.menuButtonRef.focus();
126
+ }
118
127
  return;
119
128
  }
120
129
  });
@@ -151,23 +160,25 @@ class HeaderMenu extends React__default["default"].Component {
151
160
  children,
152
161
  renderMenuContent: MenuContent,
153
162
  menuLinkName,
163
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
154
164
  focusRef,
155
- // eslint-disable-line no-unused-vars
156
165
  onBlur,
157
166
  onClick,
158
167
  onKeyDown,
159
168
  ...rest
160
169
  } = this.props;
161
- const hasActiveDescendant = childrenArg => React__default["default"].Children.toArray(childrenArg).some(child => child.props && (child.props.isActive || child.props.isCurrentPage || child.props.children instanceof Array && hasActiveDescendant(child.props.children)));
170
+ const hasActiveDescendant = childrenArg => React__default["default"].Children.toArray(childrenArg).some(child => /*#__PURE__*/React__default["default"].isValidElement(child) && (
171
+ // This is the type guard
172
+ child.props.isActive || child.props.isCurrentPage || Array.isArray(child.props.children) && hasActiveDescendant(child.props.children)));
162
173
  const accessibilityLabel = {
163
174
  'aria-label': ariaLabel,
164
175
  'aria-labelledby': ariaLabelledBy
165
176
  };
166
177
  const itemClassName = cx__default["default"]({
167
178
  [`${prefix}--header__submenu`]: true,
168
- [customClassName]: !!customClassName
179
+ [`${customClassName}`]: !!customClassName
169
180
  });
170
- let isActivePage = isActive ? isActive : isCurrentPage;
181
+ const isActivePage = isActive ? isActive : isCurrentPage;
171
182
  const linkClassName = cx__default["default"]({
172
183
  [`${prefix}--header__menu-item`]: true,
173
184
  [`${prefix}--header__menu-title`]: true,
@@ -258,12 +269,13 @@ _rollupPluginBabelHelpers.defineProperty(HeaderMenu, "propTypes", {
258
269
  });
259
270
  _rollupPluginBabelHelpers.defineProperty(HeaderMenu, "contextType", usePrefix.PrefixContext);
260
271
  const HeaderMenuForwardRef = /*#__PURE__*/React__default["default"].forwardRef((props, ref) => {
261
- return /*#__PURE__*/React__default["default"].createElement(HeaderMenu, _rollupPluginBabelHelpers["extends"]({}, props, {
272
+ return /*#__PURE__*/React__default["default"].createElement(HeaderMenu, _rollupPluginBabelHelpers["extends"]({
273
+ menuLinkName: "link"
274
+ }, props, {
262
275
  focusRef: ref
263
276
  }));
264
277
  });
265
278
  HeaderMenuForwardRef.displayName = 'HeaderMenu';
266
- var HeaderMenuForwardRef$1 = HeaderMenuForwardRef;
267
279
 
268
280
  exports.HeaderMenu = HeaderMenu;
269
- exports["default"] = HeaderMenuForwardRef$1;
281
+ exports["default"] = HeaderMenuForwardRef;
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.55.0-rc.0",
4
+ "version": "1.55.0",
5
5
  "license": "Apache-2.0",
6
6
  "main": "lib/index.js",
7
7
  "module": "es/index.js",
@@ -51,8 +51,8 @@
51
51
  "@carbon/feature-flags": "^0.19.0",
52
52
  "@carbon/icons-react": "^11.39.0",
53
53
  "@carbon/layout": "^11.21.0",
54
- "@carbon/styles": "^1.55.0-rc.0",
55
- "@floating-ui/react": "^0.25.4",
54
+ "@carbon/styles": "^1.55.0",
55
+ "@floating-ui/react": "^0.26.0",
56
56
  "@ibm/telemetry-js": "^1.2.1",
57
57
  "classnames": "2.5.1",
58
58
  "copy-to-clipboard": "^3.3.1",
@@ -141,5 +141,5 @@
141
141
  "**/*.scss",
142
142
  "**/*.css"
143
143
  ],
144
- "gitHead": "600138750484cf814dc1b927ed4c277301b5290a"
144
+ "gitHead": "0163f7e7932f667a892bc75f0aa35464f726f4ec"
145
145
  }