@carbon/react 1.51.1 → 1.52.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 +832 -785
  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
@@ -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 } from 'react';
11
+ import React__default, { forwardRef, useContext } from 'react';
12
12
  import Link, { LinkPropTypes } from './Link.js';
13
13
  import SideNavIcon from './SideNavIcon.js';
14
14
  import SideNavItem from './SideNavItem.js';
@@ -16,7 +16,7 @@ import SideNavLinkText from './SideNavLinkText.js';
16
16
  import { usePrefix } from '../../internal/usePrefix.js';
17
17
  import { SideNavContext } from './SideNav.js';
18
18
 
19
- const SideNavLink = /*#__PURE__*/React__default.forwardRef(function SideNavLink(_ref, ref) {
19
+ const SideNavLink = /*#__PURE__*/forwardRef(function SideNavLink(_ref, ref) {
20
20
  let {
21
21
  children,
22
22
  className: customClassName,
@@ -71,12 +71,12 @@ SideNavLink.propTypes = {
71
71
  /**
72
72
  * Provide an icon to render in the side navigation link. Should be a React class.
73
73
  */
74
+ // @ts-expect-error - PropTypes are unable to cover this case.
74
75
  renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
75
76
  /**
76
77
  * Optional prop to specify the tabIndex of the button. If undefined, it will be applied default validation
77
78
  */
78
79
  tabIndex: PropTypes.number
79
80
  };
80
- var SideNavLink$1 = SideNavLink;
81
81
 
82
- export { SideNavLink$1 as default };
82
+ export { SideNavLink as default };
@@ -0,0 +1,45 @@
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 { MouseEventHandler } from 'react';
8
+ /**
9
+ * Array of two numbers either representing [left, right] or [top, bottom].
10
+ */
11
+ type TwoCoordinates = [number, number];
12
+ export interface UseAttachedMenuReturn {
13
+ /**
14
+ * Whether the menu is open or not.
15
+ */
16
+ open: boolean;
17
+ /**
18
+ * The x position of the menu.
19
+ */
20
+ x: TwoCoordinates;
21
+ /**
22
+ * The y position of the menu.
23
+ */
24
+ y: TwoCoordinates;
25
+ /**
26
+ * A function to be called when the trigger element receives a click event.
27
+ */
28
+ handleClick: () => void;
29
+ /**
30
+ * A function to be called when the trigger element receives a mousedown event.
31
+ */
32
+ handleMousedown: MouseEventHandler;
33
+ /**
34
+ * A function to be called when the menu emits onClose.
35
+ */
36
+ handleClose: () => void;
37
+ }
38
+ /**
39
+ * This hook contains common code to be used when a menu should be visually attached to an anchor based on a click event.
40
+ *
41
+ * @param {Element|object} anchor The element or ref the menu should visually be attached to.
42
+ * @returns {useAttachedMenuReturn}
43
+ */
44
+ export declare function useAttachedMenu(anchor: any): UseAttachedMenuReturn;
45
+ export {};
@@ -8,13 +8,7 @@
8
8
  import { useState } from 'react';
9
9
 
10
10
  /**
11
- * @typedef {object} useAttachedMenuReturn
12
- * @property {boolean} open Whether the menu is open or not
13
- * @property {[number, number]} x The x position of the menu
14
- * @property {[number, number]} y The y position of the menu
15
- * @property {Function} handleClick A function to be called when the trigger element receives a click event
16
- * @property {Function} handleMousedown A function to be called when the trigger element recives a mousedown event
17
- * @property {Function} handleClose A function to be called when the menu emits onClose
11
+ * Array of two numbers either representing [left, right] or [top, bottom].
18
12
  */
19
13
 
20
14
  /**
@@ -0,0 +1,20 @@
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 { ReactAttr } from '../types/common';
9
+ type HTMLTagName = keyof HTMLElementTagNameMap;
10
+ type WrapComponentArgs<T extends HTMLTagName> = {
11
+ name: string;
12
+ type: T;
13
+ className?: string | ((prefix: string) => string);
14
+ };
15
+ /**
16
+ * @param {{ name: string, type: string, className?: string | (prefix: string) => string }} props
17
+ * @returns
18
+ */
19
+ declare const wrapComponent: <T extends keyof HTMLElementTagNameMap>({ name, className: getClassName, type, }: WrapComponentArgs<T>) => (props: ReactAttr<T>) => React.ReactElement;
20
+ export default wrapComponent;
@@ -5,9 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import React__default from 'react';
9
- import PropTypes from 'prop-types';
10
8
  import cx from 'classnames';
9
+ import PropTypes from 'prop-types';
10
+ import React__default from 'react';
11
11
  import { usePrefix } from '../internal/usePrefix.js';
12
12
 
13
13
  /**
@@ -46,6 +46,5 @@ const wrapComponent = _ref => {
46
46
  };
47
47
  return Component;
48
48
  };
49
- var wrapComponent$1 = wrapComponent;
50
49
 
51
- export { wrapComponent$1 as default };
50
+ export { wrapComponent as default };
@@ -126,7 +126,7 @@ const ComposedModal = /*#__PURE__*/React__default["default"].forwardRef(function
126
126
  const startSentinel = React.useRef(null);
127
127
  const endSentinel = React.useRef(null);
128
128
 
129
- // Kepp track of modal open/close state
129
+ // Keep track of modal open/close state
130
130
  // and propagate it to the document.body
131
131
  React.useEffect(() => {
132
132
  if (open !== wasOpen) {
@@ -143,12 +143,14 @@ const ComposedModal = /*#__PURE__*/React__default["default"].forwardRef(function
143
143
  }, []); // eslint-disable-line react-hooks/exhaustive-deps
144
144
 
145
145
  function handleKeyDown(evt) {
146
+ evt.stopPropagation();
146
147
  if (match.match(evt, keys.Escape)) {
147
148
  closeModal(evt);
148
149
  }
149
150
  onKeyDown?.(evt);
150
151
  }
151
152
  function handleMousedown(evt) {
153
+ evt.stopPropagation();
152
154
  const isInside = innerModal.current?.contains(evt.target);
153
155
  if (!isInside && !preventCloseOnClickOutside) {
154
156
  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;
@@ -16,6 +16,5 @@ const TableActionList = wrapComponent["default"]({
16
16
  type: 'div',
17
17
  className: prefix => `${prefix}--action-list`
18
18
  });
19
- var TableActionList$1 = TableActionList;
20
19
 
21
- exports["default"] = TableActionList$1;
20
+ exports["default"] = TableActionList;
@@ -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;
@@ -70,7 +70,7 @@ Link.propTypes = {
70
70
  * Provide a custom element or component to render the top-level node for the
71
71
  * component.
72
72
  */
73
- as: PropTypes__default["default"].string,
73
+ as: PropTypes__default["default"].elementType,
74
74
  /**
75
75
  * Provide the content for the Link
76
76
  */
@@ -95,7 +95,6 @@ Link.propTypes = {
95
95
  * Optional prop to render an icon next to the link.
96
96
  * Can be a React component class
97
97
  */
98
- // @ts-expect-error - PropTypes are unable to cover this case.
99
98
  renderIcon: PropTypes__default["default"].oneOfType([PropTypes__default["default"].func, PropTypes__default["default"].object]),
100
99
  /**
101
100
  * 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 };
@@ -30,7 +30,7 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
30
30
 
31
31
  const spacing = 8; // distance to keep to window edges, in px
32
32
 
33
- const Menu = /*#__PURE__*/React__default["default"].forwardRef(function Menu(_ref, forwardRef) {
33
+ const Menu = /*#__PURE__*/React.forwardRef(function Menu(_ref, forwardRef) {
34
34
  let {
35
35
  children,
36
36
  className,
@@ -82,7 +82,7 @@ const Menu = /*#__PURE__*/React__default["default"].forwardRef(function Menu(_re
82
82
  actionButtonWidth = w;
83
83
  }
84
84
 
85
- // Set RTL based on document direction or `LayoutDirection`
85
+ // Set RTL based on the document direction or `LayoutDirection`
86
86
  const {
87
87
  direction
88
88
  } = useLayoutDirection.useLayoutDirection();
@@ -313,6 +313,7 @@ Menu.propTypes = {
313
313
  /**
314
314
  * A label describing the Menu.
315
315
  */
316
+ // @ts-ignore-next-line -- avoid spurious (?) TS2322 error
316
317
  label: PropTypes__default["default"].string,
317
318
  /**
318
319
  * Specify how the menu should align with the button element
@@ -345,14 +346,17 @@ Menu.propTypes = {
345
346
  /**
346
347
  * Specify a DOM node where the Menu should be rendered in. Defaults to document.body.
347
348
  */
349
+ // @ts-ignore-next-line -- avoid spurious (?) TS2322 error
348
350
  target: PropTypes__default["default"].object,
349
351
  /**
350
352
  * 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])
351
353
  */
354
+ // @ts-ignore-next-line -- avoid spurious (?) TS2322 error
352
355
  x: PropTypes__default["default"].oneOfType([PropTypes__default["default"].number, PropTypes__default["default"].arrayOf(PropTypes__default["default"].number)]),
353
356
  /**
354
357
  * 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])
355
358
  */
359
+ // @ts-ignore-next-line -- avoid spurious (?) TS2322 error
356
360
  y: PropTypes__default["default"].oneOfType([PropTypes__default["default"].number, PropTypes__default["default"].arrayOf(PropTypes__default["default"].number)])
357
361
  };
358
362
 
@@ -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 };
@@ -11,10 +11,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
11
11
 
12
12
  var React = require('react');
13
13
 
14
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
-
16
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
17
-
18
14
  const menuDefaultState = {
19
15
  isRoot: true,
20
16
  mode: 'full',
@@ -37,10 +33,10 @@ function menuReducer(state, action) {
37
33
  };
38
34
  }
39
35
  }
40
- const MenuContext = /*#__PURE__*/React__default["default"].createContext({
36
+ const MenuContext = /*#__PURE__*/React.createContext({
41
37
  state: menuDefaultState,
42
38
  // 'dispatch' is populated by the root menu
43
- dispatch: () => {}
39
+ dispatch: _ => {}
44
40
  });
45
41
 
46
42
  exports.MenuContext = MenuContext;
@@ -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>>;