@carbon/react 1.51.0 → 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 (74) hide show
  1. package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +776 -729
  2. package/es/components/ChatButton/ChatButton.js +9 -1
  3. package/es/components/ComposedModal/ComposedModal.js +5 -4
  4. package/es/components/DataTable/TableActionList.d.ts +8 -0
  5. package/es/components/DataTable/TableActionList.js +1 -2
  6. package/es/components/DataTable/TableHead.d.ts +2 -2
  7. package/es/components/DataTable/TableToolbarContent.d.ts +1 -12
  8. package/es/components/Dropdown/Dropdown.d.ts +1 -1
  9. package/es/components/Link/Link.d.ts +5 -10
  10. package/es/components/Link/Link.js +1 -2
  11. package/es/components/Menu/Menu.d.ts +6 -6
  12. package/es/components/Menu/Menu.js +7 -3
  13. package/es/components/Menu/MenuContext.d.ts +14 -6
  14. package/es/components/Menu/MenuContext.js +3 -3
  15. package/es/components/Menu/MenuItem.d.ts +22 -31
  16. package/es/components/Menu/MenuItem.js +25 -13
  17. package/es/components/MenuButton/index.d.ts +43 -0
  18. package/es/components/MenuButton/index.js +15 -10
  19. package/es/components/Modal/Modal.js +2 -1
  20. package/es/components/Notification/Notification.d.ts +17 -1
  21. package/es/components/Notification/Notification.js +24 -9
  22. package/es/components/Toggletip/index.d.ts +1 -1
  23. package/es/components/Toggletip/index.js +4 -3
  24. package/es/components/TreeView/TreeNode.js +46 -24
  25. package/es/components/TreeView/TreeView.js +40 -13
  26. package/es/components/UIShell/Header.d.ts +24 -0
  27. package/es/components/UIShell/Header.js +1 -2
  28. package/es/components/UIShell/HeaderGlobalAction.d.ts +50 -0
  29. package/es/components/UIShell/HeaderGlobalAction.js +1 -2
  30. package/es/components/UIShell/HeaderGlobalBar.d.ts +11 -0
  31. package/es/components/UIShell/HeaderGlobalBar.js +2 -1
  32. package/es/components/UIShell/SideNavLink.d.ts +57 -0
  33. package/es/components/UIShell/SideNavLink.js +4 -4
  34. package/es/internal/useAttachedMenu.d.ts +45 -0
  35. package/es/internal/useAttachedMenu.js +1 -7
  36. package/es/tools/wrapComponent.d.ts +20 -0
  37. package/es/tools/wrapComponent.js +3 -4
  38. package/lib/components/ChatButton/ChatButton.js +9 -1
  39. package/lib/components/ComposedModal/ComposedModal.js +5 -4
  40. package/lib/components/DataTable/TableActionList.d.ts +8 -0
  41. package/lib/components/DataTable/TableActionList.js +1 -2
  42. package/lib/components/DataTable/TableHead.d.ts +2 -2
  43. package/lib/components/DataTable/TableToolbarContent.d.ts +1 -12
  44. package/lib/components/Dropdown/Dropdown.d.ts +1 -1
  45. package/lib/components/Link/Link.d.ts +5 -10
  46. package/lib/components/Link/Link.js +1 -2
  47. package/lib/components/Menu/Menu.d.ts +6 -6
  48. package/lib/components/Menu/Menu.js +6 -2
  49. package/lib/components/Menu/MenuContext.d.ts +14 -6
  50. package/lib/components/Menu/MenuContext.js +2 -6
  51. package/lib/components/Menu/MenuItem.d.ts +22 -31
  52. package/lib/components/Menu/MenuItem.js +24 -12
  53. package/lib/components/MenuButton/index.d.ts +43 -0
  54. package/lib/components/MenuButton/index.js +14 -9
  55. package/lib/components/Modal/Modal.js +2 -1
  56. package/lib/components/Notification/Notification.d.ts +17 -1
  57. package/lib/components/Notification/Notification.js +24 -9
  58. package/lib/components/Toggletip/index.d.ts +1 -1
  59. package/lib/components/Toggletip/index.js +4 -3
  60. package/lib/components/TreeView/TreeNode.js +46 -24
  61. package/lib/components/TreeView/TreeView.js +40 -13
  62. package/lib/components/UIShell/Header.d.ts +24 -0
  63. package/lib/components/UIShell/Header.js +1 -2
  64. package/lib/components/UIShell/HeaderGlobalAction.d.ts +50 -0
  65. package/lib/components/UIShell/HeaderGlobalAction.js +1 -2
  66. package/lib/components/UIShell/HeaderGlobalBar.d.ts +11 -0
  67. package/lib/components/UIShell/HeaderGlobalBar.js +2 -1
  68. package/lib/components/UIShell/SideNavLink.d.ts +57 -0
  69. package/lib/components/UIShell/SideNavLink.js +3 -3
  70. package/lib/internal/useAttachedMenu.d.ts +45 -0
  71. package/lib/internal/useAttachedMenu.js +1 -7
  72. package/lib/tools/wrapComponent.d.ts +20 -0
  73. package/lib/tools/wrapComponent.js +5 -6
  74. package/package.json +8 -8
@@ -15,6 +15,8 @@ var PropTypes = require('prop-types');
15
15
  var cx = require('classnames');
16
16
  var uniqueId = require('../../tools/uniqueId.js');
17
17
  var usePrefix = require('../../internal/usePrefix.js');
18
+ var useControllableState = require('../../internal/useControllableState.js');
19
+ var index = require('../FeatureFlags/index.js');
18
20
  var match = require('../../internal/keyboard/match.js');
19
21
  var keys = require('../../internal/keyboard/keys.js');
20
22
 
@@ -32,11 +34,13 @@ function TreeView(_ref) {
32
34
  hideLabel = false,
33
35
  label,
34
36
  multiselect = false,
37
+ onActivate,
35
38
  onSelect,
36
- selected: preselected = [],
39
+ selected: preselected,
37
40
  size = 'sm',
38
41
  ...rest
39
42
  } = _ref;
43
+ const enableTreeviewControllable = index.useFeatureFlag('enable-treeview-controllable');
40
44
  const {
41
45
  current: treeId
42
46
  } = React.useRef(rest.id || uniqueId["default"]());
@@ -46,8 +50,20 @@ function TreeView(_ref) {
46
50
  });
47
51
  const treeRootRef = React.useRef(null);
48
52
  const treeWalker = React.useRef(treeRootRef?.current);
49
- const [selected, setSelected] = React.useState(preselected);
50
- const [active, setActive] = React.useState(prespecifiedActive);
53
+ const controllableSelectionState = useControllableState.useControllableState({
54
+ value: preselected,
55
+ onChange: onSelect,
56
+ defaultValue: []
57
+ });
58
+ const uncontrollableSelectionState = React.useState(preselected ?? []);
59
+ const [selected, setSelected] = enableTreeviewControllable ? controllableSelectionState : uncontrollableSelectionState;
60
+ const controllableActiveState = useControllableState.useControllableState({
61
+ value: prespecifiedActive,
62
+ onChange: onActivate,
63
+ defaultValue: undefined
64
+ });
65
+ const uncontrollableActiveState = React.useState(prespecifiedActive);
66
+ const [active, setActive] = enableTreeviewControllable ? controllableActiveState : uncontrollableActiveState;
51
67
  function resetNodeTabIndices() {
52
68
  Array.prototype.forEach.call(treeRootRef?.current?.querySelectorAll('[tabIndex="0"]') ?? [], item => {
53
69
  item.tabIndex = -1;
@@ -64,14 +80,18 @@ function TreeView(_ref) {
64
80
  } else {
65
81
  setSelected(selected.filter(selectedId => selectedId !== nodeId));
66
82
  }
67
- onSelect?.(event, node);
83
+ if (!enableTreeviewControllable) {
84
+ onSelect?.(event, node);
85
+ }
68
86
  } else {
69
87
  setSelected([nodeId]);
70
88
  setActive(nodeId);
71
- onSelect?.(event, {
72
- activeNodeId: nodeId,
73
- ...node
74
- });
89
+ if (!enableTreeviewControllable) {
90
+ onSelect?.(event, {
91
+ activeNodeId: nodeId,
92
+ ...node
93
+ });
94
+ }
75
95
  }
76
96
  }
77
97
  function handleFocusEvent(event) {
@@ -177,11 +197,13 @@ function TreeView(_ref) {
177
197
  });
178
198
  }, [prefix]);
179
199
  const useActiveAndSelectedOnMount = () => React.useEffect(() => {
180
- if (preselected.length) {
181
- setSelected(preselected);
182
- }
183
- if (prespecifiedActive) {
184
- setActive(prespecifiedActive);
200
+ if (!enableTreeviewControllable) {
201
+ if (preselected?.length) {
202
+ setSelected(preselected);
203
+ }
204
+ if (prespecifiedActive) {
205
+ setActive(prespecifiedActive);
206
+ }
185
207
  }
186
208
  }, []);
187
209
  useActiveAndSelectedOnMount();
@@ -226,6 +248,11 @@ TreeView.propTypes = {
226
248
  * If `multiselect` is `false` then only one node can be selected at a time
227
249
  */
228
250
  multiselect: PropTypes__default["default"].bool,
251
+ /**
252
+ * **[Experimental]** Callback function that is called when any node is activated.
253
+ * *This is only supported with the `enable-treeview-controllable` feature flag!*
254
+ */
255
+ onActivate: PropTypes__default["default"].func,
229
256
  /**
230
257
  * Callback function that is called when any node is selected
231
258
  */
@@ -0,0 +1,24 @@
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, { ReactNode } from 'react';
8
+ interface HeaderProps {
9
+ children?: ReactNode;
10
+ /**
11
+ * Required props for the accessibility label of the header
12
+ */
13
+ 'aria-label'?: string;
14
+ /**
15
+ * Required props for the accessibility label of the header
16
+ */
17
+ 'aria-labelledby'?: string;
18
+ /**
19
+ * Optionally provide a custom class name that is applied to the underlying <header>
20
+ */
21
+ className?: string;
22
+ }
23
+ declare const Header: React.FC<HeaderProps>;
24
+ export default Header;
@@ -44,6 +44,5 @@ Header.propTypes = {
44
44
  */
45
45
  className: PropTypes__default["default"].string
46
46
  };
47
- var Header$1 = Header;
48
47
 
49
- exports["default"] = Header$1;
48
+ exports["default"] = Header;
@@ -0,0 +1,50 @@
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, { ReactNode } from 'react';
8
+ interface HeaderGlobalActionProps {
9
+ /**
10
+ * Required props for the accessibility label of the button
11
+ */
12
+ 'aria-label'?: string;
13
+ /**
14
+ * Required props for the accessibility label of the button
15
+ */
16
+ 'aria-labelledby'?: string;
17
+ /**
18
+ * Provide a custom icon for this global action
19
+ */
20
+ children: ReactNode;
21
+ /**
22
+ * Optionally provide a custom class name that is applied to the underlying
23
+ * button
24
+ */
25
+ className?: string;
26
+ /**
27
+ * Specify whether the action is currently active
28
+ */
29
+ isActive?: boolean;
30
+ /**
31
+ * Optionally provide an onClick handler that is called when the underlying
32
+ * button fires it's onclick event
33
+ */
34
+ onClick?: () => void;
35
+ /**
36
+ * Specify the alignment of the tooltip to the icon-only button.
37
+ * Can be one of: start, center, or end.
38
+ */
39
+ tooltipAlignment?: 'start' | 'center' | 'end';
40
+ }
41
+ /**
42
+ * HeaderGlobalAction is used as a part of the `HeaderGlobalBar`. It is
43
+ * essentially an Icon Button with an additional state to indicate whether it is
44
+ * "active". The active state comes from when a user clicks on the global action
45
+ * which should trigger a panel to appear.
46
+ *
47
+ * Note: children passed to this component should be an Icon.
48
+ */
49
+ declare const HeaderGlobalAction: React.FC<HeaderGlobalActionProps>;
50
+ export default HeaderGlobalAction;
@@ -94,6 +94,5 @@ HeaderGlobalAction.propTypes = {
94
94
  tooltipAlignment: PropTypes__default["default"].oneOf(['start', 'center', 'end'])
95
95
  };
96
96
  HeaderGlobalAction.displayName = 'HeaderGlobalAction';
97
- var HeaderGlobalAction$1 = HeaderGlobalAction;
98
97
 
99
- exports["default"] = HeaderGlobalAction$1;
98
+ exports["default"] = HeaderGlobalAction;
@@ -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
+ /**
8
+ * Generic container for `HeaderGlobalAction` components
9
+ */
10
+ declare const HeaderGlobalBar: (props: import("../../types/common").ReactAttr<"div">) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
11
+ export default HeaderGlobalBar;
@@ -14,7 +14,8 @@ var wrapComponent = require('../../tools/wrapComponent.js');
14
14
  /**
15
15
  * Generic container for `HeaderGlobalAction` components
16
16
  */
17
- var HeaderGlobalBar = wrapComponent["default"]({
17
+
18
+ const HeaderGlobalBar = wrapComponent["default"]({
18
19
  name: 'HeaderGlobalBar',
19
20
  className: prefix => `${prefix}--header__global`,
20
21
  type: 'div'
@@ -0,0 +1,57 @@
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 { ComponentType, ElementType, ForwardedRef, ReactNode, WeakValidationMap } from 'react';
8
+ import { LinkProps } from './Link';
9
+ export type SideNavLinkProps<E extends ElementType> = LinkProps<E> & {
10
+ /**
11
+ * Required props for the accessibility label
12
+ */
13
+ 'aria-label'?: string;
14
+ /**
15
+ * Required props for the accessibility label
16
+ */
17
+ 'aria-labelledby'?: string;
18
+ /**
19
+ * Specify the text content for the link
20
+ */
21
+ children: ReactNode;
22
+ /**
23
+ * Provide an optional class to be applied to the containing node
24
+ */
25
+ className?: string;
26
+ /**
27
+ * Specify whether the link is the current page
28
+ */
29
+ isActive?: boolean;
30
+ /**
31
+ * Property to indicate if the side nav container is open (or not). Use to
32
+ * keep local state and styling in step with the SideNav expansion state.
33
+ */
34
+ isSideNavExpanded?: boolean;
35
+ /**
36
+ * Specify if this is a large variation of the SideNavLink
37
+ */
38
+ large?: boolean;
39
+ /**
40
+ * Provide an icon to render in the side navigation link. Should be a React class.
41
+ */
42
+ renderIcon?: ComponentType;
43
+ /**
44
+ * Optional prop to specify the tabIndex of the button. If undefined, it will be applied default validation
45
+ */
46
+ tabIndex?: number;
47
+ };
48
+ export interface SideNavLinkComponent {
49
+ <E extends ElementType = 'a'>(props: SideNavLinkProps<E> & {
50
+ ref?: ForwardedRef<ElementType>;
51
+ }): JSX.Element | null;
52
+ displayName?: string;
53
+ propTypes?: WeakValidationMap<SideNavLinkProps<any>>;
54
+ }
55
+ declare const SideNavLink: SideNavLinkComponent;
56
+ export declare const createCustomSideNavLink: (element: any) => (props: any) => import("react/jsx-runtime").JSX.Element;
57
+ export default SideNavLink;
@@ -26,7 +26,7 @@ var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
26
26
  var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
27
27
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
28
28
 
29
- const SideNavLink = /*#__PURE__*/React__default["default"].forwardRef(function SideNavLink(_ref, ref) {
29
+ const SideNavLink = /*#__PURE__*/React.forwardRef(function SideNavLink(_ref, ref) {
30
30
  let {
31
31
  children,
32
32
  className: customClassName,
@@ -81,12 +81,12 @@ SideNavLink.propTypes = {
81
81
  /**
82
82
  * Provide an icon to render in the side navigation link. Should be a React class.
83
83
  */
84
+ // @ts-expect-error - PropTypes are unable to cover this case.
84
85
  renderIcon: PropTypes__default["default"].oneOfType([PropTypes__default["default"].func, PropTypes__default["default"].object]),
85
86
  /**
86
87
  * Optional prop to specify the tabIndex of the button. If undefined, it will be applied default validation
87
88
  */
88
89
  tabIndex: PropTypes__default["default"].number
89
90
  };
90
- var SideNavLink$1 = SideNavLink;
91
91
 
92
- exports["default"] = SideNavLink$1;
92
+ exports["default"] = SideNavLink;
@@ -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 {};
@@ -12,13 +12,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
12
12
  var React = require('react');
13
13
 
14
14
  /**
15
- * @typedef {object} useAttachedMenuReturn
16
- * @property {boolean} open Whether the menu is open or not
17
- * @property {[number, number]} x The x position of the menu
18
- * @property {[number, number]} y The y position of the menu
19
- * @property {Function} handleClick A function to be called when the trigger element receives a click event
20
- * @property {Function} handleMousedown A function to be called when the trigger element recives a mousedown event
21
- * @property {Function} handleClose A function to be called when the menu emits onClose
15
+ * Array of two numbers either representing [left, right] or [top, bottom].
22
16
  */
23
17
 
24
18
  /**
@@ -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;
@@ -9,16 +9,16 @@
9
9
 
10
10
  Object.defineProperty(exports, '__esModule', { value: true });
11
11
 
12
- var React = require('react');
13
- var PropTypes = require('prop-types');
14
12
  var cx = require('classnames');
13
+ var PropTypes = require('prop-types');
14
+ var React = require('react');
15
15
  var usePrefix = require('../internal/usePrefix.js');
16
16
 
17
17
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
18
 
19
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
20
- var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
21
19
  var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
20
+ var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
21
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
22
22
 
23
23
  /**
24
24
  * @param {{ name: string, type: string, className?: string | (prefix: string) => string }} props
@@ -56,6 +56,5 @@ const wrapComponent = _ref => {
56
56
  };
57
57
  return Component;
58
58
  };
59
- var wrapComponent$1 = wrapComponent;
60
59
 
61
- exports["default"] = wrapComponent$1;
60
+ exports["default"] = wrapComponent;
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.51.0",
4
+ "version": "1.52.0-rc.0",
5
5
  "license": "Apache-2.0",
6
6
  "main": "lib/index.js",
7
7
  "module": "es/index.js",
@@ -48,15 +48,15 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@babel/runtime": "^7.18.3",
51
- "@carbon/feature-flags": "^0.16.0",
52
- "@carbon/icons-react": "^11.36.0",
51
+ "@carbon/feature-flags": "^0.17.0-rc.0",
52
+ "@carbon/icons-react": "^11.37.0-rc.0",
53
53
  "@carbon/layout": "^11.20.0",
54
- "@carbon/styles": "^1.51.0",
55
- "@ibm/telemetry-js": "^1.2.0",
54
+ "@carbon/styles": "^1.52.0-rc.0",
55
+ "@ibm/telemetry-js": "^1.2.1",
56
56
  "classnames": "2.5.1",
57
57
  "copy-to-clipboard": "^3.3.1",
58
58
  "downshift": "8.3.1",
59
- "flatpickr": "4.6.9",
59
+ "flatpickr": "4.6.13",
60
60
  "invariant": "^2.2.3",
61
61
  "lodash.debounce": "^4.0.8",
62
62
  "lodash.findlast": "^4.5.0",
@@ -108,7 +108,7 @@
108
108
  "html-webpack-plugin": "^5.5.0",
109
109
  "mini-css-extract-plugin": "^2.4.5",
110
110
  "postcss": "^8.4.5",
111
- "postcss-loader": "^7.0.0",
111
+ "postcss-loader": "^8.0.0",
112
112
  "process": "^0.11.10",
113
113
  "prop-types": "^15.7.2",
114
114
  "react": "^18.2.0",
@@ -139,5 +139,5 @@
139
139
  "**/*.scss",
140
140
  "**/*.css"
141
141
  ],
142
- "gitHead": "957667fa7f197b544f6cb336814daa7074daaaee"
142
+ "gitHead": "be0fb52e96855034df55e03f8bc281fc38ef606c"
143
143
  }