@carbon/ibm-products 2.58.0 → 2.59.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 (60) hide show
  1. package/css/index-full-carbon.css +18 -14
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +1 -1
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon-released-only.css +17 -4
  6. package/css/index-without-carbon-released-only.css.map +1 -1
  7. package/css/index-without-carbon-released-only.min.css +1 -1
  8. package/css/index-without-carbon-released-only.min.css.map +1 -1
  9. package/css/index-without-carbon.css +18 -14
  10. package/css/index-without-carbon.css.map +1 -1
  11. package/css/index-without-carbon.min.css +1 -1
  12. package/css/index-without-carbon.min.css.map +1 -1
  13. package/css/index.css +18 -14
  14. package/css/index.css.map +1 -1
  15. package/css/index.min.css +1 -1
  16. package/css/index.min.css.map +1 -1
  17. package/es/components/ConditionBuilder/ConditionBuilder.types.d.ts +1 -1
  18. package/es/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemOption/ItemOptionForValueField.js +1 -1
  19. package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +1 -1
  20. package/es/components/InterstitialScreen/InterstitialScreen.js +10 -7
  21. package/es/components/NotificationsPanel/NotificationsPanel.js +12 -3
  22. package/es/components/PageHeader/PageHeader.js +11 -1
  23. package/es/components/ScrollGradient/ScrollGradient.js +34 -27
  24. package/es/components/StringFormatter/StringFormatter.js +9 -6
  25. package/es/components/TagOverflow/TagOverflow.d.ts +10 -1
  26. package/es/components/TagOverflow/TagOverflow.js +54 -146
  27. package/es/components/Tearsheet/Tearsheet.d.ts +6 -14
  28. package/es/components/Tearsheet/Tearsheet.js +2 -18
  29. package/es/components/Tearsheet/TearsheetNarrow.d.ts +6 -4
  30. package/es/components/Tearsheet/TearsheetNarrow.js +2 -10
  31. package/es/components/Tearsheet/TearsheetShell.d.ts +8 -8
  32. package/es/components/Tearsheet/TearsheetShell.js +40 -27
  33. package/es/components/TruncatedList/TruncatedList.js +7 -4
  34. package/es/components/WebTerminal/WebTerminal.js +15 -5
  35. package/es/global/js/hooks/useOverflowItems.d.ts +16 -0
  36. package/es/global/js/hooks/useOverflowItems.js +88 -0
  37. package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts +1 -1
  38. package/lib/components/ConditionBuilder/ConditionBuilderItem/ConditionBuilderItemOption/ItemOptionForValueField.js +1 -1
  39. package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +1 -1
  40. package/lib/components/InterstitialScreen/InterstitialScreen.js +9 -6
  41. package/lib/components/NotificationsPanel/NotificationsPanel.js +12 -3
  42. package/lib/components/PageHeader/PageHeader.js +11 -1
  43. package/lib/components/ScrollGradient/ScrollGradient.js +32 -25
  44. package/lib/components/StringFormatter/StringFormatter.js +8 -5
  45. package/lib/components/TagOverflow/TagOverflow.d.ts +10 -1
  46. package/lib/components/TagOverflow/TagOverflow.js +52 -144
  47. package/lib/components/Tearsheet/Tearsheet.d.ts +6 -14
  48. package/lib/components/Tearsheet/Tearsheet.js +1 -17
  49. package/lib/components/Tearsheet/TearsheetNarrow.d.ts +6 -4
  50. package/lib/components/Tearsheet/TearsheetNarrow.js +1 -9
  51. package/lib/components/Tearsheet/TearsheetShell.d.ts +8 -8
  52. package/lib/components/Tearsheet/TearsheetShell.js +37 -24
  53. package/lib/components/TruncatedList/TruncatedList.js +7 -4
  54. package/lib/components/WebTerminal/WebTerminal.js +14 -4
  55. package/lib/global/js/hooks/useOverflowItems.d.ts +16 -0
  56. package/lib/global/js/hooks/useOverflowItems.js +90 -0
  57. package/package.json +5 -5
  58. package/scss/components/ConditionBuilder/_condition-builder.scss +0 -6
  59. package/scss/components/TagOverflow/_tag-overflow.scss +1 -6
  60. package/scss/components/Tearsheet/_tearsheet.scss +21 -6
@@ -7,7 +7,7 @@
7
7
 
8
8
  import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, extends as _extends, defineProperty as _defineProperty } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import { ComposedModal, ModalHeader, ProgressIndicator, ProgressStep, ModalBody, ModalFooter, FlexGrid, Row, Column, Button } from '@carbon/react';
10
- import React__default, { useRef, useState, Children, useCallback, useEffect, isValidElement } from 'react';
10
+ import React__default, { useRef, useState, Children, useCallback, useEffect, useMemo, isValidElement } from 'react';
11
11
  import { ArrowRight } from '@carbon/react/icons';
12
12
  import { Carousel } from '../Carousel/Carousel.js';
13
13
  import '../Carousel/CarouselItem.js';
@@ -172,6 +172,9 @@ var InterstitialScreen = /*#__PURE__*/React__default.forwardRef(function (_ref,
172
172
  return window.removeEventListener('keydown', close);
173
173
  };
174
174
  }, [handleClose]);
175
+ var stepSize = useMemo(function () {
176
+ return children && Children.count(children) > 1 ? parseFloat((1 / (Children.count(children) - 1)).toFixed(2)) : 0;
177
+ }, [children]);
175
178
  if (!isOpen) {
176
179
  return null;
177
180
  }
@@ -237,6 +240,10 @@ var InterstitialScreen = /*#__PURE__*/React__default.forwardRef(function (_ref,
237
240
  }
238
241
  })))), childElements, renderFooter()));
239
242
  };
243
+ var scrollToCurrentStep = function scrollToCurrentStep(scrollPercent) {
244
+ var currentStep = scrollPercent / stepSize;
245
+ setProgStep(Math.ceil(currentStep));
246
+ };
240
247
  var renderBody = function renderBody() {
241
248
  return /*#__PURE__*/React__default.createElement("div", {
242
249
  className: cx("".concat(blockClass, "--body")),
@@ -259,9 +266,7 @@ var InterstitialScreen = /*#__PURE__*/React__default.forwardRef(function (_ref,
259
266
  }, /*#__PURE__*/React__default.createElement(Carousel, {
260
267
  disableArrowScroll: true,
261
268
  ref: scrollRef,
262
- onScroll: function onScroll(scrollPercent) {
263
- scrollPercent === 0 && setProgStep(0);
264
- }
269
+ onScroll: scrollToCurrentStep
265
270
  }, children)) : childArray[0])), mediaIsDefined && /*#__PURE__*/React__default.createElement(Column, {
266
271
  xlg: mediaBreakpoints.xlg,
267
272
  lg: mediaBreakpoints.lg,
@@ -281,9 +286,7 @@ var InterstitialScreen = /*#__PURE__*/React__default.forwardRef(function (_ref,
281
286
  }, /*#__PURE__*/React__default.createElement(Carousel, {
282
287
  disableArrowScroll: true,
283
288
  ref: scrollRef,
284
- onScroll: function onScroll(scrollPercent) {
285
- scrollPercent === 0 && setProgStep(0);
286
- }
289
+ onScroll: scrollToCurrentStep
287
290
  }, children)) : /*#__PURE__*/React__default.createElement("div", null, childArray[0])));
288
291
  };
289
292
  var renderFooter = function renderFooter() {
@@ -27,6 +27,7 @@ import usePrefersReducedMotion from '../../global/js/hooks/usePrefersReducedMoti
27
27
  import wrapFocus from '../../global/js/utils/wrapFocus.js';
28
28
  import { usePreviousValue } from '../../global/js/hooks/usePreviousValue.js';
29
29
  import { useClickOutside } from '../../global/js/hooks/useClickOutside.js';
30
+ import { useIsomorphicEffect } from '../../global/js/hooks/useIsomorphicEffect.js';
30
31
 
31
32
  var _Close;
32
33
  var _excluded = ["className", "data", "daysAgoText", "dismissAllLabel", "dismissSingleNotificationIconDescription", "doNotDisturbDefaultToggled", "doNotDisturbLabel", "emptyStateLabel", "hourAgoText", "hoursAgoText", "minuteAgoText", "minutesAgoText", "monthAgoText", "monthsAgoText", "nowText", "onClickOutside", "onDismissAllNotifications", "onDismissSingleNotification", "onDoNotDisturbChange", "onSettingsClick", "onViewAllClick", "open", "previousLabel", "readLessLabel", "readMoreLabel", "secondsAgoText", "settingsIconDescription", "title", "todayLabel", "viewAllLabel", "yearAgoText", "yearsAgoText", "yesterdayAtText", "yesterdayLabel", "selectorsFloatingMenus", "triggerButtonRef"];
@@ -376,6 +377,17 @@ var NotificationsPanel = /*#__PURE__*/React__default.forwardRef(function (_ref,
376
377
  onDismissSingleNotification(notification);
377
378
  };
378
379
  var mainSectionClassName = cx(["".concat(blockClass, "__main-section"), _defineProperty({}, "".concat(blockClass, "__main-section-empty"), allNotifications && !allNotifications.length)]);
380
+ useIsomorphicEffect(function () {
381
+ // setTimeout ensures that this gets run
382
+ var timeout = setTimeout(function () {
383
+ if (notificationPanelRef.current && !reducedMotion) {
384
+ notificationPanelRef.current.style.animation = open ? 'fade-in 250ms' : 'fade-out forwards 250ms';
385
+ }
386
+ }, 0);
387
+ return function () {
388
+ return clearTimeout(timeout);
389
+ };
390
+ }, [open, reducedMotion]);
379
391
  return shouldRender ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("button", {
380
392
  type: "button",
381
393
  className: "".concat(carbonPrefix, "--visually-hidden"),
@@ -389,9 +401,6 @@ var NotificationsPanel = /*#__PURE__*/React__default.forwardRef(function (_ref,
389
401
  }, rest, {
390
402
  id: blockClass,
391
403
  className: cx(blockClass, className, "".concat(blockClass, "__container")),
392
- style: {
393
- animation: !reducedMotion ? "".concat(open ? 'fade-in 250ms' : 'fade-out forwards 250ms') : undefined
394
- },
395
404
  onAnimationEnd: onAnimationEnd,
396
405
  ref: ref || notificationPanelRef
397
406
  }, getDevtoolsProps(componentName)), /*#__PURE__*/React__default.createElement("div", {
@@ -22,6 +22,7 @@ import { useResizeObserver } from '../../global/js/hooks/useResizeObserver.js';
22
22
  import { checkHeightOverflow } from '../../global/js/utils/checkForOverflow.js';
23
23
  import { useNearestScroll } from '../../global/js/hooks/useWindowScroll.js';
24
24
  import { useWindowResize } from '../../global/js/hooks/useWindowResize.js';
25
+ import { useIsomorphicEffect } from '../../global/js/hooks/useIsomorphicEffect.js';
25
26
  import { BreadcrumbWithOverflow } from '../BreadcrumbWithOverflow/BreadcrumbWithOverflow.js';
26
27
  import { ActionBar } from '../ActionBar/ActionBar.js';
27
28
  import { ButtonSetWithOverflow } from '../ButtonSetWithOverflow/ButtonSetWithOverflow.js';
@@ -362,6 +363,16 @@ var PageHeader = /*#__PURE__*/React__default.forwardRef(function (_ref, ref) {
362
363
  }
363
364
  };
364
365
  var displayedBreadcrumbs = getBreadcrumbs();
366
+ useIsomorphicEffect(function () {
367
+ Object.keys(pageHeaderStyles).forEach(function (key) {
368
+ // check if style is a css var
369
+ if (key.startsWith('--')) {
370
+ headerRef.current.style.setProperty(key, pageHeaderStyles[key]);
371
+ } else {
372
+ headerRef.current.style[key] = pageHeaderStyles[key];
373
+ }
374
+ });
375
+ }, [headerRef, pageHeaderStyles]);
365
376
  var subtitleRef = useRef(null);
366
377
  var isOverflowing = checkHeightOverflow(subtitleRef.current);
367
378
  var subtitleContent = /*#__PURE__*/React__default.createElement("span", {
@@ -373,7 +384,6 @@ var PageHeader = /*#__PURE__*/React__default.forwardRef(function (_ref, ref) {
373
384
  ref: offsetTopMeasuringRef
374
385
  }), /*#__PURE__*/React__default.createElement("section", _extends({}, rest, {
375
386
  className: cx([blockClass, "".concat(blockClass, "--no-margins-below-row"), className, _defineProperty(_defineProperty({}, "".concat(blockClass, "--has-navigation"), navigation || tags), "".concat(blockClass, "--has-navigation-tags-only"), !navigation && tags)]),
376
- style: pageHeaderStyles,
377
387
  ref: headerRef
378
388
  }, getDevtoolsProps(componentName)), /*#__PURE__*/React__default.createElement(FlexGrid, {
379
389
  fullWidth: fullWidthGrid === true || fullWidthGrid === 'xl',
@@ -6,13 +6,14 @@
6
6
  */
7
7
 
8
8
  import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, extends as _extends, defineProperty as _defineProperty } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React__default, { useState, useRef, useCallback, useEffect } from 'react';
9
+ import React__default, { useRef, useState, useCallback, useEffect } from 'react';
10
10
  import PropTypes from '../../_virtual/index.js';
11
11
  import cx from 'classnames';
12
12
  import { getDevtoolsProps } from '../../global/js/utils/devtools.js';
13
13
  import { pkg, carbon } from '../../settings.js';
14
14
  import { throttle } from 'lodash';
15
- import { ScrollStates, getScrollState, useIsOverflow, ScrollDirection } from './constants.js';
15
+ import { useIsOverflow, ScrollStates, getScrollState, ScrollDirection } from './constants.js';
16
+ import { useIsomorphicEffect } from '../../global/js/hooks/useIsomorphicEffect.js';
16
17
 
17
18
  var _excluded = ["children", "className", "color", "onScroll", "scrollElementClassName", "getScrollElementRef", "hideStartGradient"];
18
19
  var blockClass = "".concat(pkg.prefix, "--scroll-gradient");
@@ -42,6 +43,13 @@ var ScrollGradient = /*#__PURE__*/React__default.forwardRef(function (_ref, ref)
42
43
  _ref$hideStartGradien = _ref.hideStartGradient,
43
44
  hideStartGradient = _ref$hideStartGradien === void 0 ? defaults.hideStartGradient : _ref$hideStartGradien,
44
45
  rest = _objectWithoutProperties(_ref, _excluded);
46
+ var scrollContainer = useRef(undefined);
47
+ var contentChildrenContainer = useRef(undefined);
48
+ var _useIsOverflow = useIsOverflow(scrollContainer),
49
+ xScrollable = _useIsOverflow.xScrollable,
50
+ yScrollable = _useIsOverflow.yScrollable;
51
+ var gradientRight = yScrollable && scrollContainer.current && contentChildrenContainer.current ? scrollContainer.current.offsetWidth - contentChildrenContainer.current.offsetWidth : 0;
52
+ var gradientBottom = xScrollable && scrollContainer.current && contentChildrenContainer.current ? scrollContainer.current.offsetHeight - contentChildrenContainer.current.offsetHeight : 0;
45
53
  var _useState = useState(ScrollStates.NONE),
46
54
  _useState2 = _slicedToArray(_useState, 2),
47
55
  verticalPosition = _useState2[0],
@@ -50,8 +58,26 @@ var ScrollGradient = /*#__PURE__*/React__default.forwardRef(function (_ref, ref)
50
58
  _useState4 = _slicedToArray(_useState3, 2),
51
59
  horizontalPosition = _useState4[0],
52
60
  setHorizontalPosition = _useState4[1];
53
- var scrollContainer = useRef(undefined);
54
- var contentChildrenContainer = useRef(undefined);
61
+ var startVerticalRef = useRef(null);
62
+ var startHorizontalRef = useRef(null);
63
+ var endVerticalRef = useRef(null);
64
+ var endHorizontalRef = useRef(null);
65
+ useIsomorphicEffect(function () {
66
+ // start vertical styles
67
+ startVerticalRef.current.style.right = gradientRight;
68
+ startVerticalRef.current.style.backgroundImage = "linear-gradient(0deg, transparent, ".concat(color, " 90%)");
69
+ // start horizontal styles
70
+ startHorizontalRef.current.backgroundImage = "linear-gradient(-90deg, transparent, ".concat(color, " 90%)");
71
+ startHorizontalRef.current.bottom = gradientBottom;
72
+ // end vertical styles
73
+ endVerticalRef.current.style.right = gradientRight;
74
+ endVerticalRef.current.style.bottom = gradientBottom;
75
+ endVerticalRef.current.style.backgroundImage = "linear-gradient(0deg, ".concat(color, " 10%, transparent)");
76
+ // end horizontal styles
77
+ endHorizontalRef.current.style.right = gradientRight;
78
+ endHorizontalRef.current.style.bottom = gradientBottom;
79
+ endHorizontalRef.current.style.backgroundImage = "linear-gradient(-90deg, ".concat(color, " 10%, transparent)");
80
+ }, [color, gradientRight, gradientBottom]);
55
81
  var updateScrollState = throttle(function () {
56
82
  var updatedVerticalVal = getScrollState(scrollContainer.current, ScrollDirection.Y);
57
83
  var updatedHorizontalVal = getScrollState(scrollContainer.current, ScrollDirection.X);
@@ -69,11 +95,6 @@ var ScrollGradient = /*#__PURE__*/React__default.forwardRef(function (_ref, ref)
69
95
  useEffect(function () {
70
96
  scrollHandler();
71
97
  }, [scrollHandler]);
72
- var _useIsOverflow = useIsOverflow(scrollContainer),
73
- xScrollable = _useIsOverflow.xScrollable,
74
- yScrollable = _useIsOverflow.yScrollable;
75
- var gradientRight = yScrollable && scrollContainer.current && contentChildrenContainer.current ? scrollContainer.current.offsetWidth - contentChildrenContainer.current.offsetWidth : 0;
76
- var gradientBottom = xScrollable && scrollContainer.current && contentChildrenContainer.current ? scrollContainer.current.offsetHeight - contentChildrenContainer.current.offsetHeight : 0;
77
98
  return /*#__PURE__*/React__default.createElement("div", _extends({}, rest, {
78
99
  className: cx(blockClass, "".concat(blockClass, "--x-").concat(horizontalPosition.toLowerCase()), "".concat(blockClass, "--y-").concat(verticalPosition.toLowerCase()), _defineProperty(_defineProperty({}, "".concat(blockClass, "--x-scrollable"), xScrollable), "".concat(blockClass, "--y-scrollable"), yScrollable), className),
79
100
  ref: ref,
@@ -87,37 +108,23 @@ var ScrollGradient = /*#__PURE__*/React__default.forwardRef(function (_ref, ref)
87
108
  ref: contentChildrenContainer,
88
109
  className: "".concat(blockClass, "__content-children")
89
110
  }, children)), !hideStartGradient && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", {
111
+ ref: startVerticalRef,
90
112
  className: "".concat(blockClass, "__start-vertical"),
91
- style: {
92
- right: gradientRight,
93
- backgroundImage: "linear-gradient(0deg, transparent, ".concat(color, " 90%)")
94
- },
95
113
  role: "presentation",
96
114
  "aria-hidden": true
97
115
  }), /*#__PURE__*/React__default.createElement("div", {
116
+ ref: startHorizontalRef,
98
117
  className: "".concat(blockClass, "__start-horizontal"),
99
- style: {
100
- backgroundImage: "linear-gradient(-90deg, transparent, ".concat(color, " 90%)"),
101
- bottom: gradientBottom
102
- },
103
118
  role: "presentation",
104
119
  "aria-hidden": true
105
120
  })), /*#__PURE__*/React__default.createElement("div", {
121
+ ref: endVerticalRef,
106
122
  className: "".concat(blockClass, "__end-vertical"),
107
- style: {
108
- right: gradientRight,
109
- bottom: gradientBottom,
110
- backgroundImage: "linear-gradient(0deg, ".concat(color, " 10%, transparent)")
111
- },
112
123
  role: "presentation",
113
124
  "aria-hidden": true
114
125
  }), /*#__PURE__*/React__default.createElement("div", {
126
+ ref: endHorizontalRef,
115
127
  className: "".concat(blockClass, "__end-horizontal"),
116
- style: {
117
- right: gradientRight,
118
- bottom: gradientBottom,
119
- backgroundImage: "linear-gradient(-90deg, ".concat(color, " 10%, transparent)")
120
- },
121
128
  role: "presentation",
122
129
  "aria-hidden": true
123
130
  }));
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import { objectWithoutProperties as _objectWithoutProperties, defineProperty as _defineProperty, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React__default from 'react';
9
+ import React__default, { useRef } from 'react';
10
10
  import PropTypes from '../../_virtual/index.js';
11
11
  import cx from 'classnames';
12
12
  import { getDevtoolsProps } from '../../global/js/utils/devtools.js';
@@ -14,6 +14,7 @@ import { pkg } from '../../settings.js';
14
14
  import { DefinitionTooltip } from '@carbon/react';
15
15
  import { propMappingFunction, StringFormatterAlignment, deprecated_StringFormatterAlignment } from './utils/enums.js';
16
16
  import { allPropTypes } from '../../global/js/utils/props-helper.js';
17
+ import { useIsomorphicEffect } from '../../global/js/hooks/useIsomorphicEffect.js';
17
18
 
18
19
  var _excluded = ["className", "lines", "tooltipDirection", "truncate", "width", "value"];
19
20
  var blockClass = "".concat(pkg.prefix, "--string-formatter");
@@ -41,12 +42,14 @@ var StringFormatter = /*#__PURE__*/React__default.forwardRef(function (_ref, ref
41
42
  width = _ref$width === void 0 ? defaults.width : _ref$width,
42
43
  value = _ref.value,
43
44
  rest = _objectWithoutProperties(_ref, _excluded);
45
+ var contentRef = useRef(null);
46
+ useIsomorphicEffect(function () {
47
+ contentRef.current.style.maxWidth = width;
48
+ contentRef.current.style.WebkitLineClamp = lines;
49
+ }, [lines, width]);
44
50
  var stringFormatterContent = /*#__PURE__*/React__default.createElement("span", {
45
- className: cx("".concat(blockClass, "--content"), _defineProperty({}, "".concat(blockClass, "--truncate"), truncate)),
46
- style: {
47
- maxWidth: width,
48
- WebkitLineClamp: lines
49
- }
51
+ ref: contentRef,
52
+ className: cx("".concat(blockClass, "--content"), _defineProperty({}, "".concat(blockClass, "--truncate"), truncate))
50
53
  }, value);
51
54
  return /*#__PURE__*/React__default.createElement("span", _extends({}, rest, {
52
55
  className: cx(blockClass, className),
@@ -26,10 +26,19 @@ export interface TagOverflowProps {
26
26
  allTagsModalTitle?: string;
27
27
  autoAlign?: boolean;
28
28
  className?: string;
29
- containingElementRef?: RefObject<HTMLElement>;
29
+ /**
30
+ * @deprecated The `containingElementRef` prop is no longer going to be used in favor of the forwarded ref.
31
+ */
32
+ containingElementRef?: RefObject<HTMLDivElement>;
30
33
  items: TagOverflowItem[];
31
34
  maxVisible?: number;
35
+ /**
36
+ * @deprecated The `measurementOffset` prop is no longer going to be used. This value will now be calculated automatically.
37
+ */
32
38
  measurementOffset?: number;
39
+ /**
40
+ * @deprecated The `multiline` prop is no longer going to be used. This component should only be used when you need to hide overflowing items.
41
+ */
33
42
  multiline?: boolean;
34
43
  overflowAlign?: 'top' | 'top-left' | 'top-right' | 'bottom' | 'bottom-left' | 'bottom-right' | 'left' | 'left-bottom' | 'left-top' | 'right' | 'right-bottom' | 'right-top';
35
44
  overflowClassName?: string;
@@ -5,8 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, objectSpread2 as _objectSpread2, extends as _extends, defineProperty as _defineProperty } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React__default, { forwardRef, useRef, useState, useCallback, useEffect, createElement } from 'react';
8
+ import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, extends as _extends, objectSpread2 as _objectSpread2 } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
+ import React__default, { forwardRef, useRef, useState, useCallback, createElement } from 'react';
10
10
  import { DismissibleTag, Tag } from '@carbon/react';
11
11
  import PropTypes from '../../_virtual/index.js';
12
12
  import { TYPES } from './constants.js';
@@ -16,12 +16,11 @@ import cx from 'classnames';
16
16
  import { getDevtoolsProps } from '../../global/js/utils/devtools.js';
17
17
  import { isRequiredIf } from '../../global/js/utils/props-helper.js';
18
18
  import { pkg } from '../../settings.js';
19
- import { useResizeObserver } from '../../global/js/hooks/useResizeObserver.js';
19
+ import { useOverflowItems } from '../../global/js/hooks/useOverflowItems.js';
20
20
 
21
- var _excluded = ["align", "allTagsModalAriaLabel", "allTagsModalSearchLabel", "allTagsModalSearchPlaceholderText", "allTagsModalTarget", "allTagsModalTitle", "autoAlign", "className", "containingElementRef", "items", "maxVisible", "measurementOffset", "multiline", "overflowAlign", "overflowClassName", "overflowType", "onOverflowTagChange", "showAllTagsLabel", "tagComponent"],
22
- _excluded2 = ["className", "id"],
23
- _excluded3 = ["tagType"],
24
- _excluded4 = ["id", "label", "tagType", "onClose", "filter"];
21
+ var _excluded = ["align", "allTagsModalAriaLabel", "allTagsModalSearchLabel", "allTagsModalSearchPlaceholderText", "allTagsModalTarget", "allTagsModalTitle", "autoAlign", "className", "items", "maxVisible", "overflowAlign", "overflowClassName", "overflowType", "onOverflowTagChange", "showAllTagsLabel", "tagComponent"],
22
+ _excluded2 = ["className"],
23
+ _excluded3 = ["id", "label", "tagType", "onClose", "filter"];
25
24
  var blockClass = "".concat(pkg.prefix, "--tag-overflow");
26
25
  var componentName = 'TagOverflow';
27
26
  var allTagsModalSearchThreshold = 10;
@@ -35,12 +34,8 @@ var TagOverflow = /*#__PURE__*/forwardRef(function (props, ref) {
35
34
  allTagsModalTitle = props.allTagsModalTitle,
36
35
  autoAlign = props.autoAlign,
37
36
  className = props.className,
38
- containingElementRef = props.containingElementRef,
39
37
  items = props.items,
40
38
  maxVisible = props.maxVisible,
41
- _props$measurementOff = props.measurementOffset,
42
- measurementOffset = _props$measurementOff === void 0 ? 0 : _props$measurementOff,
43
- multiline = props.multiline,
44
39
  _props$overflowAlign = props.overflowAlign,
45
40
  overflowAlign = _props$overflowAlign === void 0 ? 'bottom' : _props$overflowAlign,
46
41
  overflowClassName = props.overflowClassName,
@@ -50,119 +45,33 @@ var TagOverflow = /*#__PURE__*/forwardRef(function (props, ref) {
50
45
  showAllTagsLabel = props.showAllTagsLabel,
51
46
  tagComponent = props.tagComponent,
52
47
  rest = _objectWithoutProperties(props, _excluded);
53
- var localContainerRef = useRef(null);
54
- var containerRef = ref || localContainerRef;
55
- var itemRefs = useRef(null);
56
- var overflowRef = useRef(null);
57
- // itemOffset is the value of margin applied on each items
58
- // This value is required for calculating how many items will fit within the container
59
- var itemOffset = 4;
60
- var overflowIndicatorWidth = 40;
61
- var _useState = useState(0),
48
+ var containerRef = useRef(null);
49
+ var offsetRef = useRef(null);
50
+ var _useState = useState(false),
62
51
  _useState2 = _slicedToArray(_useState, 2),
63
- containerWidth = _useState2[0],
64
- setContainerWidth = _useState2[1];
65
- var _useState3 = useState([]),
52
+ showAllModalOpen = _useState2[0],
53
+ setShowAllModalOpen = _useState2[1];
54
+ var _useState3 = useState(false),
66
55
  _useState4 = _slicedToArray(_useState3, 2),
67
- visibleItems = _useState4[0],
68
- setVisibleItems = _useState4[1];
69
- var _useState5 = useState([]),
70
- _useState6 = _slicedToArray(_useState5, 2),
71
- overflowItems = _useState6[0],
72
- setOverflowItems = _useState6[1];
73
- var _useState7 = useState(false),
74
- _useState8 = _slicedToArray(_useState7, 2),
75
- showAllModalOpen = _useState8[0],
76
- setShowAllModalOpen = _useState8[1];
77
- var _useState9 = useState(false),
78
- _useState10 = _slicedToArray(_useState9, 2),
79
- popoverOpen = _useState10[0],
80
- setPopoverOpen = _useState10[1];
81
- var resizeElm = containingElementRef && containingElementRef.current ? containingElementRef : containerRef;
56
+ popoverOpen = _useState4[0],
57
+ setPopoverOpen = _useState4[1];
58
+ var _useOverflowItems = useOverflowItems(items, containerRef, offsetRef, maxVisible, onOverflowTagChange),
59
+ visibleItems = _useOverflowItems.visibleItems,
60
+ overflowItems = _useOverflowItems.hiddenItems,
61
+ itemRefHandler = _useOverflowItems.itemRefHandler;
82
62
  var handleShowAllClick = function handleShowAllClick() {
83
63
  setShowAllModalOpen(true);
84
64
  };
85
65
  var handleModalClose = function handleModalClose() {
86
66
  setShowAllModalOpen(false);
87
67
  };
88
- var handleResize = function handleResize() {
89
- if (typeof resizeElm !== 'function' && resizeElm.current) {
90
- setContainerWidth(resizeElm.current.offsetWidth);
91
- }
92
- };
93
- useResizeObserver(resizeElm, handleResize);
94
- var getMap = function getMap() {
95
- if (!itemRefs.current) {
96
- itemRefs.current = new Map();
97
- }
98
- return itemRefs.current;
99
- };
100
- var itemRefHandler = function itemRefHandler(id, node) {
101
- var map = getMap();
102
- if (id && node && map.get(id) !== node.offsetWidth) {
103
- map.set(id, node.offsetWidth);
104
- }
105
- };
106
- var getVisibleItems = useCallback(function () {
107
- if (!itemRefs.current) {
108
- return items;
109
- }
110
- if (multiline) {
111
- var _visibleItems = maxVisible ? items === null || items === void 0 ? void 0 : items.slice(0, maxVisible) : items;
112
- return _visibleItems;
113
- }
114
- var map = getMap();
115
- var optionalContainingElement = containingElementRef === null || containingElementRef === void 0 ? void 0 : containingElementRef.current;
116
- var measurementOffsetValue = typeof measurementOffset === 'number' ? measurementOffset : 0;
117
- var spaceAvailable = optionalContainingElement ? optionalContainingElement.offsetWidth - measurementOffsetValue : containerWidth;
118
- var overflowContainerWidth = overflowRef && overflowRef.current && overflowRef.current.offsetWidth > overflowIndicatorWidth ? overflowRef.current.offsetWidth : overflowIndicatorWidth;
119
- var maxWidth = spaceAvailable - overflowContainerWidth;
120
- var childrenWidth = 0;
121
- var maxReached = false;
122
- return items.reduce(function (prev, cur) {
123
- if (!maxReached) {
124
- var itemWidth = (map ? Number(map.get(cur.id)) : 0) + itemOffset;
125
- var fits = itemWidth + childrenWidth < maxWidth;
126
- if (fits) {
127
- childrenWidth += itemWidth;
128
- prev.push(cur);
129
- } else {
130
- maxReached = true;
131
- }
132
- }
133
- return prev;
134
- }, []);
135
- }, [containerWidth, containingElementRef, items, maxVisible, measurementOffset, multiline]);
136
68
  var getCustomComponent = function getCustomComponent(item, tagComponent) {
137
69
  var className = item.className,
138
- id = item.id,
139
70
  other = _objectWithoutProperties(item, _excluded2);
140
71
  return /*#__PURE__*/createElement(tagComponent, _objectSpread2(_objectSpread2({}, other), {}, {
141
- key: id,
142
- className: cx("".concat(blockClass, "__item"), className),
143
- ref: function ref(node) {
144
- return itemRefHandler(id, node);
145
- }
72
+ className: cx("".concat(blockClass, "__item"), className)
146
73
  }));
147
74
  };
148
- useEffect(function () {
149
- var visibleItemsArr = getVisibleItems();
150
- if (maxVisible && maxVisible < visibleItemsArr.length) {
151
- var _visibleItemsArr;
152
- visibleItemsArr = (_visibleItemsArr = visibleItemsArr) === null || _visibleItemsArr === void 0 ? void 0 : _visibleItemsArr.slice(0, maxVisible);
153
- }
154
- var hiddenItems = items === null || items === void 0 ? void 0 : items.slice(visibleItemsArr.length);
155
- var overflowItemsArr = hiddenItems === null || hiddenItems === void 0 ? void 0 : hiddenItems.map(function (_ref) {
156
- var tagType = _ref.tagType,
157
- other = _objectWithoutProperties(_ref, _excluded3);
158
- return _objectSpread2({
159
- type: tagType
160
- }, other);
161
- });
162
- setVisibleItems(visibleItemsArr);
163
- setOverflowItems(overflowItemsArr);
164
- onOverflowTagChange === null || onOverflowTagChange === void 0 || onOverflowTagChange(overflowItemsArr);
165
- }, [getVisibleItems, items, maxVisible, onOverflowTagChange]);
166
75
  var handleTagOnClose = useCallback(function (onClose, index) {
167
76
  onClose === null || onClose === void 0 || onClose();
168
77
  if (index <= (visibleItems === null || visibleItems === void 0 ? void 0 : visibleItems.length) - 1) {
@@ -170,41 +79,40 @@ var TagOverflow = /*#__PURE__*/forwardRef(function (props, ref) {
170
79
  }
171
80
  }, [visibleItems]);
172
81
  return /*#__PURE__*/React__default.createElement("div", _extends({}, rest, {
173
- className: cx(blockClass, className, "".concat(blockClass, "--align-").concat(align), _defineProperty({}, "".concat(blockClass, "--multiline"), multiline)),
82
+ className: cx(blockClass, className)
83
+ }, getDevtoolsProps(componentName), {
84
+ ref: ref
85
+ }), /*#__PURE__*/React__default.createElement("div", {
86
+ className: cx("".concat(blockClass, "__visible-tags"), "".concat(blockClass, "--align-").concat(align)),
174
87
  ref: containerRef
175
- }, getDevtoolsProps(componentName)), (visibleItems === null || visibleItems === void 0 ? void 0 : visibleItems.length) > 0 && visibleItems.map(function (item, index) {
176
- // Render custom components
177
- if (tagComponent) {
178
- return getCustomComponent(item, tagComponent);
179
- } else {
180
- var id = item.id,
181
- label = item.label,
182
- tagType = item.tagType,
183
- _onClose = item.onClose,
184
- filter = item.filter,
185
- other = _objectWithoutProperties(item, _excluded4);
186
- // If there is no template prop, then render items as Tags
187
- return /*#__PURE__*/React__default.createElement("div", {
188
- ref: function ref(node) {
189
- return itemRefHandler(id, node);
190
- },
191
- key: id
192
- }, typeof _onClose === 'function' || filter ? /*#__PURE__*/React__default.createElement(DismissibleTag, _extends({}, other, {
193
- className: "".concat(blockClass, "__item--tag"),
194
- type: tagType,
195
- onClose: function onClose() {
196
- return handleTagOnClose(_onClose, index);
197
- },
198
- text: label
199
- })) : /*#__PURE__*/React__default.createElement(Tag, _extends({}, other, {
200
- className: "".concat(blockClass, "__item--tag"),
201
- type: tagType
202
- }), label));
203
- }
204
- }), /*#__PURE__*/React__default.createElement("span", {
88
+ }, visibleItems.map(function (item, index) {
89
+ var id = item.id,
90
+ label = item.label,
91
+ tagType = item.tagType,
92
+ _onClose = item.onClose,
93
+ filter = item.filter,
94
+ other = _objectWithoutProperties(item, _excluded3);
95
+ return /*#__PURE__*/React__default.createElement("div", {
96
+ className: "".concat(blockClass, "__tag-container"),
97
+ ref: function ref(node) {
98
+ itemRefHandler(id, node);
99
+ },
100
+ key: id
101
+ }, tagComponent ? getCustomComponent(item, tagComponent) : typeof _onClose === 'function' || filter ? /*#__PURE__*/React__default.createElement(DismissibleTag, _extends({}, other, {
102
+ className: "".concat(blockClass, "__item--tag"),
103
+ type: tagType,
104
+ onClose: function onClose() {
105
+ return handleTagOnClose(_onClose, index);
106
+ },
107
+ text: label
108
+ })) : /*#__PURE__*/React__default.createElement(Tag, _extends({}, other, {
109
+ className: "".concat(blockClass, "__item--tag"),
110
+ type: tagType
111
+ }), label));
112
+ }), overflowItems.length > 0 && /*#__PURE__*/React__default.createElement("div", {
205
113
  className: "".concat(blockClass, "__indicator"),
206
- ref: overflowRef
207
- }, (overflowItems === null || overflowItems === void 0 ? void 0 : overflowItems.length) > 0 && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(TagOverflowPopover, {
114
+ ref: offsetRef
115
+ }, /*#__PURE__*/React__default.createElement(TagOverflowPopover, {
208
116
  allTagsModalSearchThreshold: allTagsModalSearchThreshold,
209
117
  className: overflowClassName,
210
118
  onShowAllClick: handleShowAllClick,
@@ -213,7 +121,7 @@ var TagOverflow = /*#__PURE__*/forwardRef(function (props, ref) {
213
121
  overflowType: overflowType,
214
122
  showAllTagsLabel: showAllTagsLabel,
215
123
  key: "tag-overflow-popover",
216
- ref: overflowRef,
124
+ ref: offsetRef,
217
125
  popoverOpen: popoverOpen,
218
126
  setPopoverOpen: setPopoverOpen,
219
127
  autoAlign: autoAlign
@@ -242,8 +150,8 @@ var tagTypes = Object.keys(TYPES);
242
150
  * The strings shown in the showAllModal are only shown if we have more than allTagsModalSearchLThreshold
243
151
  * @returns null if no problems
244
152
  */
245
- var string_required_if_more_than_10_tags = isRequiredIf(PropTypes.string, function (_ref2) {
246
- var items = _ref2.items;
153
+ var string_required_if_more_than_10_tags = isRequiredIf(PropTypes.string, function (_ref) {
154
+ var items = _ref.items;
247
155
  return (items === null || items === void 0 ? void 0 : items.length) > allTagsModalSearchThreshold;
248
156
  });
249
157
 
@@ -8,19 +8,6 @@
8
8
  import { type ButtonProps } from '@carbon/react';
9
9
  import React, { PropsWithChildren, ReactNode } from 'react';
10
10
  import PropTypes from 'prop-types';
11
- /**
12
- * The accessibility title for the close icon (if shown).
13
- *
14
- * **Note:** This prop is only required if a close icon is shown, i.e. if
15
- * there are a no navigation actions and/or hasCloseIcon is true.
16
- */
17
- export type CloseIconDescriptionTypes = {
18
- hasCloseIcon?: false;
19
- closeIconDescription?: string;
20
- } | {
21
- hasCloseIcon: true;
22
- closeIconDescription: string;
23
- };
24
11
  export interface TearsheetAction extends ButtonProps<'button'> {
25
12
  label?: string;
26
13
  }
@@ -48,6 +35,11 @@ export interface TearsheetProps extends PropsWithChildren {
48
35
  * An optional class or classes to be added to the outermost element.
49
36
  */
50
37
  className?: string;
38
+ /**
39
+ * The accessibility title for the close icon (if shown).
40
+ *
41
+ */
42
+ closeIconDescription?: string;
51
43
  /**
52
44
  * A description of the flow, displayed in the header area of the tearsheet.
53
45
  */
@@ -145,7 +137,7 @@ export interface TearsheetProps extends PropsWithChildren {
145
137
  * panel on either the left or right side, the main content area, and a set of
146
138
  * action buttons.
147
139
  */
148
- export declare let Tearsheet: React.ForwardRefExoticComponent<(TearsheetProps & CloseIconDescriptionTypes) & React.RefAttributes<HTMLDivElement>>;
140
+ export declare let Tearsheet: React.ForwardRefExoticComponent<TearsheetProps & React.RefAttributes<HTMLDivElement>>;
149
141
  export declare const deprecatedProps: {
150
142
  /**
151
143
  * **Deprecated**