@carbon/react 1.51.1 → 1.52.0-rc.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.
Files changed (72) hide show
  1. package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +913 -907
  2. package/es/components/ComposedModal/ComposedModal.js +3 -1
  3. package/es/components/DataTable/TableActionList.d.ts +8 -0
  4. package/es/components/DataTable/TableActionList.js +1 -2
  5. package/es/components/DataTable/TableHead.d.ts +2 -2
  6. package/es/components/DataTable/TableToolbarContent.d.ts +1 -12
  7. package/es/components/Dropdown/Dropdown.d.ts +1 -1
  8. package/es/components/Link/Link.d.ts +5 -10
  9. package/es/components/Link/Link.js +1 -2
  10. package/es/components/Menu/Menu.d.ts +6 -6
  11. package/es/components/Menu/Menu.js +7 -3
  12. package/es/components/Menu/MenuContext.d.ts +14 -6
  13. package/es/components/Menu/MenuContext.js +3 -3
  14. package/es/components/Menu/MenuItem.d.ts +22 -31
  15. package/es/components/Menu/MenuItem.js +25 -13
  16. package/es/components/MenuButton/index.d.ts +43 -0
  17. package/es/components/MenuButton/index.js +15 -10
  18. package/es/components/Modal/Modal.js +2 -1
  19. package/es/components/Notification/Notification.d.ts +17 -1
  20. package/es/components/Notification/Notification.js +24 -9
  21. package/es/components/Toggletip/index.d.ts +1 -1
  22. package/es/components/Toggletip/index.js +4 -3
  23. package/es/components/TreeView/TreeNode.js +46 -24
  24. package/es/components/TreeView/TreeView.js +40 -13
  25. package/es/components/UIShell/Header.d.ts +24 -0
  26. package/es/components/UIShell/Header.js +1 -2
  27. package/es/components/UIShell/HeaderGlobalAction.d.ts +50 -0
  28. package/es/components/UIShell/HeaderGlobalAction.js +1 -2
  29. package/es/components/UIShell/HeaderGlobalBar.d.ts +11 -0
  30. package/es/components/UIShell/HeaderGlobalBar.js +2 -1
  31. package/es/components/UIShell/SideNavLink.d.ts +57 -0
  32. package/es/components/UIShell/SideNavLink.js +4 -4
  33. package/es/internal/useAttachedMenu.d.ts +45 -0
  34. package/es/internal/useAttachedMenu.js +1 -7
  35. package/es/tools/wrapComponent.d.ts +20 -0
  36. package/es/tools/wrapComponent.js +3 -4
  37. package/lib/components/ComposedModal/ComposedModal.js +3 -1
  38. package/lib/components/DataTable/TableActionList.d.ts +8 -0
  39. package/lib/components/DataTable/TableActionList.js +1 -2
  40. package/lib/components/DataTable/TableHead.d.ts +2 -2
  41. package/lib/components/DataTable/TableToolbarContent.d.ts +1 -12
  42. package/lib/components/Dropdown/Dropdown.d.ts +1 -1
  43. package/lib/components/Link/Link.d.ts +5 -10
  44. package/lib/components/Link/Link.js +1 -2
  45. package/lib/components/Menu/Menu.d.ts +6 -6
  46. package/lib/components/Menu/Menu.js +6 -2
  47. package/lib/components/Menu/MenuContext.d.ts +14 -6
  48. package/lib/components/Menu/MenuContext.js +2 -6
  49. package/lib/components/Menu/MenuItem.d.ts +22 -31
  50. package/lib/components/Menu/MenuItem.js +24 -12
  51. package/lib/components/MenuButton/index.d.ts +43 -0
  52. package/lib/components/MenuButton/index.js +14 -9
  53. package/lib/components/Modal/Modal.js +2 -1
  54. package/lib/components/Notification/Notification.d.ts +17 -1
  55. package/lib/components/Notification/Notification.js +24 -9
  56. package/lib/components/Toggletip/index.d.ts +1 -1
  57. package/lib/components/Toggletip/index.js +4 -3
  58. package/lib/components/TreeView/TreeNode.js +46 -24
  59. package/lib/components/TreeView/TreeView.js +40 -13
  60. package/lib/components/UIShell/Header.d.ts +24 -0
  61. package/lib/components/UIShell/Header.js +1 -2
  62. package/lib/components/UIShell/HeaderGlobalAction.d.ts +50 -0
  63. package/lib/components/UIShell/HeaderGlobalAction.js +1 -2
  64. package/lib/components/UIShell/HeaderGlobalBar.d.ts +11 -0
  65. package/lib/components/UIShell/HeaderGlobalBar.js +2 -1
  66. package/lib/components/UIShell/SideNavLink.d.ts +57 -0
  67. package/lib/components/UIShell/SideNavLink.js +3 -3
  68. package/lib/internal/useAttachedMenu.d.ts +45 -0
  69. package/lib/internal/useAttachedMenu.js +1 -7
  70. package/lib/tools/wrapComponent.d.ts +20 -0
  71. package/lib/tools/wrapComponent.js +5 -6
  72. package/package.json +8 -8
@@ -115,7 +115,7 @@ const ComposedModal = /*#__PURE__*/React__default.forwardRef(function ComposedMo
115
115
  const startSentinel = useRef(null);
116
116
  const endSentinel = useRef(null);
117
117
 
118
- // Kepp track of modal open/close state
118
+ // Keep track of modal open/close state
119
119
  // and propagate it to the document.body
120
120
  useEffect(() => {
121
121
  if (open !== wasOpen) {
@@ -132,12 +132,14 @@ const ComposedModal = /*#__PURE__*/React__default.forwardRef(function ComposedMo
132
132
  }, []); // eslint-disable-line react-hooks/exhaustive-deps
133
133
 
134
134
  function handleKeyDown(evt) {
135
+ evt.stopPropagation();
135
136
  if (match(evt, Escape)) {
136
137
  closeModal(evt);
137
138
  }
138
139
  onKeyDown?.(evt);
139
140
  }
140
141
  function handleMousedown(evt) {
142
+ evt.stopPropagation();
141
143
  const isInside = innerModal.current?.contains(evt.target);
142
144
  if (!isInside && !preventCloseOnClickOutside) {
143
145
  closeModal(evt);
@@ -0,0 +1,8 @@
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
+ declare const TableActionList: (props: import("../../types/common").ReactAttr<"div">) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
8
+ export default TableActionList;
@@ -12,6 +12,5 @@ const TableActionList = wrapComponent({
12
12
  type: 'div',
13
13
  className: prefix => `${prefix}--action-list`
14
14
  });
15
- var TableActionList$1 = TableActionList;
16
15
 
17
- export { TableActionList$1 as default };
16
+ export { TableActionList as default };
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import React, { ThHTMLAttributes } from 'react';
7
+ import { ThHTMLAttributes } from 'react';
8
8
  export type TableHeadProps = ThHTMLAttributes<HTMLTableSectionElement>;
9
- declare const TableHead: React.FC<TableHeadProps>;
9
+ declare const TableHead: (props: import("../../types/common").ReactAttr<"thead">) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
10
10
  export default TableHead;
@@ -4,16 +4,5 @@
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- declare const TableToolbarContent: {
8
- ({ className: baseClassName, ...other }: {
9
- [x: string]: any;
10
- className?: string | undefined;
11
- }): import("react").ReactElement<{
12
- className: string | undefined;
13
- }, string | import("react").JSXElementConstructor<any>>;
14
- displayName: string;
15
- propTypes: {
16
- className: import("prop-types").Requireable<string>;
17
- };
18
- };
7
+ declare const TableToolbarContent: (props: import("../../types/common").ReactAttr<"div">) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
19
8
  export default TableToolbarContent;
@@ -102,7 +102,7 @@ export interface DropdownProps<ItemType> extends Omit<ReactAttr<HTMLDivElement>,
102
102
  * An optional callback to render the currently selected item as a react element instead of only
103
103
  * as a string.
104
104
  */
105
- renderSelectedItem?(item: ItemType): React.JSXElementConstructor<ItemType> | null;
105
+ renderSelectedItem?(item: ItemType): ReactNode;
106
106
  /**
107
107
  * In the case you want to control the dropdown selection entirely.
108
108
  */
@@ -4,13 +4,9 @@
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import React, { AnchorHTMLAttributes, AriaAttributes, ComponentType, HTMLAttributeAnchorTarget } from 'react';
8
- export interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
9
- /**
10
- * Provide a custom element or component to render the top-level node for the
11
- * component.
12
- */
13
- as?: string | undefined;
7
+ import React, { AnchorHTMLAttributes, AriaAttributes, ComponentType, ElementType, HTMLAttributeAnchorTarget } from 'react';
8
+ import { PolymorphicProps } from '../../types/common';
9
+ export interface LinkBaseProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
14
10
  /**
15
11
  * @description Indicates the element that represents the
16
12
  * current item within a container or set of related
@@ -52,7 +48,6 @@ export interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
52
48
  */
53
49
  visited?: boolean;
54
50
  }
55
- declare const Link: React.ForwardRefExoticComponent<LinkProps & {
56
- children?: React.ReactNode;
57
- } & React.RefAttributes<HTMLAnchorElement>>;
51
+ export type LinkProps<E extends ElementType> = PolymorphicProps<E, LinkBaseProps>;
52
+ declare const Link: React.ForwardRefExoticComponent<Omit<LinkProps<React.ElementType<any>>, "ref"> & React.RefAttributes<unknown>>;
58
53
  export default Link;
@@ -60,7 +60,7 @@ Link.propTypes = {
60
60
  * Provide a custom element or component to render the top-level node for the
61
61
  * component.
62
62
  */
63
- as: PropTypes.string,
63
+ as: PropTypes.elementType,
64
64
  /**
65
65
  * Provide the content for the Link
66
66
  */
@@ -85,7 +85,6 @@ Link.propTypes = {
85
85
  * Optional prop to render an icon next to the link.
86
86
  * Can be a React component class
87
87
  */
88
- // @ts-expect-error - PropTypes are unable to cover this case.
89
88
  renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
90
89
  /**
91
90
  * Specify the size of the Link. Currently supports either `sm`, 'md' (default) or 'lg` as an option.
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import React, { RefObject } from 'react';
7
+ import React, { ReactNode, RefObject } from 'react';
8
8
  interface MenuProps extends React.HTMLAttributes<HTMLUListElement> {
9
9
  /**
10
10
  * The ref of the containing element, used for positioning and alignment of the menu
@@ -13,7 +13,7 @@ interface MenuProps extends React.HTMLAttributes<HTMLUListElement> {
13
13
  /**
14
14
  * A collection of MenuItems to be rendered within this Menu.
15
15
  */
16
- children?: React.ReactNode;
16
+ children?: ReactNode;
17
17
  /**
18
18
  * Additional CSS class names.
19
19
  */
@@ -21,7 +21,7 @@ interface MenuProps extends React.HTMLAttributes<HTMLUListElement> {
21
21
  /**
22
22
  * A label describing the Menu.
23
23
  */
24
- label?: string;
24
+ label: string;
25
25
  /**
26
26
  * Specify how the menu should align with the button element
27
27
  */
@@ -53,15 +53,15 @@ interface MenuProps extends React.HTMLAttributes<HTMLUListElement> {
53
53
  /**
54
54
  * Specify a DOM node where the Menu should be rendered in. Defaults to document.body.
55
55
  */
56
- target?: any;
56
+ target?: HTMLElement;
57
57
  /**
58
58
  * Specify the x position of the Menu. Either pass a single number or an array with two numbers describing your activator's boundaries ([x1, x2])
59
59
  */
60
- x?: number | (number | null | undefined)[];
60
+ x?: number | [number, number];
61
61
  /**
62
62
  * Specify the y position of the Menu. Either pass a single number or an array with two numbers describing your activator's boundaries ([y1, y2])
63
63
  */
64
- y?: number | (number | null | undefined)[];
64
+ y?: number | [number, number];
65
65
  }
66
66
  declare const Menu: React.ForwardRefExoticComponent<MenuProps & React.RefAttributes<HTMLUListElement>>;
67
67
  export { Menu };
@@ -8,7 +8,7 @@
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import cx from 'classnames';
10
10
  import PropTypes from 'prop-types';
11
- import React__default, { useRef, useContext, useReducer, useMemo, useState, useEffect } from 'react';
11
+ import React__default, { forwardRef, useRef, useContext, useReducer, useMemo, useState, useEffect } from 'react';
12
12
  import { createPortal } from 'react-dom';
13
13
  import { useMergedRefs } from '../../internal/useMergedRefs.js';
14
14
  import { usePrefix } from '../../internal/usePrefix.js';
@@ -20,7 +20,7 @@ import { Escape, ArrowLeft, ArrowUp, ArrowDown } from '../../internal/keyboard/k
20
20
 
21
21
  const spacing = 8; // distance to keep to window edges, in px
22
22
 
23
- const Menu = /*#__PURE__*/React__default.forwardRef(function Menu(_ref, forwardRef) {
23
+ const Menu = /*#__PURE__*/forwardRef(function Menu(_ref, forwardRef) {
24
24
  let {
25
25
  children,
26
26
  className,
@@ -72,7 +72,7 @@ const Menu = /*#__PURE__*/React__default.forwardRef(function Menu(_ref, forwardR
72
72
  actionButtonWidth = w;
73
73
  }
74
74
 
75
- // Set RTL based on document direction or `LayoutDirection`
75
+ // Set RTL based on the document direction or `LayoutDirection`
76
76
  const {
77
77
  direction
78
78
  } = useLayoutDirection();
@@ -303,6 +303,7 @@ Menu.propTypes = {
303
303
  /**
304
304
  * A label describing the Menu.
305
305
  */
306
+ // @ts-ignore-next-line -- avoid spurious (?) TS2322 error
306
307
  label: PropTypes.string,
307
308
  /**
308
309
  * Specify how the menu should align with the button element
@@ -335,14 +336,17 @@ Menu.propTypes = {
335
336
  /**
336
337
  * Specify a DOM node where the Menu should be rendered in. Defaults to document.body.
337
338
  */
339
+ // @ts-ignore-next-line -- avoid spurious (?) TS2322 error
338
340
  target: PropTypes.object,
339
341
  /**
340
342
  * Specify the x position of the Menu. Either pass a single number or an array with two numbers describing your activator's boundaries ([x1, x2])
341
343
  */
344
+ // @ts-ignore-next-line -- avoid spurious (?) TS2322 error
342
345
  x: PropTypes.oneOfType([PropTypes.number, PropTypes.arrayOf(PropTypes.number)]),
343
346
  /**
344
347
  * Specify the y position of the Menu. Either pass a single number or an array with two numbers describing your activator's boundaries ([y1, y2])
345
348
  */
349
+ // @ts-ignore-next-line -- avoid spurious (?) TS2322 error
346
350
  y: PropTypes.oneOfType([PropTypes.number, PropTypes.arrayOf(PropTypes.number)])
347
351
  };
348
352
 
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import React from 'react';
7
+ import { KeyboardEvent, RefObject } from 'react';
8
8
  type ActionType = {
9
9
  type: 'enableIcons' | 'registerItem';
10
10
  payload: any;
@@ -15,7 +15,7 @@ type StateType = {
15
15
  hasIcons: boolean;
16
16
  size: 'xs' | 'sm' | 'md' | 'lg' | null;
17
17
  items: any[];
18
- requestCloseRoot: (e: Pick<React.KeyboardEvent<HTMLUListElement>, 'type'>) => void;
18
+ requestCloseRoot: (e: Pick<KeyboardEvent<HTMLUListElement>, 'type'>) => void;
19
19
  };
20
20
  declare function menuReducer(state: StateType, action: ActionType): {
21
21
  hasIcons: boolean;
@@ -23,10 +23,18 @@ declare function menuReducer(state: StateType, action: ActionType): {
23
23
  mode: "full" | "basic";
24
24
  size: "sm" | "md" | "lg" | "xs" | null;
25
25
  items: any[];
26
- requestCloseRoot: (e: Pick<React.KeyboardEvent<HTMLUListElement>, "type">) => void;
26
+ requestCloseRoot: (e: Pick<KeyboardEvent<HTMLUListElement>, "type">) => void;
27
27
  };
28
- declare const MenuContext: React.Context<{
28
+ type DispatchFuncProps = {
29
+ type: 'registerItem' | 'enableIcons';
30
+ payload: {
31
+ ref: RefObject<HTMLLIElement>;
32
+ disabled: boolean;
33
+ };
34
+ };
35
+ type MenuContextProps = {
29
36
  state: StateType;
30
- dispatch: React.Dispatch<any>;
31
- }>;
37
+ dispatch: (props: DispatchFuncProps) => void;
38
+ };
39
+ declare const MenuContext: import("react").Context<MenuContextProps>;
32
40
  export { MenuContext, menuReducer };
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import React__default from 'react';
8
+ import { createContext } from 'react';
9
9
 
10
10
  const menuDefaultState = {
11
11
  isRoot: true,
@@ -29,10 +29,10 @@ function menuReducer(state, action) {
29
29
  };
30
30
  }
31
31
  }
32
- const MenuContext = /*#__PURE__*/React__default.createContext({
32
+ const MenuContext = /*#__PURE__*/createContext({
33
33
  state: menuDefaultState,
34
34
  // 'dispatch' is populated by the root menu
35
- dispatch: () => {}
35
+ dispatch: _ => {}
36
36
  });
37
37
 
38
38
  export { MenuContext, menuReducer };
@@ -4,12 +4,12 @@
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import React from 'react';
8
- interface MenuItemProps extends React.LiHTMLAttributes<HTMLLIElement> {
7
+ import React, { ChangeEventHandler, ComponentProps, FC, KeyboardEvent, LiHTMLAttributes, MouseEvent, ReactNode } from 'react';
8
+ export interface MenuItemProps extends LiHTMLAttributes<HTMLLIElement> {
9
9
  /**
10
10
  * Optionally provide another Menu to create a submenu. props.children can't be used to specify the content of the MenuItem itself. Use props.label instead.
11
11
  */
12
- children?: React.ReactNode;
12
+ children?: ReactNode;
13
13
  /**
14
14
  * Additional CSS class names.
15
15
  */
@@ -29,45 +29,37 @@ interface MenuItemProps extends React.LiHTMLAttributes<HTMLLIElement> {
29
29
  /**
30
30
  * Provide an optional function to be called when the MenuItem is clicked.
31
31
  */
32
- onClick?: (event: React.KeyboardEvent<HTMLLIElement> | React.MouseEvent<HTMLLIElement>) => void;
32
+ onClick?: (event: KeyboardEvent<HTMLLIElement> | MouseEvent<HTMLLIElement>) => void;
33
33
  /**
34
34
  * Only applicable if the parent menu is in `basic` mode. Sets the menu item's icon.
35
35
  */
36
- renderIcon?: any;
36
+ renderIcon?: FC;
37
37
  /**
38
38
  * Provide a shortcut for the action of this MenuItem. Note that the component will only render it as a hint but not actually register the shortcut.
39
39
  */
40
40
  shortcut?: string;
41
41
  }
42
- declare const MenuItem: React.ForwardRefExoticComponent<MenuItemProps & React.RefAttributes<HTMLLIElement>>;
43
- interface MenuItemSelectableProps {
44
- /**
45
- * Additional CSS class names.
46
- */
47
- className?: string;
42
+ export declare const MenuItem: React.ForwardRefExoticComponent<MenuItemProps & React.RefAttributes<HTMLLIElement>>;
43
+ export interface MenuItemSelectableProps extends Omit<MenuItemProps, 'onChange'> {
48
44
  /**
49
45
  * Specify whether the option should be selected by default.
50
46
  */
51
47
  defaultSelected?: boolean;
52
- /**
53
- * A required label titling this option.
54
- */
55
- label: string;
56
48
  /**
57
49
  * Provide an optional function to be called when the selection state changes.
58
50
  */
59
- onChange?: React.ChangeEventHandler<HTMLLIElement>;
51
+ onChange?: ChangeEventHandler<HTMLLIElement>;
60
52
  /**
61
- * Pass a bool to props.selected to control the state of this option.
53
+ * Controls the state of this option.
62
54
  */
63
55
  selected?: boolean;
64
56
  }
65
- declare const MenuItemSelectable: React.ForwardRefExoticComponent<MenuItemSelectableProps & React.RefAttributes<HTMLLIElement>>;
66
- interface MenuItemGroupProps {
57
+ export declare const MenuItemSelectable: React.ForwardRefExoticComponent<MenuItemSelectableProps & React.RefAttributes<HTMLLIElement>>;
58
+ export interface MenuItemGroupProps extends ComponentProps<'ul'> {
67
59
  /**
68
60
  * A collection of MenuItems to be rendered within this group.
69
61
  */
70
- children?: React.ReactNode;
62
+ children?: ReactNode;
71
63
  /**
72
64
  * Additional CSS class names.
73
65
  */
@@ -77,8 +69,8 @@ interface MenuItemGroupProps {
77
69
  */
78
70
  label: string;
79
71
  }
80
- declare const MenuItemGroup: React.ForwardRefExoticComponent<MenuItemGroupProps & React.RefAttributes<HTMLLIElement>>;
81
- interface MenuItemRadioGroupProps {
72
+ export declare const MenuItemGroup: React.ForwardRefExoticComponent<Omit<MenuItemGroupProps, "ref"> & React.RefAttributes<HTMLLIElement>>;
73
+ export interface MenuItemRadioGroupProps<Item> extends Omit<ComponentProps<'ul'>, 'onChange'> {
82
74
  /**
83
75
  * Additional CSS class names.
84
76
  */
@@ -86,15 +78,15 @@ interface MenuItemRadioGroupProps {
86
78
  /**
87
79
  * Specify the default selected item. Must match the type of props.items.
88
80
  */
89
- defaultSelectedItem?: any;
81
+ defaultSelectedItem?: Item;
90
82
  /**
91
83
  * Provide a function to convert an item to the string that will be rendered. Defaults to item.toString().
92
84
  */
93
- itemToString?: (item: any) => string;
85
+ itemToString?: (item: Item) => string;
94
86
  /**
95
87
  * Provide the options for this radio group. Can be of any type, as long as you provide an appropriate props.itemToString function.
96
88
  */
97
- items?: any[];
89
+ items: Item[];
98
90
  /**
99
91
  * A required label titling this radio group.
100
92
  */
@@ -102,18 +94,17 @@ interface MenuItemRadioGroupProps {
102
94
  /**
103
95
  * Provide an optional function to be called when the selection changes.
104
96
  */
105
- onChange?: React.ChangeEventHandler<HTMLLIElement>;
97
+ onChange?: ChangeEventHandler<HTMLLIElement>;
106
98
  /**
107
99
  * Provide props.selectedItem to control the state of this radio group. Must match the type of props.items.
108
100
  */
109
- selectedItem?: any;
101
+ selectedItem?: Item;
110
102
  }
111
- declare const MenuItemRadioGroup: React.ForwardRefExoticComponent<MenuItemRadioGroupProps & React.RefAttributes<HTMLLIElement>>;
112
- interface MenuItemDividerProps {
103
+ export declare const MenuItemRadioGroup: React.ForwardRefExoticComponent<Omit<MenuItemRadioGroupProps<unknown>, "ref"> & React.RefAttributes<HTMLLIElement>>;
104
+ export interface MenuItemDividerProps extends ComponentProps<'li'> {
113
105
  /**
114
106
  * Additional CSS class names.
115
107
  */
116
108
  className?: string;
117
109
  }
118
- declare const MenuItemDivider: React.ForwardRefExoticComponent<MenuItemDividerProps & React.RefAttributes<HTMLLIElement>>;
119
- export { MenuItem, MenuItemSelectable, MenuItemGroup, MenuItemRadioGroup, MenuItemDivider, };
110
+ export declare const MenuItemDivider: React.ForwardRefExoticComponent<Omit<MenuItemDividerProps, "ref"> & React.RefAttributes<HTMLLIElement>>;
@@ -8,7 +8,7 @@
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import cx from 'classnames';
10
10
  import PropTypes from 'prop-types';
11
- import React__default, { useContext, useRef, useState, useEffect } from 'react';
11
+ import React__default, { forwardRef, useContext, useRef, useState, useEffect } from 'react';
12
12
  import { CaretLeft, CaretRight, Checkmark } from '@carbon/icons-react';
13
13
  import { useControllableState } from '../../internal/useControllableState.js';
14
14
  import { useMergedRefs } from '../../internal/useMergedRefs.js';
@@ -25,7 +25,7 @@ import { ArrowRight, Enter, Space } from '../../internal/keyboard/keys.js';
25
25
  var _CaretLeft, _CaretRight;
26
26
  const hoverIntentDelay = 150; // in ms
27
27
 
28
- const MenuItem = /*#__PURE__*/React__default.forwardRef(function MenuItem(_ref, forwardRef) {
28
+ const MenuItem = /*#__PURE__*/forwardRef(function MenuItem(_ref, forwardRef) {
29
29
  let {
30
30
  children,
31
31
  className,
@@ -45,7 +45,7 @@ const MenuItem = /*#__PURE__*/React__default.forwardRef(function MenuItem(_ref,
45
45
  x: -1,
46
46
  y: -1
47
47
  });
48
- const [isRtl, setRtl] = useState(false);
48
+ const [rtl, setRtl] = useState(false);
49
49
  const hasChildren = Boolean(children);
50
50
  const [submenuOpen, setSubmenuOpen] = useState(false);
51
51
  const hoverIntentTimeout = useRef(null);
@@ -70,7 +70,7 @@ const MenuItem = /*#__PURE__*/React__default.forwardRef(function MenuItem(_ref,
70
70
  width,
71
71
  height
72
72
  } = menuItem.current.getBoundingClientRect();
73
- if (isRtl) {
73
+ if (rtl) {
74
74
  setBoundaries({
75
75
  x: [-x, x - width],
76
76
  y: [y, y + height]
@@ -138,7 +138,7 @@ const MenuItem = /*#__PURE__*/React__default.forwardRef(function MenuItem(_ref,
138
138
  // eslint-disable-next-line react-hooks/exhaustive-deps
139
139
  }, []);
140
140
 
141
- // Set RTL based on document direction or `LayoutDirection`
141
+ // Set RTL based on the document direction or `LayoutDirection`
142
142
  const {
143
143
  direction
144
144
  } = useLayoutDirection();
@@ -152,6 +152,7 @@ const MenuItem = /*#__PURE__*/React__default.forwardRef(function MenuItem(_ref,
152
152
  const iconsAllowed = context.state.mode === 'basic' || rest.role === 'menuitemcheckbox' || rest.role === 'menuitemradio';
153
153
  useEffect(() => {
154
154
  if (iconsAllowed && IconElement && !context.state.hasIcons) {
155
+ // @ts-ignore - TODO: Should we be passing payload?
155
156
  context.dispatch({
156
157
  type: 'enableIcons'
157
158
  });
@@ -163,8 +164,8 @@ const MenuItem = /*#__PURE__*/React__default.forwardRef(function MenuItem(_ref,
163
164
  ref: ref,
164
165
  className: classNames,
165
166
  tabIndex: -1,
166
- "aria-disabled": isDisabled,
167
- "aria-haspopup": hasChildren || undefined,
167
+ "aria-disabled": isDisabled ?? undefined,
168
+ "aria-haspopup": hasChildren ?? undefined,
168
169
  "aria-expanded": hasChildren ? submenuOpen : undefined,
169
170
  onClick: handleClick,
170
171
  onMouseEnter: hasChildren ? handleMouseEnter : undefined,
@@ -180,7 +181,7 @@ const MenuItem = /*#__PURE__*/React__default.forwardRef(function MenuItem(_ref,
180
181
  className: `${prefix}--menu-item__shortcut`
181
182
  }, shortcut), hasChildren && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", {
182
183
  className: `${prefix}--menu-item__shortcut`
183
- }, isRtl ? _CaretLeft || (_CaretLeft = /*#__PURE__*/React__default.createElement(CaretLeft, null)) : _CaretRight || (_CaretRight = /*#__PURE__*/React__default.createElement(CaretRight, null))), /*#__PURE__*/React__default.createElement(Menu, {
184
+ }, rtl ? _CaretLeft || (_CaretLeft = /*#__PURE__*/React__default.createElement(CaretLeft, null)) : _CaretRight || (_CaretRight = /*#__PURE__*/React__default.createElement(CaretRight, null))), /*#__PURE__*/React__default.createElement(Menu, {
184
185
  label: label,
185
186
  open: submenuOpen,
186
187
  onClose: () => {
@@ -215,17 +216,20 @@ MenuItem.propTypes = {
215
216
  /**
216
217
  * Provide an optional function to be called when the MenuItem is clicked.
217
218
  */
219
+ // @ts-ignore-next-line -- avoid spurious (?) TS2322 error
218
220
  onClick: PropTypes.func,
219
221
  /**
220
222
  * Only applicable if the parent menu is in `basic` mode. Sets the menu item's icon.
221
223
  */
224
+ // @ts-ignore-next-line -- avoid spurious (?) TS2322 error
222
225
  renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
223
226
  /**
224
227
  * Provide a shortcut for the action of this MenuItem. Note that the component will only render it as a hint but not actually register the shortcut.
225
228
  */
229
+ // @ts-ignore-next-line -- avoid spurious (?) TS2322 error
226
230
  shortcut: PropTypes.string
227
231
  };
228
- const MenuItemSelectable = /*#__PURE__*/React__default.forwardRef(function MenuItemSelectable(_ref2, forwardRef) {
232
+ const MenuItemSelectable = /*#__PURE__*/forwardRef(function MenuItemSelectable(_ref2, forwardRef) {
229
233
  let {
230
234
  className,
231
235
  defaultSelected,
@@ -252,6 +256,7 @@ const MenuItemSelectable = /*#__PURE__*/React__default.forwardRef(function MenuI
252
256
  }
253
257
  useEffect(() => {
254
258
  if (!context.state.hasIcons) {
259
+ // @ts-ignore - TODO: Should we be passing payload?
255
260
  context.dispatch({
256
261
  type: 'enableIcons'
257
262
  });
@@ -276,6 +281,7 @@ MenuItemSelectable.propTypes = {
276
281
  /**
277
282
  * Specify whether the option should be selected by default.
278
283
  */
284
+ // @ts-ignore-next-line -- avoid spurious (?) TS2322 error
279
285
  defaultSelected: PropTypes.bool,
280
286
  /**
281
287
  * A required label titling this option.
@@ -284,13 +290,15 @@ MenuItemSelectable.propTypes = {
284
290
  /**
285
291
  * Provide an optional function to be called when the selection state changes.
286
292
  */
293
+ // @ts-ignore-next-line -- avoid spurious (?) TS2322 error
287
294
  onChange: PropTypes.func,
288
295
  /**
289
296
  * Pass a bool to props.selected to control the state of this option.
290
297
  */
298
+ // @ts-ignore-next-line -- avoid spurious (?) TS2322 error
291
299
  selected: PropTypes.bool
292
300
  };
293
- const MenuItemGroup = /*#__PURE__*/React__default.forwardRef(function MenuItemGroup(_ref3, forwardRef) {
301
+ const MenuItemGroup = /*#__PURE__*/forwardRef(function MenuItemGroup(_ref3, forwardRef) {
294
302
  let {
295
303
  children,
296
304
  className,
@@ -323,7 +331,7 @@ MenuItemGroup.propTypes = {
323
331
  label: PropTypes.string.isRequired
324
332
  };
325
333
  const defaultItemToString = item => item.toString();
326
- const MenuItemRadioGroup = /*#__PURE__*/React__default.forwardRef(function MenuItemRadioGroup(_ref4, forwardRef) {
334
+ const MenuItemRadioGroup = /*#__PURE__*/forwardRef(function MenuItemRadioGroup(_ref4, forwardRef) {
327
335
  let {
328
336
  className,
329
337
  defaultSelectedItem,
@@ -352,6 +360,7 @@ const MenuItemRadioGroup = /*#__PURE__*/React__default.forwardRef(function MenuI
352
360
  }
353
361
  useEffect(() => {
354
362
  if (!context.state.hasIcons) {
363
+ // @ts-ignore - TODO: Should we be passing payload?
355
364
  context.dispatch({
356
365
  type: 'enableIcons'
357
366
  });
@@ -365,7 +374,7 @@ const MenuItemRadioGroup = /*#__PURE__*/React__default.forwardRef(function MenuI
365
374
  }, /*#__PURE__*/React__default.createElement("ul", _extends({}, rest, {
366
375
  role: "group",
367
376
  "aria-label": label
368
- }), items?.map((item, i) => /*#__PURE__*/React__default.createElement(MenuItem, {
377
+ }), items.map((item, i) => /*#__PURE__*/React__default.createElement(MenuItem, {
369
378
  key: i,
370
379
  label: itemToString(item),
371
380
  role: "menuitemradio",
@@ -388,10 +397,12 @@ MenuItemRadioGroup.propTypes = {
388
397
  /**
389
398
  * Provide a function to convert an item to the string that will be rendered. Defaults to item.toString().
390
399
  */
400
+ // @ts-ignore-next-line -- avoid spurious (?) TS2322 error
391
401
  itemToString: PropTypes.func,
392
402
  /**
393
403
  * Provide the options for this radio group. Can be of any type, as long as you provide an appropriate props.itemToString function.
394
404
  */
405
+ // @ts-ignore-next-line -- avoid spurious (?) TS2322 error
395
406
  items: PropTypes.array,
396
407
  /**
397
408
  * A required label titling this radio group.
@@ -400,13 +411,14 @@ MenuItemRadioGroup.propTypes = {
400
411
  /**
401
412
  * Provide an optional function to be called when the selection changes.
402
413
  */
414
+ // @ts-ignore-next-line -- avoid spurious (?) TS2322 error
403
415
  onChange: PropTypes.func,
404
416
  /**
405
417
  * Provide props.selectedItem to control the state of this radio group. Must match the type of props.items.
406
418
  */
407
419
  selectedItem: PropTypes.any
408
420
  };
409
- const MenuItemDivider = /*#__PURE__*/React__default.forwardRef(function MenuItemDivider(_ref5, forwardRef) {
421
+ const MenuItemDivider = /*#__PURE__*/forwardRef(function MenuItemDivider(_ref5, forwardRef) {
410
422
  let {
411
423
  className,
412
424
  ...rest
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Copyright IBM Corp. 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, { ComponentProps, ReactNode } from 'react';
8
+ export interface MenuButtonProps extends ComponentProps<'div'> {
9
+ /**
10
+ * A collection of MenuItems to be rendered as actions for this MenuButton.
11
+ */
12
+ children?: ReactNode;
13
+ /**
14
+ * Additional CSS class names.
15
+ */
16
+ className?: string;
17
+ /**
18
+ * Specify whether the MenuButton should be disabled, or not.
19
+ */
20
+ disabled?: boolean;
21
+ /**
22
+ * Specify the type of button to be used as the base for the trigger button.
23
+ */
24
+ kind?: 'primary' | 'tertiary' | 'ghost';
25
+ /**
26
+ * Provide the label to be rendered on the trigger button.
27
+ */
28
+ label: string;
29
+ /**
30
+ * Experimental property. Specify how the menu should align with the button element
31
+ */
32
+ menuAlignment: 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end';
33
+ /**
34
+ * Specify the size of the button and menu.
35
+ */
36
+ size?: 'sm' | 'md' | 'lg';
37
+ /**
38
+ * Specify the tabIndex of the button.
39
+ */
40
+ tabIndex?: number;
41
+ }
42
+ declare const MenuButton: React.ForwardRefExoticComponent<Omit<MenuButtonProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
43
+ export { MenuButton };