@carbon/ibm-products 1.51.0 → 1.52.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. package/README.md +10 -5
  2. package/css/index-full-carbon.css +89 -64
  3. package/css/index-full-carbon.css.map +1 -1
  4. package/css/index-full-carbon.min.css +1 -1
  5. package/css/index-full-carbon.min.css.map +1 -1
  6. package/css/index-without-carbon.css +89 -64
  7. package/css/index-without-carbon.css.map +1 -1
  8. package/css/index-without-carbon.min.css +1 -1
  9. package/css/index-without-carbon.min.css.map +1 -1
  10. package/css/index.css +89 -64
  11. package/css/index.css.map +1 -1
  12. package/css/index.min.css +1 -1
  13. package/css/index.min.css.map +1 -1
  14. package/es/components/AboutModal/AboutModal.js +3 -4
  15. package/es/components/ActionBar/ActionBar.js +9 -18
  16. package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +8 -13
  17. package/es/components/ButtonSetWithOverflow/ButtonSetWithOverflow.js +7 -11
  18. package/es/components/Datagrid/Datagrid/DatagridToolbar.js +5 -5
  19. package/es/components/Datagrid/Datagrid/DatagridVirtualBody.js +3 -4
  20. package/es/components/Datagrid/index.js +1 -0
  21. package/es/components/Datagrid/useActionsColumn.js +10 -7
  22. package/es/components/Datagrid/useCustomizeColumns.js +5 -1
  23. package/es/components/Datagrid/useEditableCell.js +12 -0
  24. package/es/components/Datagrid/useExpandedRow.js +11 -7
  25. package/es/components/Datagrid/useFiltering.js +11 -8
  26. package/es/components/Datagrid/useInlineEdit.js +17 -8
  27. package/es/components/Datagrid/useNestedRows.js +10 -6
  28. package/es/components/ExampleComponent/ExampleComponent.js +32 -4
  29. package/es/components/ExampleComponent/useExample.js +49 -0
  30. package/es/components/InlineEditV1/InlineEditV1.js +3 -1
  31. package/es/components/NonLinearReading/NonLinearReading.js +7 -7
  32. package/es/components/PageHeader/PageHeader.js +28 -31
  33. package/es/components/SidePanel/SidePanel.js +25 -26
  34. package/es/components/TagSet/TagSet.js +5 -7
  35. package/es/components/Tearsheet/TearsheetShell.js +4 -6
  36. package/es/components/index.js +1 -1
  37. package/es/global/js/hooks/useResizeObserver.js +74 -0
  38. package/es/global/js/package-settings.js +34 -4
  39. package/es/global/js/utils/test-helper.js +34 -3
  40. package/es/settings.js +26 -30
  41. package/lib/components/AboutModal/AboutModal.js +3 -4
  42. package/lib/components/ActionBar/ActionBar.js +9 -18
  43. package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +8 -13
  44. package/lib/components/ButtonSetWithOverflow/ButtonSetWithOverflow.js +7 -11
  45. package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +4 -4
  46. package/lib/components/Datagrid/Datagrid/DatagridVirtualBody.js +3 -4
  47. package/lib/components/Datagrid/index.js +7 -0
  48. package/lib/components/Datagrid/useActionsColumn.js +7 -1
  49. package/lib/components/Datagrid/useCustomizeColumns.js +4 -0
  50. package/lib/components/Datagrid/useEditableCell.js +20 -0
  51. package/lib/components/Datagrid/useExpandedRow.js +4 -0
  52. package/lib/components/Datagrid/useFiltering.js +4 -0
  53. package/lib/components/Datagrid/useInlineEdit.js +19 -8
  54. package/lib/components/Datagrid/useNestedRows.js +9 -6
  55. package/lib/components/ExampleComponent/ExampleComponent.js +35 -4
  56. package/lib/components/ExampleComponent/useExample.js +58 -0
  57. package/lib/components/InlineEditV1/InlineEditV1.js +3 -1
  58. package/lib/components/NonLinearReading/NonLinearReading.js +6 -6
  59. package/lib/components/PageHeader/PageHeader.js +28 -31
  60. package/lib/components/SidePanel/SidePanel.js +25 -26
  61. package/lib/components/TagSet/TagSet.js +5 -7
  62. package/lib/components/Tearsheet/TearsheetShell.js +4 -6
  63. package/lib/components/index.js +6 -0
  64. package/lib/global/js/hooks/useResizeObserver.js +83 -0
  65. package/lib/global/js/package-settings.js +33 -3
  66. package/lib/global/js/utils/test-helper.js +37 -5
  67. package/lib/settings.js +26 -30
  68. package/package.json +2 -3
  69. package/scss/components/NonLinearReading/_non-linear-reading.scss +76 -67
  70. package/scss/components/NonLinearReading/_storybook-styles.scss +16 -0
@@ -16,7 +16,7 @@ import React, { useEffect, useRef, useState } from 'react';
16
16
  import PropTypes from 'prop-types';
17
17
  import { layout05, baseFontSize } from '@carbon/layout';
18
18
  import cx from 'classnames';
19
- import { useResizeDetector } from 'react-resize-detector';
19
+ import { useResizeObserver } from '../../global/js/hooks/useResizeObserver';
20
20
  import { Grid, Column, Row, Button, Tag } from 'carbon-components-react';
21
21
  import { breakpoints } from '@carbon/layout';
22
22
  import { useWindowResize, useNearestScroll } from '../../global/js/hooks';
@@ -38,7 +38,7 @@ var defaults = {
38
38
  narrowGrid: false
39
39
  };
40
40
  export var PageHeader = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
41
- var _withoutBackground, _enableBreadcrumbScro, _ref6, _cx2, _ref7, _cx4, _cx7;
41
+ var _withoutBackground, _enableBreadcrumbScro, _ref7, _cx2, _ref8, _cx4, _cx7;
42
42
  var actionBarItems = _ref.actionBarItems,
43
43
  actionBarMenuOptionsClass = _ref.actionBarMenuOptionsClass,
44
44
  actionBarOverflowAriaLabel = _ref.actionBarOverflowAriaLabel,
@@ -175,7 +175,8 @@ export var PageHeader = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
175
175
  };
176
176
 
177
177
  /* istanbul ignore next */
178
- var handleResizeActionBarColumn = function handleResizeActionBarColumn(width) {
178
+ var handleResizeActionBarColumn = function handleResizeActionBarColumn(_ref4) {
179
+ var width = _ref4.width;
179
180
  /* don't know how to test resize */
180
181
  /* istanbul ignore next */
181
182
  setActionBarColumnWidth(width);
@@ -249,8 +250,8 @@ export var PageHeader = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
249
250
  useNearestScroll(headerRef,
250
251
  // on scroll or various layout changes check updates if needed
251
252
  // istanbul ignore next
252
- function (_ref4) {
253
- var current = _ref4.current;
253
+ function (_ref5) {
254
+ var current = _ref5.current;
254
255
  setPageHeaderStyles(function (prev) {
255
256
  return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, "--".concat(blockClass, "--breadcrumb-top"), "".concat(metrics.headerOffset, "px")));
256
257
  });
@@ -266,8 +267,8 @@ export var PageHeader = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
266
267
  document.documentElement.style.setProperty("--".concat(blockClass, "--tagset-tooltip-offset"), "".concat(tagsetTooltipOffset, "px"));
267
268
  setScrollYValue(current.scrollY);
268
269
  }, [metrics.headerHeight, metrics.headerTopValue, metrics.headerOffset, enableBreadcrumbScroll]);
269
- useWindowResize(function (_ref5) {
270
- var current = _ref5.current;
270
+ useWindowResize(function (_ref6) {
271
+ var current = _ref6.current;
271
272
  // on window resize and other updates some values may have changed
272
273
  checkUpdateVerticalSpace();
273
274
  setWidthIsNarrow(current.innerWidth / 16 < parseInt(breakpoints.md.width)); // small (below medium) media query
@@ -313,15 +314,11 @@ export var PageHeader = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
313
314
  utilSetCollapsed(collapseHeader, metrics.headerOffset, metrics.headerTopValue);
314
315
  }
315
316
  }, [collapseHeader, metrics.headerOffset, metrics.headerTopValue]);
316
- useResizeDetector({
317
- onResize: handleResizeActionBarColumn,
318
- targetRef: sizingContainerRef,
319
- handleWidth: true
317
+ useResizeObserver(sizingContainerRef, {
318
+ callback: handleResizeActionBarColumn
320
319
  });
321
- useResizeDetector({
322
- onResize: handleResize,
323
- targetRef: headerRef,
324
- handleHeight: true
320
+ useResizeObserver(headerRef, {
321
+ callback: handleResize
325
322
  });
326
323
 
327
324
  // Determine what form of title to display in the breadcrumb
@@ -330,7 +327,7 @@ export var PageHeader = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
330
327
  className: "".concat(blockClass, "--offset-top-measuring-element"),
331
328
  ref: offsetTopMeasuringRef
332
329
  }), /*#__PURE__*/React.createElement("section", _extends({}, rest, {
333
- className: cx([blockClass, "".concat(blockClass, "--no-margins-below-row"), className, (_ref6 = {}, _defineProperty(_ref6, "".concat(blockClass, "--has-navigation"), navigation || tags), _defineProperty(_ref6, "".concat(blockClass, "--has-navigation-tags-only"), !navigation && tags), _ref6)]),
330
+ className: cx([blockClass, "".concat(blockClass, "--no-margins-below-row"), className, (_ref7 = {}, _defineProperty(_ref7, "".concat(blockClass, "--has-navigation"), navigation || tags), _defineProperty(_ref7, "".concat(blockClass, "--has-navigation-tags-only"), !navigation && tags), _ref7)]),
334
331
  style: pageHeaderStyles,
335
332
  ref: headerRef
336
333
  }, getDevtoolsProps(componentName)), /*#__PURE__*/React.createElement(Grid, {
@@ -351,7 +348,7 @@ export var PageHeader = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
351
348
  overflowAriaLabel: breadcrumbOverflowAriaLabel,
352
349
  breadcrumbs: breadcrumbs && breadcrumbItemForTitle ? breadcrumbs.concat(breadcrumbItemForTitle) : breadcrumbItemForTitle ? [breadcrumbItemForTitle] : breadcrumbs // breadcrumbs may be null or undefined
353
350
  }) : null), /*#__PURE__*/React.createElement(Column, {
354
- className: cx(["".concat(blockClass, "__action-bar-column ").concat(blockClass, "__action-bar-column--background"), (_ref7 = {}, _defineProperty(_ref7, "".concat(blockClass, "__action-bar-column--has-page-actions"), pageActions), _defineProperty(_ref7, "".concat(blockClass, "__action-bar-column--influenced-by-collapse-button"), spaceForCollapseButton), _ref7)])
351
+ className: cx(["".concat(blockClass, "__action-bar-column ").concat(blockClass, "__action-bar-column--background"), (_ref8 = {}, _defineProperty(_ref8, "".concat(blockClass, "__action-bar-column--has-page-actions"), pageActions), _defineProperty(_ref8, "".concat(blockClass, "__action-bar-column--influenced-by-collapse-button"), spaceForCollapseButton), _ref8)])
355
352
  }, /*#__PURE__*/React.createElement("div", {
356
353
  className: "".concat(blockClass, "__action-bar-column-content"),
357
354
  ref: sizingContainerRef
@@ -500,8 +497,8 @@ PageHeader.propTypes = _objectSpread({
500
497
  *
501
498
  * NOTE: This prop is required if actionBarItems are supplied
502
499
  */
503
- actionBarOverflowAriaLabel: PropTypes.string.isRequired.if(function (_ref9) {
504
- var actionBarItems = _ref9.actionBarItems;
500
+ actionBarOverflowAriaLabel: PropTypes.string.isRequired.if(function (_ref10) {
501
+ var actionBarItems = _ref10.actionBarItems;
505
502
  return actionBarItems && actionBarItems.length > 0;
506
503
  }),
507
504
  /**
@@ -532,8 +529,8 @@ PageHeader.propTypes = _objectSpread({
532
529
  * If the user supplies breadcrumbs then this property is required.
533
530
  * It is used in an overflow menu when there is insufficient space to display all breadcrumbs inline.
534
531
  */
535
- breadcrumbOverflowAriaLabel: PropTypes.string.isRequired.if(function (_ref10) {
536
- var breadcrumbs = _ref10.breadcrumbs;
532
+ breadcrumbOverflowAriaLabel: PropTypes.string.isRequired.if(function (_ref11) {
533
+ var breadcrumbs = _ref11.breadcrumbs;
537
534
  return breadcrumbs && breadcrumbs.length > 0;
538
535
  }),
539
536
  /**
@@ -567,8 +564,8 @@ PageHeader.propTypes = _objectSpread({
567
564
  /**
568
565
  * A text version of the `label` for display, required if `label` is not a string.
569
566
  */
570
- title: PropTypes.string.isRequired.if(function (_ref11) {
571
- var label = _ref11.label;
567
+ title: PropTypes.string.isRequired.if(function (_ref12) {
568
+ var label = _ref12.label;
572
569
  return typeof label !== 'string';
573
570
  })
574
571
  })),
@@ -594,9 +591,9 @@ PageHeader.propTypes = _objectSpread({
594
591
  * If `hasCollapseHeaderToggle` is set and `withoutBackground` is unset/falsy then assistive text is
595
592
  * required for both the expend and collapse states of the button component used.
596
593
  */
597
- collapseHeaderIconDescription: PropTypes.string.isRequired.if(function (_ref12) {
598
- var withoutBackground = _ref12.withoutBackground,
599
- hasCollapseHeaderToggle = _ref12.hasCollapseHeaderToggle;
594
+ collapseHeaderIconDescription: PropTypes.string.isRequired.if(function (_ref13) {
595
+ var withoutBackground = _ref13.withoutBackground,
596
+ hasCollapseHeaderToggle = _ref13.hasCollapseHeaderToggle;
600
597
  return !withoutBackground && hasCollapseHeaderToggle;
601
598
  }),
602
599
  /**
@@ -613,9 +610,9 @@ PageHeader.propTypes = _objectSpread({
613
610
  * If `hasCollapseHeaderToggle` is set and `withoutBackground` is unset/falsy then assistive text is
614
611
  * required for both the expend and collapse states of the button component used.
615
612
  */
616
- expandHeaderIconDescription: PropTypes.string.isRequired.if(function (_ref13) {
617
- var withoutBackground = _ref13.withoutBackground,
618
- hasCollapseHeaderToggle = _ref13.hasCollapseHeaderToggle;
613
+ expandHeaderIconDescription: PropTypes.string.isRequired.if(function (_ref14) {
614
+ var withoutBackground = _ref14.withoutBackground,
615
+ hasCollapseHeaderToggle = _ref14.hasCollapseHeaderToggle;
619
616
  return !withoutBackground && hasCollapseHeaderToggle;
620
617
  }),
621
618
  /**
@@ -679,8 +676,8 @@ PageHeader.propTypes = _objectSpread({
679
676
  *
680
677
  * NOTE: This prop is required if pageActions are supplied
681
678
  */
682
- pageActionsOverflowLabel: PropTypes.node.isRequired.if(function (_ref14) {
683
- var pageActions = _ref14.pageActions;
679
+ pageActionsOverflowLabel: PropTypes.node.isRequired.if(function (_ref15) {
680
+ var pageActions = _ref15.pageActions;
684
681
  return pageActions && pageActions.length > 0 && !pageActions.content;
685
682
  }),
686
683
  /**
@@ -20,7 +20,7 @@ import { motion, AnimatePresence } from 'framer-motion';
20
20
  // Other standard imports.
21
21
  import PropTypes from 'prop-types';
22
22
  import cx from 'classnames';
23
- import { useResizeDetector } from 'react-resize-detector';
23
+ import { useResizeObserver } from '../../global/js/hooks/useResizeObserver';
24
24
  import { moderate02 } from '@carbon/motion';
25
25
  import { getDevtoolsProps } from '../../global/js/utils/devtools';
26
26
  import { allPropTypes } from '../../global/js/utils/props-helper';
@@ -53,7 +53,7 @@ var defaults = {
53
53
  * Side panels keep users in-context of a page while performing tasks like navigating, editing, viewing details, or configuring something new.
54
54
  */
55
55
  export var SidePanel = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
56
- var _window, _ref4, _cx4;
56
+ var _window, _ref5, _cx4;
57
57
  var actionToolbarButtons = _ref.actionToolbarButtons,
58
58
  actions = _ref.actions,
59
59
  _ref$animateTitle = _ref.animateTitle,
@@ -165,8 +165,9 @@ export var SidePanel = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
165
165
  }, [labelText, title]);
166
166
 
167
167
  /* istanbul ignore next */
168
- var handleResize = function handleResize(width, height) {
168
+ var handleResize = function handleResize(_ref2) {
169
169
  var _sidePanelOuter$style3;
170
+ var height = _ref2.height;
170
171
  setPanelHeight(height);
171
172
  var sidePanelOuter = document.querySelector("#".concat(blockClass, "-outer"));
172
173
  var actionsContainer = getActionsContainerElement();
@@ -353,9 +354,9 @@ export var SidePanel = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
353
354
 
354
355
  // adds focus trap functionality
355
356
  /* istanbul ignore next */
356
- var handleBlur = function handleBlur(_ref2) {
357
- var oldActiveNode = _ref2.target,
358
- currentActiveNode = _ref2.relatedTarget;
357
+ var handleBlur = function handleBlur(_ref3) {
358
+ var oldActiveNode = _ref3.target,
359
+ currentActiveNode = _ref3.relatedTarget;
359
360
  // focus trap should only be set if the side panel is a `slideOver` type
360
361
  if (open && sidePanelInnerRef && !slideIn) {
361
362
  wrapFocus({
@@ -368,7 +369,7 @@ export var SidePanel = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
368
369
  }
369
370
  };
370
371
  var primaryActionContainerClassNames = cx(["".concat(blockClass, "__actions-container"), _defineProperty({}, "".concat(blockClass, "__actions-container-condensed"), condensedActions)]);
371
- var mainPanelClassNames = cx([blockClass, className, "".concat(blockClass, "__container"), "".concat(blockClass, "__container--").concat(size), (_ref4 = {}, _defineProperty(_ref4, "".concat(blockClass, "__container-right-placement"), placement === 'right'), _defineProperty(_ref4, "".concat(blockClass, "__container-left-placement"), placement === 'left'), _defineProperty(_ref4, "".concat(blockClass, "__container-with-action-toolbar"), actionToolbarButtons && actionToolbarButtons.length), _defineProperty(_ref4, "".concat(blockClass, "__container-without-overlay"), !includeOverlay && !slideIn), _defineProperty(_ref4, "".concat(blockClass, "__container-is-animating"), !animationComplete || !open), _ref4)]);
372
+ var mainPanelClassNames = cx([blockClass, className, "".concat(blockClass, "__container"), "".concat(blockClass, "__container--").concat(size), (_ref5 = {}, _defineProperty(_ref5, "".concat(blockClass, "__container-right-placement"), placement === 'right'), _defineProperty(_ref5, "".concat(blockClass, "__container-left-placement"), placement === 'left'), _defineProperty(_ref5, "".concat(blockClass, "__container-with-action-toolbar"), actionToolbarButtons && actionToolbarButtons.length), _defineProperty(_ref5, "".concat(blockClass, "__container-without-overlay"), !includeOverlay && !slideIn), _defineProperty(_ref5, "".concat(blockClass, "__container-is-animating"), !animationComplete || !open), _ref5)]);
372
373
  var renderHeader = function renderHeader() {
373
374
  var _cx, _cx2;
374
375
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
@@ -397,17 +398,17 @@ export var SidePanel = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
397
398
  className: cx("".concat(blockClass, "__subtitle-text"), (_cx2 = {}, _defineProperty(_cx2, "".concat(blockClass, "__subtitle-text-no-animation"), !animateTitle), _defineProperty(_cx2, "".concat(blockClass, "__subtitle-text-no-animation-no-action-toolbar"), !animateTitle && (!actionToolbarButtons || !actionToolbarButtons.length)), _defineProperty(_cx2, "".concat(blockClass, "__subtitle-text-is-animating"), !animationComplete && animateTitle), _defineProperty(_cx2, "".concat(blockClass, "__subtitle-without-title"), !title), _cx2))
398
399
  }, subtitle), actionToolbarButtons && actionToolbarButtons.length && /*#__PURE__*/React.createElement("div", {
399
400
  className: cx("".concat(blockClass, "__action-toolbar"), _defineProperty({}, "".concat(blockClass, "__action-toolbar-no-animation"), !animateTitle))
400
- }, actionToolbarButtons.map(function (_ref5) {
401
- var label = _ref5.label,
402
- kind = _ref5.kind,
403
- icon = _ref5.icon,
404
- tooltipPosition = _ref5.tooltipPosition,
405
- tooltipAlignment = _ref5.tooltipAlignment,
406
- leading = _ref5.leading,
407
- disabled = _ref5.disabled,
408
- className = _ref5.className,
409
- onClick = _ref5.onClick,
410
- rest = _objectWithoutProperties(_ref5, _excluded2);
401
+ }, actionToolbarButtons.map(function (_ref6) {
402
+ var label = _ref6.label,
403
+ kind = _ref6.kind,
404
+ icon = _ref6.icon,
405
+ tooltipPosition = _ref6.tooltipPosition,
406
+ tooltipAlignment = _ref6.tooltipAlignment,
407
+ leading = _ref6.leading,
408
+ disabled = _ref6.disabled,
409
+ className = _ref6.className,
410
+ onClick = _ref6.onClick,
411
+ rest = _objectWithoutProperties(_ref6, _excluded2);
411
412
  return /*#__PURE__*/React.createElement(Button, _extends({}, rest, {
412
413
  key: label,
413
414
  kind: kind || 'ghost',
@@ -435,10 +436,8 @@ export var SidePanel = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
435
436
  }, title));
436
437
  };
437
438
  var contentRef = ref || sidePanelRef;
438
- useResizeDetector({
439
- handleHeight: true,
440
- onResize: handleResize,
441
- targetRef: contentRef
439
+ useResizeObserver(contentRef, {
440
+ callback: handleResize
442
441
  });
443
442
  return /*#__PURE__*/React.createElement(AnimatePresence, null, open && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(motion.div, _extends({}, getDevtoolsProps(componentName), rest, {
444
443
  id: "".concat(blockClass, "-outer"),
@@ -591,8 +590,8 @@ SidePanel.propTypes = {
591
590
  * This is the selector to the element that contains all of the page content that will shrink if the panel is a slide in.
592
591
  * This prop is required when using the `slideIn` variant of the side panel.
593
592
  */
594
- selectorPageContent: PropTypes.string.isRequired.if(function (_ref7) {
595
- var slideIn = _ref7.slideIn;
593
+ selectorPageContent: PropTypes.string.isRequired.if(function (_ref8) {
594
+ var slideIn = _ref8.slideIn;
596
595
  return slideIn;
597
596
  }),
598
597
  /**
@@ -615,8 +614,8 @@ SidePanel.propTypes = {
615
614
  /**
616
615
  * Sets the title text
617
616
  */
618
- title: PropTypes.string.isRequired.if(function (_ref8) {
619
- var labelText = _ref8.labelText;
617
+ title: PropTypes.string.isRequired.if(function (_ref9) {
618
+ var labelText = _ref9.labelText;
620
619
  return labelText;
621
620
  })
622
621
  };
@@ -21,7 +21,7 @@ import cx from 'classnames';
21
21
  import { TagSetOverflow } from './TagSetOverflow';
22
22
  import { TagSetModal } from './TagSetModal';
23
23
  import { Tag } from 'carbon-components-react';
24
- import { useResizeDetector } from 'react-resize-detector';
24
+ import { useResizeObserver } from '../../global/js/hooks/useResizeObserver';
25
25
  import { getDevtoolsProps } from '../../global/js/utils/devtools';
26
26
  import { prepareProps, isRequiredIf } from '../../global/js/utils/props-helper';
27
27
  import { pkg } from '../../settings';
@@ -202,13 +202,11 @@ export var TagSet = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
202
202
  var handleModalClose = function handleModalClose() {
203
203
  setShowAllModalOpen(false);
204
204
  };
205
- useResizeDetector({
206
- onResize: handleSizerTagsResize,
207
- targetRef: sizingContainerRef
205
+ useResizeObserver(sizingContainerRef, {
206
+ callback: handleSizerTagsResize
208
207
  });
209
- useResizeDetector({
210
- onResize: handleResize,
211
- targetRef: tagSetRef
208
+ useResizeObserver(tagSetRef, {
209
+ callback: handleResize
212
210
  });
213
211
  return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
214
212
  className: cx([blockClass, className]),
@@ -15,7 +15,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
15
15
  // Import portions of React that are needed.
16
16
  import React, { useEffect, useState, useRef } from 'react';
17
17
  import { createPortal } from 'react-dom';
18
- import { useResizeDetector } from 'react-resize-detector';
18
+ import { useResizeObserver } from '../../global/js/hooks/useResizeObserver';
19
19
 
20
20
  // Other standard imports.
21
21
  import PropTypes from 'prop-types';
@@ -93,12 +93,10 @@ export var TearsheetShell = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
93
93
  }
94
94
  }, [portalTargetIn]);
95
95
  var localRef = useRef();
96
+ var resizer = useRef(null);
96
97
  var modalRef = ref || localRef;
97
- var _useResizeDetector = useResizeDetector({
98
- handleHeight: false
99
- }),
100
- width = _useResizeDetector.width,
101
- resizer = _useResizeDetector.ref;
98
+ var _useResizeObserver = useResizeObserver(resizer),
99
+ width = _useResizeObserver.width;
102
100
 
103
101
  // Keep track of the stack depth and our position in it (1-based, 0=closed)
104
102
  var _useState3 = useState(0),
@@ -37,7 +37,7 @@ export { WebTerminal, WebTerminalContentWrapper, useWebTerminal, WebTerminalProv
37
37
  export { EditSidePanel } from './EditSidePanel';
38
38
  export { OptionsTile } from './OptionsTile';
39
39
  export { DataSpreadsheet } from './DataSpreadsheet';
40
- export { Datagrid, useDatagrid, useInfiniteScroll, useNestedRows, useSelectRows, useExpandedRow, useOnRowClick, useSortableColumns, useRowIsMouseOver, useColumnCenterAlign, useColumnRightAlign, useDisableSelectRows, useStickyColumn, useActionsColumn, useCustomizeColumns, useSelectAllWithToggle, useColumnOrder, useInlineEdit, useFiltering, getAutoSizedColumnWidth } from './Datagrid';
40
+ export { Datagrid, useDatagrid, useInfiniteScroll, useNestedRows, useSelectRows, useExpandedRow, useOnRowClick, useSortableColumns, useRowIsMouseOver, useColumnCenterAlign, useColumnRightAlign, useDisableSelectRows, useStickyColumn, useActionsColumn, useCustomizeColumns, useSelectAllWithToggle, useColumnOrder, useInlineEdit, useEditableCell, useFiltering, getAutoSizedColumnWidth } from './Datagrid';
41
41
  export { EditTearsheet } from './EditTearsheet';
42
42
  export { EditTearsheetNarrow } from './EditTearsheetNarrow';
43
43
  export { EditFullPage } from './EditFullPage';
@@ -0,0 +1,74 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ /**
3
+ * Copyright IBM Corp. 2023, 2023
4
+ *
5
+ * This source code is licensed under the Apache-2.0 license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { useRef, useState, useLayoutEffect } from 'react';
9
+ export var useResizeObserver = function useResizeObserver(ref) {
10
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
11
+ callback: null,
12
+ throttleInterval: 0
13
+ };
14
+ var callback = options.callback,
15
+ throttleInterval = options.throttleInterval;
16
+ var _useState = useState(0),
17
+ _useState2 = _slicedToArray(_useState, 2),
18
+ width = _useState2[0],
19
+ setWidth = _useState2[1];
20
+ var _useState3 = useState(0),
21
+ _useState4 = _slicedToArray(_useState3, 2),
22
+ height = _useState4[0],
23
+ setHeight = _useState4[1];
24
+ var throttleTimeout = useRef(null);
25
+ var entriesToHandle = useRef(null);
26
+ useLayoutEffect(function () {
27
+ if (!(ref !== null && ref !== void 0 && ref.current)) {
28
+ return;
29
+ }
30
+ var doCallbacks = function doCallbacks() {
31
+ if (!(ref !== null && ref !== void 0 && ref.current) || !Array.isArray(entriesToHandle === null || entriesToHandle === void 0 ? void 0 : entriesToHandle.current)) {
32
+ return;
33
+ }
34
+ var entry = entriesToHandle.current[0];
35
+ setWidth(entry.contentRect.width);
36
+ setHeight(entry.contentRect.height);
37
+ throttleTimeout.current = null;
38
+ callback && callback(entry.contentRect);
39
+ };
40
+ var observer = new ResizeObserver(function (entries) {
41
+ // always update entriesToHandle
42
+ entriesToHandle.current = entries;
43
+ if (throttleInterval) {
44
+ // if a throttleInterval check for running timeout
45
+ if (throttleTimeout.current === null) {
46
+ // no live timeout set entries to handle and move on
47
+
48
+ // set up throttle
49
+ throttleTimeout.current = setTimeout(function () {
50
+ // do callbacks
51
+ doCallbacks();
52
+ // reset throttle
53
+ throttleTimeout.current = null;
54
+ }, throttleInterval);
55
+ }
56
+ } else {
57
+ // no throttle do callbacks every time
58
+ doCallbacks();
59
+ }
60
+ });
61
+
62
+ // observe all refs passed
63
+ observer.observe(ref.current);
64
+ return function () {
65
+ observer.disconnect();
66
+ observer = null;
67
+ };
68
+ // eslint-disable-next-line react-hooks/exhaustive-deps
69
+ }, [ref, options]);
70
+ return {
71
+ width: width,
72
+ height: height
73
+ };
74
+ };
@@ -2,7 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
3
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
4
  //
5
- // Copyright IBM Corp. 2020, 2021
5
+ // Copyright IBM Corp. 2020, 2023
6
6
  //
7
7
  // This source code is licensed under the Apache-2.0 license found in the
8
8
  // LICENSE file in the root directory of this source tree.
@@ -79,7 +79,15 @@ var defaults = {
79
79
  // feature level flags
80
80
  feature: {
81
81
  'a-new-feature': false,
82
- 'default-portal-target-body': true
82
+ 'default-portal-target-body': true,
83
+ 'Datagrid.useExpandedRow': false,
84
+ 'Datagrid.useNestedRows': false,
85
+ 'Datagrid.useInlineEdit': false,
86
+ 'Datagrid.useActionsColumn': false,
87
+ 'Datagrid.useFiltering': false,
88
+ 'Datagrid.useCustomizeColumns': false,
89
+ 'ExampleComponent.secondaryIcon': false,
90
+ 'ExampleComponent.useExample': false
83
91
  }
84
92
  };
85
93
  var warningMessageComponent = function warningMessageComponent(property) {
@@ -88,6 +96,9 @@ var warningMessageComponent = function warningMessageComponent(property) {
88
96
  var warningMessageFeature = function warningMessageFeature(property) {
89
97
  return "Carbon for IBM Products (WARNING): Feature \"".concat(property, "\" enabled via feature flags.");
90
98
  };
99
+ var errorMessageFeature = function errorMessageFeature(property) {
100
+ return "Carbon for IBM Products (Error): Feature \"".concat(property, "\" not enabled. To enable see the notes on feature flags in the README.");
101
+ };
91
102
  var warningMessageAllComponents = 'Carbon for IBM Products (WARNING): All components enabled through use of setAllComponents. This includes components that have not yet completed their review process.';
92
103
  var warningMessageAllFeatures = 'Carbon for IBM Products (WARNING): All features enabled through use of setAllFeatures';
93
104
 
@@ -109,7 +120,10 @@ var allFeatures = all.INITIAL;
109
120
  var silent = false;
110
121
  var component = new Proxy(_objectSpread({}, defaults.component), {
111
122
  set: function set(target, property, value) {
112
- value && !silent && console.warn(warningMessageComponent(property));
123
+ if (target[property] !== true && !silent && value) {
124
+ // not already true, not silent, and now true
125
+ console.warn(warningMessageComponent(property));
126
+ }
113
127
  target[property] = value;
114
128
  return true; // value set
115
129
  },
@@ -120,7 +134,15 @@ var component = new Proxy(_objectSpread({}, defaults.component), {
120
134
  });
121
135
  var feature = new Proxy(_objectSpread({}, defaults.feature), {
122
136
  set: function set(target, property, value) {
123
- value && !silent && console.warn(warningMessageFeature(property));
137
+ // If we receive a feature flag that doesn't exist in our defaults we should not log
138
+ // a warning message and instead just return
139
+ if (!Object.getOwnPropertyDescriptor(defaults.feature, property)) {
140
+ return true;
141
+ }
142
+ if (target[property] !== true && !silent && value) {
143
+ // not already true, not silent, and now true
144
+ console.warn(warningMessageFeature(property));
145
+ }
124
146
  target[property] = value;
125
147
  return true; // value set
126
148
  },
@@ -149,6 +171,14 @@ export default {
149
171
  var byDefault = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
150
172
  return byDefault ? defaults.feature[featureName] : feature[featureName];
151
173
  },
174
+ checkReportFeatureEnabled: function checkReportFeatureEnabled(featureName) {
175
+ if (feature[featureName]) {
176
+ // NOTE: Warning emitted if feature flag is enabled (see Proxy above)
177
+ return true;
178
+ } else {
179
+ console.error(errorMessageFeature(featureName));
180
+ }
181
+ },
152
182
  isFeaturePublic: function isFeaturePublic(featureName) {
153
183
  var byDefault = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
154
184
  return Object.prototype.hasOwnProperty.call(byDefault ? defaults.feature : feature, featureName);
@@ -182,6 +182,39 @@ export var expectMultipleWarn = function expectMultipleWarn(messages, test) {
182
182
  warn.mockRestore();
183
183
  return result;
184
184
  };
185
+ var checkLogging = function checkLogging(mock, message) {
186
+ if (message) {
187
+ var _expect4;
188
+ expect(mock).toBeCalled();
189
+ (_expect4 = expect(mock)).toHaveBeenCalledWith.apply(_expect4, _toConsumableArray(makeMatcherArray(message)));
190
+ }
191
+ };
192
+
193
+ /**
194
+ * A helper function to enable a test to expect a single call to
195
+ * console.error, for example when intentionally omitting a required prop
196
+ * or supplying an invalid prop type or value for the purposes of the test.
197
+ * @param {errors: {string|regex|function|[]}, warnings: {string|regex|function|[]}} messages the expected parameters for the call to
198
+ * console.error or console.warn, which must be called exactly once. A single string or regex or an
199
+ * expect matcher can be used to match a single-argument call to console.error (most common),
200
+ * while an array of strings and/or regex and/or expect matchers can be used to match a
201
+ * multiple-argument call. Strings can be full or substring matches to the corresponding
202
+ * argument.
203
+ * @param {Function} test the test function to call, during which the call to
204
+ * console.error will be expected.
205
+ */
206
+ export var expectLogging = function expectLogging(_ref2, test) {
207
+ var errors = _ref2.errors,
208
+ warnings = _ref2.warnings;
209
+ var error = jest.spyOn(console, 'error').mockImplementation(jest.fn());
210
+ var warn = jest.spyOn(console, 'warn').mockImplementation(jest.fn());
211
+ var result = test();
212
+ checkLogging(error, errors);
213
+ checkLogging(warn, warnings);
214
+ error.mockRestore();
215
+ warn.mockRestore();
216
+ return result;
217
+ };
185
218
 
186
219
  /**
187
220
  * A helper function to enable a test to expect a single call to
@@ -197,11 +230,9 @@ export var expectMultipleWarn = function expectMultipleWarn(messages, test) {
197
230
  * console.error will be expected.
198
231
  */
199
232
  export var expectError = function expectError(message, test) {
200
- var _expect4;
201
233
  var error = jest.spyOn(console, 'error').mockImplementation(jest.fn());
202
234
  var result = test();
203
- expect(error).toBeCalledTimes(1);
204
- (_expect4 = expect(error)).toHaveBeenCalledWith.apply(_expect4, _toConsumableArray(makeMatcherArray(message)));
235
+ checkLogging(error, message);
205
236
  error.mockRestore();
206
237
  return result;
207
238
  };
package/es/settings.js CHANGED
@@ -35,24 +35,22 @@ pkgSettings.logDeprecated = function (component, name) {
35
35
  // Note that the returned stub carries any other properties which had already
36
36
  // been assigned (eg propTypes, displayName, etc).
37
37
  pkgSettings.checkComponentEnabled = function (component, name) {
38
- pkgSettings.logDeprecated(component, name);
39
38
  if (component.render) {
40
39
  // The component is a forward-ref, so make a stub forward-ref.
41
40
  var forward = /*#__PURE__*/React.forwardRef(function (props, ref) {
42
- return (
43
- // Replace the stub's render fn so this test only happens once.
44
- (forward.render = pkgSettings.isComponentEnabled(name) || !pkgSettings.isComponentPublic(name) ?
45
- // If the component is enabled, or if it's not a public component,
46
- // replace the stub's render fn with the component's render fn.
47
- component.render :
48
- // Note that Canary is a direct render fn (not a forward-ref) and
49
- // will ignore the passed props and ref (if any)
50
- Canary.bind(undefined, {
51
- componentName: name
52
- }))(
53
- // Call it now (after this it will be directly called).
54
- props, ref)
55
- );
41
+ pkgSettings.logDeprecated(component, name); // may log don't care about result
42
+ // Replace the stub's render fn so this test only happens once.
43
+ return (forward.render = pkgSettings.isComponentEnabled(name) || !pkgSettings.isComponentPublic(name) ?
44
+ // If the component is enabled, or if it's not a public component,
45
+ // replace the stub's render fn with the component's render fn.
46
+ component.render :
47
+ // Note that Canary is a direct render fn (not a forward-ref) and
48
+ // will ignore the passed props and ref (if any)
49
+ Canary.bind(undefined, {
50
+ componentName: name
51
+ }))(
52
+ // Call it now (after this it will be directly called).
53
+ props, ref);
56
54
  });
57
55
 
58
56
  // Transfer object properties already assigned (eg propTypes, displayName)
@@ -62,22 +60,20 @@ pkgSettings.checkComponentEnabled = function (component, name) {
62
60
  } else {
63
61
  // The component is a direct render fn, so make a stub render fn.
64
62
  var _render = function render(props) {
65
- return (
66
- // Replace the stub render fn so this test only happens once.
67
- (_render = pkgSettings.isComponentEnabled(name) || !pkgSettings.isComponentPublic(name) ?
68
- // If the component is enabled, or if it's not a public component,
69
- // replace the stub render fn with the component render fn.
70
- component :
71
- // Replace the stub render fn with the Canary render fn, which will
72
- // ignore the passed props.
73
- Canary.bind(undefined, {
74
- componentName: name
75
- }))(
76
- // Call it now (after this it will be directly called).
77
- props)
78
- );
63
+ pkgSettings.logDeprecated(component, name); // may log don't care about result
64
+ // Replace the stub render fn so this test only happens once.
65
+ return (_render = pkgSettings.isComponentEnabled(name) || !pkgSettings.isComponentPublic(name) ?
66
+ // If the component is enabled, or if it's not a public component,
67
+ // replace the stub render fn with the component render fn.
68
+ component :
69
+ // Replace the stub render fn with the Canary render fn, which will
70
+ // ignore the passed props.
71
+ Canary.bind(undefined, {
72
+ componentName: name
73
+ }))(
74
+ // Call it now (after this it will be directly called).
75
+ props);
79
76
  };
80
-
81
77
  // Transfer object properties already assigned (eg propTypes, displayName)
82
78
  // to a function which calls the stub render fn which checks the component
83
79
  // status when first used.
@@ -11,7 +11,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
11
11
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
12
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
13
  var _react = _interopRequireWildcard(require("react"));
14
- var _reactResizeDetector = require("react-resize-detector");
14
+ var _useResizeObserver = require("../../global/js/hooks/useResizeObserver");
15
15
  var _propTypes = _interopRequireDefault(require("prop-types"));
16
16
  var _classnames = _interopRequireDefault(require("classnames"));
17
17
  var _settings = require("../../settings");
@@ -71,9 +71,8 @@ var AboutModal = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
71
71
  }, [bodyRef]);
72
72
 
73
73
  // Detect resize of the ModalBody to recalculate whether scrolling is enabled
74
- (0, _reactResizeDetector.useResizeDetector)({
75
- onResize: handleResize,
76
- targetRef: bodyRef
74
+ (0, _useResizeObserver.useResizeObserver)(bodyRef, {
75
+ callback: handleResize
77
76
  });
78
77
  return /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.ComposedModal, (0, _extends2.default)({}, rest, {
79
78
  className: (0, _classnames.default)(blockClass,