@carbon/react 1.24.0-rc.0 → 1.25.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 (151) hide show
  1. package/es/components/CodeSnippet/CodeSnippet.js +13 -115
  2. package/es/components/ComboBox/ComboBox.d.ts +6 -0
  3. package/es/components/ComboBox/ComboBox.js +19 -172
  4. package/es/components/ComboButton/index.js +164 -0
  5. package/es/components/ComposedModal/ComposedModal.js +1 -2
  6. package/es/components/DataTable/TableToolbar.d.ts +19 -0
  7. package/es/components/DataTable/TableToolbar.js +1 -1
  8. package/es/components/DataTable/TableToolbarAction.d.ts +21 -0
  9. package/es/components/DataTable/TableToolbarContent.d.ts +21 -0
  10. package/es/components/DataTable/TableToolbarMenu.d.ts +24 -0
  11. package/es/components/DataTable/TableToolbarMenu.js +3 -3
  12. package/es/components/DataTable/tools/sorting.js +2 -1
  13. package/es/components/DataTableSkeleton/DataTableSkeleton.d.ts +107 -0
  14. package/es/components/Dropdown/Dropdown.d.ts +6 -0
  15. package/es/components/Dropdown/Dropdown.js +8 -145
  16. package/es/components/FileUploader/FileUploader.js +1 -1
  17. package/es/components/FileUploader/FileUploaderDropContainer.js +30 -18
  18. package/es/components/FileUploader/FileUploaderItem.js +2 -1
  19. package/es/components/FileUploader/Filename.js +8 -2
  20. package/es/components/FluidTextArea/FluidTextArea.js +12 -1
  21. package/es/components/IconButton/index.js +1 -0
  22. package/es/components/ListBox/ListBoxMenuItem.d.ts +2 -2
  23. package/es/components/ListBox/ListBoxSelection.js +4 -23
  24. package/es/components/ListBox/next/ListBoxSelection.js +2 -23
  25. package/es/components/Menu/Menu.js +50 -33
  26. package/es/components/Menu/MenuContext.js +3 -6
  27. package/es/components/Menu/MenuItem.js +1 -0
  28. package/es/components/MenuButton/index.js +127 -0
  29. package/es/components/Modal/Modal.js +4 -3
  30. package/es/components/MultiSelect/FilterableMultiSelect.js +31 -137
  31. package/es/components/MultiSelect/MultiSelect.d.ts +1 -1
  32. package/es/components/MultiSelect/MultiSelect.js +48 -26
  33. package/es/components/Notification/Notification.js +27 -264
  34. package/es/components/OverflowMenu/OverflowMenu.js +13 -139
  35. package/es/components/OverflowMenuItem/OverflowMenuItem.d.ts +58 -0
  36. package/es/components/OverflowMenuItem/OverflowMenuItem.js +12 -7
  37. package/es/components/OverflowMenuV2/index.js +15 -51
  38. package/es/components/Popover/index.d.ts +55 -0
  39. package/es/components/Popover/index.js +61 -29
  40. package/es/components/RadioButtonGroup/RadioButtonGroup.js +7 -4
  41. package/es/components/RadioTile/RadioTile.js +6 -6
  42. package/es/components/Select/Select.d.ts +89 -0
  43. package/es/components/SelectItem/SelectItem.d.ts +62 -0
  44. package/es/components/SelectItem/SelectItem.js +2 -4
  45. package/es/components/SelectItemGroup/SelectItemGroup.d.ts +52 -0
  46. package/es/components/SkeletonText/SkeletonText.js +1 -1
  47. package/es/components/Slider/Slider.Skeleton.d.ts +2 -2
  48. package/es/components/Slider/Slider.d.ts +355 -0
  49. package/es/components/Slider/Slider.js +63 -35
  50. package/es/components/StructuredList/StructuredList.js +10 -38
  51. package/es/components/Tabs/Tabs.js +3 -1
  52. package/es/components/TextArea/TextArea.Skeleton.d.ts +33 -0
  53. package/es/components/TextArea/TextArea.Skeleton.js +5 -5
  54. package/es/components/TextArea/TextArea.d.ts +9 -2
  55. package/es/components/TextArea/TextArea.js +31 -8
  56. package/es/components/TextArea/index.js +1 -0
  57. package/es/components/TextInput/TextInput.d.ts +106 -0
  58. package/es/components/TextInput/TextInput.js +3 -2
  59. package/es/components/Toggle/Toggle.js +8 -19
  60. package/es/components/Tooltip/DefinitionTooltip.d.ts +52 -0
  61. package/es/components/Tooltip/DefinitionTooltip.js +2 -2
  62. package/es/components/Tooltip/Tooltip.d.ts +117 -0
  63. package/es/components/Tooltip/Tooltip.js +6 -4
  64. package/es/components/Tooltip/index.d.ts +9 -0
  65. package/es/index.d.ts +2 -0
  66. package/es/index.js +5 -3
  67. package/es/internal/ClickListener.js +1 -2
  68. package/es/internal/keyboard/match.js +1 -1
  69. package/es/internal/useAttachedMenu.js +85 -0
  70. package/es/internal/useDelayedState.d.ts +19 -0
  71. package/es/internal/useDelayedState.js +7 -3
  72. package/es/internal/useId.js +1 -1
  73. package/es/internal/useMergedRefs.d.ts +13 -0
  74. package/es/internal/useMergedRefs.js +2 -5
  75. package/es/internal/useNormalizedInputProps.js +1 -0
  76. package/lib/components/CodeSnippet/CodeSnippet.js +13 -115
  77. package/lib/components/ComboBox/ComboBox.d.ts +6 -0
  78. package/lib/components/ComboBox/ComboBox.js +18 -171
  79. package/lib/components/ComboButton/index.js +174 -0
  80. package/lib/components/ComposedModal/ComposedModal.js +1 -2
  81. package/lib/components/DataTable/TableToolbar.d.ts +19 -0
  82. package/lib/components/DataTable/TableToolbar.js +1 -1
  83. package/lib/components/DataTable/TableToolbarAction.d.ts +21 -0
  84. package/lib/components/DataTable/TableToolbarContent.d.ts +21 -0
  85. package/lib/components/DataTable/TableToolbarMenu.d.ts +24 -0
  86. package/lib/components/DataTable/TableToolbarMenu.js +3 -3
  87. package/lib/components/DataTable/tools/sorting.js +2 -1
  88. package/lib/components/DataTableSkeleton/DataTableSkeleton.d.ts +107 -0
  89. package/lib/components/Dropdown/Dropdown.d.ts +6 -0
  90. package/lib/components/Dropdown/Dropdown.js +7 -144
  91. package/lib/components/FileUploader/FileUploader.js +1 -1
  92. package/lib/components/FileUploader/FileUploaderDropContainer.js +30 -18
  93. package/lib/components/FileUploader/FileUploaderItem.js +2 -1
  94. package/lib/components/FileUploader/Filename.js +8 -2
  95. package/lib/components/FluidTextArea/FluidTextArea.js +12 -1
  96. package/lib/components/IconButton/index.js +1 -0
  97. package/lib/components/ListBox/ListBoxMenuItem.d.ts +2 -2
  98. package/lib/components/ListBox/ListBoxSelection.js +4 -23
  99. package/lib/components/ListBox/next/ListBoxSelection.js +2 -23
  100. package/lib/components/Menu/Menu.js +50 -33
  101. package/lib/components/Menu/MenuContext.js +3 -6
  102. package/lib/components/Menu/MenuItem.js +1 -0
  103. package/lib/components/MenuButton/index.js +137 -0
  104. package/lib/components/Modal/Modal.js +4 -3
  105. package/lib/components/MultiSelect/FilterableMultiSelect.js +29 -135
  106. package/lib/components/MultiSelect/MultiSelect.d.ts +1 -1
  107. package/lib/components/MultiSelect/MultiSelect.js +47 -25
  108. package/lib/components/Notification/Notification.js +27 -264
  109. package/lib/components/OverflowMenu/OverflowMenu.js +13 -139
  110. package/lib/components/OverflowMenuItem/OverflowMenuItem.d.ts +58 -0
  111. package/lib/components/OverflowMenuItem/OverflowMenuItem.js +12 -7
  112. package/lib/components/OverflowMenuV2/index.js +13 -49
  113. package/lib/components/Popover/index.d.ts +55 -0
  114. package/lib/components/Popover/index.js +61 -29
  115. package/lib/components/RadioButtonGroup/RadioButtonGroup.js +6 -3
  116. package/lib/components/RadioTile/RadioTile.js +6 -6
  117. package/lib/components/Select/Select.d.ts +89 -0
  118. package/lib/components/SelectItem/SelectItem.d.ts +62 -0
  119. package/lib/components/SelectItem/SelectItem.js +1 -3
  120. package/lib/components/SelectItemGroup/SelectItemGroup.d.ts +52 -0
  121. package/lib/components/SkeletonText/SkeletonText.js +1 -1
  122. package/lib/components/Slider/Slider.Skeleton.d.ts +2 -2
  123. package/lib/components/Slider/Slider.d.ts +355 -0
  124. package/lib/components/Slider/Slider.js +62 -34
  125. package/lib/components/StructuredList/StructuredList.js +10 -38
  126. package/lib/components/Tabs/Tabs.js +3 -1
  127. package/lib/components/TextArea/TextArea.Skeleton.d.ts +33 -0
  128. package/lib/components/TextArea/TextArea.Skeleton.js +5 -5
  129. package/lib/components/TextArea/TextArea.d.ts +9 -2
  130. package/lib/components/TextArea/TextArea.js +30 -7
  131. package/lib/components/TextArea/index.js +2 -0
  132. package/lib/components/TextInput/TextInput.d.ts +106 -0
  133. package/lib/components/TextInput/TextInput.js +3 -2
  134. package/lib/components/Toggle/Toggle.js +8 -19
  135. package/lib/components/Tooltip/DefinitionTooltip.d.ts +52 -0
  136. package/lib/components/Tooltip/DefinitionTooltip.js +2 -2
  137. package/lib/components/Tooltip/Tooltip.d.ts +117 -0
  138. package/lib/components/Tooltip/Tooltip.js +6 -4
  139. package/lib/components/Tooltip/index.d.ts +9 -0
  140. package/lib/index.d.ts +2 -0
  141. package/lib/index.js +50 -46
  142. package/lib/internal/ClickListener.js +1 -2
  143. package/lib/internal/keyboard/match.js +1 -1
  144. package/lib/internal/useAttachedMenu.js +89 -0
  145. package/lib/internal/useDelayedState.d.ts +19 -0
  146. package/lib/internal/useDelayedState.js +7 -3
  147. package/lib/internal/useId.js +1 -1
  148. package/lib/internal/useMergedRefs.d.ts +13 -0
  149. package/lib/internal/useMergedRefs.js +2 -5
  150. package/lib/internal/useNormalizedInputProps.js +1 -0
  151. package/package.json +10 -10
@@ -20,9 +20,9 @@ import { IconButton } from '../IconButton/index.js';
20
20
  import { matches } from '../../internal/keyboard/match.js';
21
21
  import { ArrowUp, ArrowRight, ArrowDown, ArrowLeft, Escape } from '../../internal/keyboard/keys.js';
22
22
 
23
- var _excluded = ["id", "ariaLabel", "children", "iconDescription", "direction", "flipped", "focusTrap", "menuOffset", "menuOffsetFlip", "iconClass", "onClick", "onOpen", "selectorPrimaryFocus", "renderIcon", "innerRef", "menuOptionsClass", "light", "size"];
23
+ var _excluded = ["id", "aria-label", "ariaLabel", "children", "iconDescription", "direction", "flipped", "focusTrap", "menuOffset", "menuOffsetFlip", "iconClass", "onClick", "onOpen", "selectorPrimaryFocus", "renderIcon", "innerRef", "menuOptionsClass", "light", "size"];
24
24
 
25
- var _triggerButtonPositio, _triggerButtonPositio2;
25
+ var _triggerButtonPositio, _triggerButtonPositio2, _defineProperty2, _defineProperty3;
26
26
 
27
27
  var on = function on(element) {
28
28
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
@@ -288,7 +288,8 @@ var OverflowMenu = /*#__PURE__*/function (_Component) {
288
288
 
289
289
  var _this$props = this.props,
290
290
  id = _this$props.id,
291
- ariaLabel = _this$props.ariaLabel,
291
+ ariaLabel = _this$props['aria-label'],
292
+ deprecatedAriaLabel = _this$props.ariaLabel,
292
293
  children = _this$props.children,
293
294
  iconDescription = _this$props.iconDescription,
294
295
  direction = _this$props.direction,
@@ -328,7 +329,7 @@ var OverflowMenu = /*#__PURE__*/function (_Component) {
328
329
  className: overflowMenuOptionsClasses,
329
330
  tabIndex: "-1",
330
331
  role: "menu",
331
- "aria-label": ariaLabel,
332
+ "aria-label": ariaLabel || deprecatedAriaLabel,
332
333
  onKeyDown: this.handleKeyPress
333
334
  }, childrenWithProps);
334
335
  var wrappedMenuBody = /*#__PURE__*/React__default.createElement(FloatingMenu, {
@@ -378,144 +379,17 @@ var OverflowMenu = /*#__PURE__*/function (_Component) {
378
379
  return OverflowMenu;
379
380
  }(Component);
380
381
 
381
- _defineProperty(OverflowMenu, "propTypes", {
382
- /**
383
- * The ARIA label.
384
- */
385
- ariaLabel: PropTypes.string.isRequired,
386
-
387
- /**
388
- * The child nodes.
389
- */
390
- children: PropTypes.node,
391
-
392
- /**
393
- * The CSS class names.
394
- */
395
- className: PropTypes.string,
396
-
397
- /**
398
- * The menu direction.
399
- */
400
- direction: PropTypes.oneOf([DIRECTION_TOP, DIRECTION_BOTTOM]),
401
-
402
- /**
403
- * `true` if the menu alignment should be flipped.
404
- */
405
- flipped: PropTypes.bool,
406
-
407
- /**
408
- * Enable or disable focus trap behavior
409
- */
410
- focusTrap: PropTypes.bool,
411
-
412
- /**
413
- * The CSS class for the icon.
414
- */
415
- iconClass: PropTypes.string,
416
-
417
- /**
418
- * The icon description.
419
- */
420
- iconDescription: PropTypes.string.isRequired,
421
-
422
- /**
423
- * The element ID.
424
- */
425
- id: PropTypes.string,
426
-
427
- /**
428
- * `true` to use the light version. For use on $ui-01 backgrounds only.
429
- * Don't use this to make OverflowMenu background color same as container background color.
430
- */
431
- light: deprecate(PropTypes.bool, 'The `light` prop for `OverflowMenu` is no longer needed and has been deprecated. It will be removed in the next major release. Use the Layer component instead.'),
432
-
433
- /**
434
- * The adjustment in position applied to the floating menu.
435
- */
436
- menuOffset: PropTypes.oneOfType([PropTypes.shape({
437
- top: PropTypes.number,
438
- left: PropTypes.number
439
- }), PropTypes.func]),
440
-
441
- /**
442
- * The adjustment in position applied to the floating menu.
443
- */
444
- menuOffsetFlip: PropTypes.oneOfType([PropTypes.shape({
445
- top: PropTypes.number,
446
- left: PropTypes.number
447
- }), PropTypes.func]),
448
-
449
- /**
450
- * The class to apply to the menu options
451
- */
452
- menuOptionsClass: PropTypes.string,
453
-
454
- /**
455
- * The event handler for the `click` event.
456
- */
457
- onClick: PropTypes.func,
458
-
459
- /**
460
- * Function called when menu is closed
461
- */
462
- onClose: PropTypes.func,
463
-
464
- /**
465
- * The event handler for the `focus` event.
466
- */
467
- onFocus: PropTypes.func,
468
-
469
- /**
470
- * The event handler for the `keydown` event.
471
- */
472
- onKeyDown: PropTypes.func,
473
-
474
- /**
475
- * Function called when menu is opened
476
- */
477
- onOpen: PropTypes.func,
478
-
479
- /**
480
- * `true` if the menu should be open.
481
- */
482
- open: PropTypes.bool,
483
-
484
- /**
485
- * Function called to override icon rendering.
486
- */
487
- renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
488
-
489
- /**
490
- * Specify a CSS selector that matches the DOM element that should
491
- * be focused when the OverflowMenu opens
492
- */
493
- selectorPrimaryFocus: PropTypes.string,
494
-
495
- /**
496
- * Specify the size of the OverflowMenu. Currently supports either `sm`, 'md' (default) or 'lg` as an option.
497
- */
498
- size: PropTypes.oneOf(['sm', 'md', 'lg'])
499
- });
382
+ _defineProperty(OverflowMenu, "propTypes", (_defineProperty2 = {}, _defineProperty(_defineProperty2, 'aria-label', PropTypes.string), _defineProperty(_defineProperty2, "ariaLabel", deprecate(PropTypes.string, 'This prop syntax has been deprecated. Please use the new `aria-label`.')), _defineProperty(_defineProperty2, "children", PropTypes.node), _defineProperty(_defineProperty2, "className", PropTypes.string), _defineProperty(_defineProperty2, "direction", PropTypes.oneOf([DIRECTION_TOP, DIRECTION_BOTTOM])), _defineProperty(_defineProperty2, "flipped", PropTypes.bool), _defineProperty(_defineProperty2, "focusTrap", PropTypes.bool), _defineProperty(_defineProperty2, "iconClass", PropTypes.string), _defineProperty(_defineProperty2, "iconDescription", PropTypes.string.isRequired), _defineProperty(_defineProperty2, "id", PropTypes.string), _defineProperty(_defineProperty2, "light", deprecate(PropTypes.bool, 'The `light` prop for `OverflowMenu` is no longer needed and has been deprecated. It will be removed in the next major release. Use the Layer component instead.')), _defineProperty(_defineProperty2, "menuOffset", PropTypes.oneOfType([PropTypes.shape({
383
+ top: PropTypes.number,
384
+ left: PropTypes.number
385
+ }), PropTypes.func])), _defineProperty(_defineProperty2, "menuOffsetFlip", PropTypes.oneOfType([PropTypes.shape({
386
+ top: PropTypes.number,
387
+ left: PropTypes.number
388
+ }), PropTypes.func])), _defineProperty(_defineProperty2, "menuOptionsClass", PropTypes.string), _defineProperty(_defineProperty2, "onClick", PropTypes.func), _defineProperty(_defineProperty2, "onClose", PropTypes.func), _defineProperty(_defineProperty2, "onFocus", PropTypes.func), _defineProperty(_defineProperty2, "onKeyDown", PropTypes.func), _defineProperty(_defineProperty2, "onOpen", PropTypes.func), _defineProperty(_defineProperty2, "open", PropTypes.bool), _defineProperty(_defineProperty2, "renderIcon", PropTypes.oneOfType([PropTypes.func, PropTypes.object])), _defineProperty(_defineProperty2, "selectorPrimaryFocus", PropTypes.string), _defineProperty(_defineProperty2, "size", PropTypes.oneOf(['sm', 'md', 'lg'])), _defineProperty2));
500
389
 
501
390
  _defineProperty(OverflowMenu, "contextType", PrefixContext);
502
391
 
503
- _defineProperty(OverflowMenu, "defaultProps", {
504
- ariaLabel: null,
505
- iconDescription: 'Options',
506
- open: false,
507
- direction: DIRECTION_BOTTOM,
508
- flipped: false,
509
- focusTrap: true,
510
- renderIcon: OverflowMenuVertical,
511
- onClick: function onClick() {},
512
- onKeyDown: function onKeyDown() {},
513
- onClose: function onClose() {},
514
- onOpen: function onOpen() {},
515
- menuOffset: getMenuOffset,
516
- menuOffsetFlip: getMenuOffset,
517
- selectorPrimaryFocus: '[data-overflow-menu-primary-focus]'
518
- });
392
+ _defineProperty(OverflowMenu, "defaultProps", (_defineProperty3 = {}, _defineProperty(_defineProperty3, 'aria-label', null), _defineProperty(_defineProperty3, "iconDescription", 'Options'), _defineProperty(_defineProperty3, "open", false), _defineProperty(_defineProperty3, "direction", DIRECTION_BOTTOM), _defineProperty(_defineProperty3, "flipped", false), _defineProperty(_defineProperty3, "focusTrap", true), _defineProperty(_defineProperty3, "renderIcon", OverflowMenuVertical), _defineProperty(_defineProperty3, "onClick", function onClick() {}), _defineProperty(_defineProperty3, "onKeyDown", function onKeyDown() {}), _defineProperty(_defineProperty3, "onClose", function onClose() {}), _defineProperty(_defineProperty3, "onOpen", function onOpen() {}), _defineProperty(_defineProperty3, "menuOffset", getMenuOffset), _defineProperty(_defineProperty3, "menuOffsetFlip", getMenuOffset), _defineProperty(_defineProperty3, "selectorPrimaryFocus", '[data-overflow-menu-primary-focus]'), _defineProperty3));
519
393
  ((function () {
520
394
  var forwardRef = function forwardRef(props, ref) {
521
395
  return /*#__PURE__*/React__default.createElement(OverflowMenu, _extends({}, props, {
@@ -0,0 +1,58 @@
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 { ForwardRefReturn } from '../../types/common';
9
+ export interface OverflowMenuItemProps extends React.HTMLAttributes<HTMLElement> {
10
+ /**
11
+ * The CSS class name to be placed on the button element
12
+ */
13
+ className?: string;
14
+ /**
15
+ * A callback to tell the parent menu component that the menu should be closed.
16
+ */
17
+ closeMenu?: () => void;
18
+ /**
19
+ * `true` to make this menu item disabled.
20
+ */
21
+ disabled?: boolean;
22
+ handleOverflowMenuItemFocus?: (options: {
23
+ currentIndex?: number;
24
+ direction: number;
25
+ }) => void;
26
+ /**
27
+ * `true` to make this menu item a divider.
28
+ */
29
+ hasDivider?: boolean;
30
+ /**
31
+ * If given, overflow item will render as a link with the given href
32
+ */
33
+ href?: string;
34
+ index?: number;
35
+ /**
36
+ * The text to show for the menu item
37
+ */
38
+ itemText?: React.ReactNode;
39
+ /**
40
+ * `true` to make this menu item a danger button.
41
+ */
42
+ isDelete?: boolean;
43
+ /**
44
+ * `true` to require the title attribute.
45
+ */
46
+ requireTitle?: boolean;
47
+ /**
48
+ * The title attribute.
49
+ */
50
+ title?: string;
51
+ /**
52
+ * The CSS class name to be placed on the wrapper element
53
+ */
54
+ wrapperClassName?: string;
55
+ }
56
+ export type OverflowMenuItemComponent = ForwardRefReturn<HTMLElement, OverflowMenuItemProps>;
57
+ declare const OverflowMenuItem: OverflowMenuItemComponent;
58
+ export default OverflowMenuItem;
@@ -9,8 +9,8 @@ import { objectWithoutProperties as _objectWithoutProperties, defineProperty as
9
9
  import cx from 'classnames';
10
10
  import PropTypes from 'prop-types';
11
11
  import React__default from 'react';
12
- import { warning } from '../../internal/warning.js';
13
12
  import { usePrefix } from '../../internal/usePrefix.js';
13
+ import { warning } from '../../internal/warning.js';
14
14
  import { match } from '../../internal/keyboard/match.js';
15
15
  import { ArrowDown, ArrowUp } from '../../internal/keyboard/keys.js';
16
16
 
@@ -44,14 +44,14 @@ var OverflowMenuItem = /*#__PURE__*/React__default.forwardRef(function OverflowM
44
44
 
45
45
  function setTabFocus(evt) {
46
46
  if (match(evt, ArrowDown)) {
47
- handleOverflowMenuItemFocus({
47
+ handleOverflowMenuItemFocus === null || handleOverflowMenuItemFocus === void 0 ? void 0 : handleOverflowMenuItemFocus({
48
48
  currentIndex: index,
49
49
  direction: 1
50
50
  });
51
51
  }
52
52
 
53
53
  if (match(evt, ArrowUp)) {
54
- handleOverflowMenuItemFocus({
54
+ handleOverflowMenuItemFocus === null || handleOverflowMenuItemFocus === void 0 ? void 0 : handleOverflowMenuItemFocus({
55
55
  currentIndex: index,
56
56
  direction: -1
57
57
  });
@@ -91,17 +91,22 @@ var OverflowMenuItem = /*#__PURE__*/React__default.forwardRef(function OverflowM
91
91
  className: overflowMenuBtnClasses,
92
92
  disabled: disabled,
93
93
  href: href,
94
- index: index,
95
94
  onClick: handleClick,
96
95
  onKeyDown: function onKeyDown(evt) {
97
96
  setTabFocus(evt);
98
97
 
99
98
  _onKeyDown(evt);
100
99
  },
101
- role: "menuitem",
100
+ role: "menuitem" // ref as any: the type of `ref` is `ForwardedRef<HTMLButtonElement>` in `Button` component
101
+ // but `OverflowMenuItem` can be rendered as `a` tag as well, which is `HTMLAnchorElement`
102
+ // so we have to use `any` here
103
+ ,
102
104
  ref: ref,
103
- tabIndex: "-1",
104
- title: requireTitle ? title || itemText : null
105
+ tabIndex: -1 // itemText as any: itemText may be a ReactNode, but `title` only accepts string
106
+ // to avoid compatibility issue, we use `any` here. Consider to enforce `itemText` to be `string?`
107
+ // in the next major release
108
+ ,
109
+ title: requireTitle ? title || itemText : undefined
105
110
  }, rest), OverflowMenuItemContent));
106
111
  });
107
112
  OverflowMenuItem.propTypes = {
@@ -5,14 +5,15 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, defineProperty as _defineProperty, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React__default, { useState, useRef } from 'react';
8
+ import { objectWithoutProperties as _objectWithoutProperties, defineProperty as _defineProperty, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
+ import React__default, { useRef } from 'react';
10
10
  import PropTypes from 'prop-types';
11
11
  import cx from 'classnames';
12
12
  import { OverflowMenuVertical } from '@carbon/icons-react';
13
- import { useId } from '../../internal/useId.js';
14
13
  import { Menu } from '../Menu/Menu.js';
14
+ import { useId } from '../../internal/useId.js';
15
15
  import { usePrefix } from '../../internal/usePrefix.js';
16
+ import { useAttachedMenu } from '../../internal/useAttachedMenu.js';
16
17
 
17
18
  var _excluded = ["children", "className", "renderIcon", "size"];
18
19
  var defaultSize = 'md';
@@ -29,53 +30,16 @@ function OverflowMenuV2(_ref) {
29
30
  rest = _objectWithoutProperties(_ref, _excluded);
30
31
 
31
32
  var id = useId('overflowmenu');
32
-
33
- var _useState = useState(false),
34
- _useState2 = _slicedToArray(_useState, 2),
35
- open = _useState2[0],
36
- setOpen = _useState2[1];
37
-
38
- var _useState3 = useState([[0, 0], [0, 0]]),
39
- _useState4 = _slicedToArray(_useState3, 2),
40
- position = _useState4[0],
41
- setPosition = _useState4[1];
42
-
43
- var triggerRef = useRef(null);
44
33
  var prefix = usePrefix();
34
+ var triggerRef = useRef(null);
45
35
 
46
- function openMenu() {
47
- if (triggerRef.current) {
48
- var _triggerRef$current$g = triggerRef.current.getBoundingClientRect(),
49
- left = _triggerRef$current$g.left,
50
- top = _triggerRef$current$g.top,
51
- right = _triggerRef$current$g.right,
52
- bottom = _triggerRef$current$g.bottom;
53
-
54
- setPosition([[left, right], [top, bottom]]);
55
- }
56
-
57
- setOpen(true);
58
- }
59
-
60
- function closeMenu() {
61
- setOpen(false);
62
- }
63
-
64
- function handleClick() {
65
- if (open) {
66
- closeMenu();
67
- } else {
68
- openMenu();
69
- }
70
- }
71
-
72
- function handleMousedown(e) {
73
- // prevent default for mousedown on trigger element to avoid
74
- // the "blur" event from firing on the menu as this would close
75
- // it and immediately re-open since "click" event is fired after
76
- // "blur" event.
77
- e.preventDefault();
78
- }
36
+ var _useAttachedMenu = useAttachedMenu(triggerRef),
37
+ open = _useAttachedMenu.open,
38
+ x = _useAttachedMenu.x,
39
+ y = _useAttachedMenu.y,
40
+ handleClick = _useAttachedMenu.handleClick,
41
+ handleMousedown = _useAttachedMenu.handleMousedown,
42
+ handleClose = _useAttachedMenu.handleClose;
79
43
 
80
44
  var containerClasses = cx("".concat(prefix, "--overflow-menu__container"));
81
45
  var triggerClasses = cx("".concat(prefix, "--overflow-menu"), (_classNames = {}, _defineProperty(_classNames, "".concat(prefix, "--overflow-menu--open"), open), _defineProperty(_classNames, className, className), _classNames), size !== defaultSize && "".concat(prefix, "--overflow-menu--").concat(size));
@@ -96,9 +60,9 @@ function OverflowMenuV2(_ref) {
96
60
  id: id,
97
61
  size: size,
98
62
  open: open,
99
- onClose: closeMenu,
100
- x: position[0],
101
- y: position[1]
63
+ onClose: handleClose,
64
+ x: x,
65
+ y: y
102
66
  }, children));
103
67
  }
104
68
 
@@ -0,0 +1,55 @@
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 { PolymorphicProps } from '../../types/common';
9
+ export type PopoverAlignment = 'top' | 'top-left' | 'top-right' | 'bottom' | 'bottom-left' | 'bottom-right' | 'left' | 'left-bottom' | 'left-top' | 'right' | 'right-bottom' | 'right-top';
10
+ interface PopoverBaseProps {
11
+ /**
12
+ * Specify how the popover should align with the trigger element
13
+ */
14
+ align?: PopoverAlignment;
15
+ /**
16
+ * Will auto-align the popover on first render if it is not visible. This prop is currently experimental and is subject to future changes.
17
+ */
18
+ autoAlign?: boolean;
19
+ /**
20
+ * Specify whether a caret should be rendered
21
+ */
22
+ caret?: boolean;
23
+ /**
24
+ * Provide elements to be rendered inside of the component
25
+ */
26
+ children?: React.ReactNode;
27
+ /**
28
+ * Provide a custom class name to be added to the outermost node in the
29
+ * component
30
+ */
31
+ className?: string;
32
+ /**
33
+ * Specify whether a drop shadow should be rendered on the popover
34
+ */
35
+ dropShadow?: boolean;
36
+ /**
37
+ * Render the component using the high-contrast variant
38
+ */
39
+ highContrast?: boolean;
40
+ /**
41
+ * Render the component using the tab tip variant
42
+ */
43
+ isTabTip?: boolean;
44
+ /**
45
+ * Specify whether the component is currently open or closed
46
+ */
47
+ open: boolean;
48
+ }
49
+ export type PopoverProps<T extends React.ElementType> = PolymorphicProps<T, PopoverBaseProps>;
50
+ declare const Popover: React.ForwardRefExoticComponent<Pick<PopoverBaseProps & Omit<any, "as"> & {
51
+ as?: React.ElementType<any> | undefined;
52
+ }, string | number | symbol> & React.RefAttributes<Element>>;
53
+ export type PopoverContentProps = React.HTMLAttributes<HTMLSpanElement>;
54
+ declare const PopoverContent: React.ForwardRefExoticComponent<PopoverContentProps & React.RefAttributes<HTMLSpanElement>>;
55
+ export { Popover, PopoverContent };
@@ -13,41 +13,50 @@ import useIsomorphicEffect from '../../internal/useIsomorphicEffect.js';
13
13
  import { useMergedRefs } from '../../internal/useMergedRefs.js';
14
14
  import { usePrefix } from '../../internal/usePrefix.js';
15
15
 
16
- var _excluded = ["align", "as", "autoAlign", "caret", "className", "children", "dropShadow", "highContrast", "open"],
16
+ var _excluded = ["isTabTip", "align", "as", "autoAlign", "caret", "className", "children", "dropShadow", "highContrast", "open"],
17
17
  _excluded2 = ["className", "children"];
18
18
  var PopoverContext = /*#__PURE__*/React__default.createContext({
19
19
  floating: {
20
20
  current: null
21
21
  }
22
22
  });
23
- var Popover = /*#__PURE__*/React__default.forwardRef(function Popover(props, forwardRef) {
23
+ var Popover = /*#__PURE__*/React__default.forwardRef(function (_ref, forwardRef) {
24
24
  var _cx;
25
25
 
26
- var _props$align = props.align,
27
- align = _props$align === void 0 ? 'bottom' : _props$align,
28
- _props$as = props.as,
29
- BaseComponent = _props$as === void 0 ? 'span' : _props$as,
30
- _props$autoAlign = props.autoAlign,
31
- autoAlign = _props$autoAlign === void 0 ? false : _props$autoAlign,
32
- _props$caret = props.caret,
33
- caret = _props$caret === void 0 ? true : _props$caret,
34
- customClassName = props.className,
35
- children = props.children,
36
- _props$dropShadow = props.dropShadow,
37
- dropShadow = _props$dropShadow === void 0 ? true : _props$dropShadow,
38
- _props$highContrast = props.highContrast,
39
- highContrast = _props$highContrast === void 0 ? false : _props$highContrast,
40
- open = props.open,
41
- rest = _objectWithoutProperties(props, _excluded);
26
+ var isTabTip = _ref.isTabTip,
27
+ _ref$align = _ref.align,
28
+ align = _ref$align === void 0 ? isTabTip ? 'bottom-left' : 'bottom' : _ref$align,
29
+ as = _ref.as,
30
+ _ref$autoAlign = _ref.autoAlign,
31
+ autoAlign = _ref$autoAlign === void 0 ? false : _ref$autoAlign,
32
+ _ref$caret = _ref.caret,
33
+ caret = _ref$caret === void 0 ? isTabTip ? false : true : _ref$caret,
34
+ customClassName = _ref.className,
35
+ children = _ref.children,
36
+ _ref$dropShadow = _ref.dropShadow,
37
+ dropShadow = _ref$dropShadow === void 0 ? true : _ref$dropShadow,
38
+ _ref$highContrast = _ref.highContrast,
39
+ highContrast = _ref$highContrast === void 0 ? false : _ref$highContrast,
40
+ open = _ref.open,
41
+ rest = _objectWithoutProperties(_ref, _excluded);
42
42
 
43
43
  var prefix = usePrefix();
44
- var floating = useRef();
45
- var popover = useRef();
44
+ var floating = useRef(null);
45
+ var popover = useRef(null);
46
46
  var value = useMemo(function () {
47
47
  return {
48
48
  floating: floating
49
49
  };
50
50
  }, []);
51
+
52
+ if (isTabTip) {
53
+ var tabTipAlignments = ['bottom-left', 'bottom-right'];
54
+
55
+ if (!tabTipAlignments.includes(align)) {
56
+ align = 'bottom-left';
57
+ }
58
+ }
59
+
51
60
  var ref = useMergedRefs([forwardRef, popover]);
52
61
 
53
62
  var _useState = useState(false),
@@ -60,13 +69,13 @@ var Popover = /*#__PURE__*/React__default.forwardRef(function Popover(props, for
60
69
  autoAlignment = _useState4[0],
61
70
  setAutoAlignment = _useState4[1];
62
71
 
63
- var className = cx((_cx = {}, _defineProperty(_cx, "".concat(prefix, "--popover-container"), true), _defineProperty(_cx, "".concat(prefix, "--popover--caret"), caret), _defineProperty(_cx, "".concat(prefix, "--popover--drop-shadow"), dropShadow), _defineProperty(_cx, "".concat(prefix, "--popover--high-contrast"), highContrast), _defineProperty(_cx, "".concat(prefix, "--popover--open"), open), _defineProperty(_cx, "".concat(prefix, "--popover--").concat(autoAlignment), autoAligned), _defineProperty(_cx, "".concat(prefix, "--popover--").concat(align), !autoAligned), _defineProperty(_cx, customClassName, !!customClassName), _cx));
72
+ var className = cx((_cx = {}, _defineProperty(_cx, "".concat(prefix, "--popover-container"), true), _defineProperty(_cx, "".concat(prefix, "--popover--caret"), caret), _defineProperty(_cx, "".concat(prefix, "--popover--drop-shadow"), dropShadow), _defineProperty(_cx, "".concat(prefix, "--popover--high-contrast"), highContrast), _defineProperty(_cx, "".concat(prefix, "--popover--open"), open), _defineProperty(_cx, "".concat(prefix, "--popover--").concat(autoAlignment), autoAligned && !isTabTip), _defineProperty(_cx, "".concat(prefix, "--popover--").concat(align), !autoAligned), _defineProperty(_cx, "".concat(prefix, "--popover--tab-tip"), isTabTip), _cx), customClassName);
64
73
  useIsomorphicEffect(function () {
65
74
  if (!open) {
66
75
  return;
67
76
  }
68
77
 
69
- if (!autoAlign) {
78
+ if (!autoAlign || isTabTip) {
70
79
  setAutoAligned(false);
71
80
  return;
72
81
  }
@@ -108,6 +117,10 @@ var Popover = /*#__PURE__*/React__default.forwardRef(function Popover(props, for
108
117
  }
109
118
 
110
119
  function isVisible(alignment) {
120
+ if (!popover.current || !floating.current) {
121
+ return false;
122
+ }
123
+
111
124
  popover.current.classList.add("".concat(prefix, "--popover--").concat(alignment));
112
125
  var rect = floating.current.getBoundingClientRect(); // Check if popover is not visible to the left of the screen
113
126
 
@@ -153,13 +166,27 @@ var Popover = /*#__PURE__*/React__default.forwardRef(function Popover(props, for
153
166
  setAutoAligned(true);
154
167
  setAutoAlignment(alignment);
155
168
  }
156
- }, [autoAligned, align, autoAlign, prefix, open]);
169
+ }, [autoAligned, align, autoAlign, prefix, open, isTabTip]);
170
+ var BaseComponent = as !== null && as !== void 0 ? as : 'span';
171
+ var mappedChildren = React__default.Children.map(children, function (child) {
172
+ var item = child;
173
+
174
+ if ((item === null || item === void 0 ? void 0 : item.type) === 'button') {
175
+ var _className = item.props.className;
176
+ var tabTipClasses = cx("".concat(prefix, "--popover--tab-tip__button"), _className);
177
+ return /*#__PURE__*/React__default.cloneElement(item, {
178
+ className: tabTipClasses
179
+ });
180
+ } else {
181
+ return item;
182
+ }
183
+ });
157
184
  return /*#__PURE__*/React__default.createElement(PopoverContext.Provider, {
158
185
  value: value
159
186
  }, /*#__PURE__*/React__default.createElement(BaseComponent, _extends({}, rest, {
160
187
  className: className,
161
188
  ref: ref
162
- }), children));
189
+ }), isTabTip ? mappedChildren : children));
163
190
  }); // Note: this displayName is temporarily set so that Storybook ArgTable
164
191
  // correctly displays the name of this component
165
192
 
@@ -180,7 +207,7 @@ Popover.propTypes = {
180
207
  as: PropTypes.oneOfType([PropTypes.string, PropTypes.elementType]),
181
208
 
182
209
  /**
183
- * Will auto-align the popover on first render if it is not visible. This prop is currently experimental and is subject to futurue changes.
210
+ * Will auto-align the popover on first render if it is not visible. This prop is currently experimental and is subject to future changes.
184
211
  */
185
212
  autoAlign: PropTypes.bool,
186
213
 
@@ -210,15 +237,20 @@ Popover.propTypes = {
210
237
  */
211
238
  highContrast: PropTypes.bool,
212
239
 
240
+ /**
241
+ * Render the component using the tab tip variant
242
+ */
243
+ isTabTip: PropTypes.bool,
244
+
213
245
  /**
214
246
  * Specify whether the component is currently open or closed
215
247
  */
216
248
  open: PropTypes.bool.isRequired
217
249
  };
218
- var PopoverContent = /*#__PURE__*/React__default.forwardRef(function PopoverContent(_ref, forwardRef) {
219
- var className = _ref.className,
220
- children = _ref.children,
221
- rest = _objectWithoutProperties(_ref, _excluded2);
250
+ var PopoverContent = /*#__PURE__*/React__default.forwardRef(function PopoverContent(_ref2, forwardRef) {
251
+ var className = _ref2.className,
252
+ children = _ref2.children,
253
+ rest = _objectWithoutProperties(_ref2, _excluded2);
222
254
 
223
255
  var prefix = usePrefix();
224
256
 
@@ -5,13 +5,14 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import { slicedToArray as _slicedToArray, defineProperty as _defineProperty } from '../../_virtual/_rollupPluginBabelHelpers.js';
8
+ import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, defineProperty as _defineProperty, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import PropTypes from 'prop-types';
10
10
  import React__default, { useState } from 'react';
11
11
  import cx from 'classnames';
12
12
  import { Legend } from '../Text/index.js';
13
13
  import { usePrefix } from '../../internal/usePrefix.js';
14
14
 
15
+ var _excluded = ["children", "className", "defaultSelected", "disabled", "labelPosition", "legendText", "name", "onChange", "orientation", "readOnly", "valueSelected"];
15
16
  var RadioButtonGroup = /*#__PURE__*/React__default.forwardRef(function RadioButtonGroup(_ref, ref) {
16
17
  var _classNames;
17
18
 
@@ -28,7 +29,9 @@ var RadioButtonGroup = /*#__PURE__*/React__default.forwardRef(function RadioButt
28
29
  _ref$orientation = _ref.orientation,
29
30
  orientation = _ref$orientation === void 0 ? 'horizontal' : _ref$orientation,
30
31
  readOnly = _ref.readOnly,
31
- valueSelected = _ref.valueSelected;
32
+ valueSelected = _ref.valueSelected,
33
+ rest = _objectWithoutProperties(_ref, _excluded);
34
+
32
35
  var prefix = usePrefix();
33
36
 
34
37
  var _useState = useState(valueSelected !== null && valueSelected !== void 0 ? valueSelected : defaultSelected),
@@ -85,11 +88,11 @@ var RadioButtonGroup = /*#__PURE__*/React__default.forwardRef(function RadioButt
85
88
  return /*#__PURE__*/React__default.createElement("div", {
86
89
  className: wrapperClasses,
87
90
  ref: ref
88
- }, /*#__PURE__*/React__default.createElement("fieldset", {
91
+ }, /*#__PURE__*/React__default.createElement("fieldset", _extends({
89
92
  className: fieldsetClasses,
90
93
  disabled: disabled,
91
94
  "aria-readonly": readOnly
92
- }, legendText && /*#__PURE__*/React__default.createElement(Legend, {
95
+ }, rest), legendText && /*#__PURE__*/React__default.createElement(Legend, {
93
96
  className: "".concat(prefix, "--label")
94
97
  }, legendText), getRadioButtons()));
95
98
  });