@carbon/ibm-products 2.17.2 → 2.18.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. package/css/index-full-carbon.css +13188 -12116
  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 +5 -2
  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 +5710 -6367
  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 +5 -2
  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/Carousel/Carousel.docs-page.js +11 -0
  18. package/es/components/Carousel/Carousel.js +322 -0
  19. package/es/components/Carousel/CarouselItem.js +53 -0
  20. package/es/components/Carousel/index.js +9 -0
  21. package/es/components/Carousel/utils.js +98 -0
  22. package/es/components/Datagrid/Datagrid/DatagridToolbar.js +4 -2
  23. package/es/components/Datagrid/Datagrid/addons/Filtering/hooks/useFilters.js +4 -3
  24. package/es/components/Datagrid/Extensions/Filtering/Filtering.docs-page.js +7 -1
  25. package/es/components/Datagrid/utils/handleFilterTagLabelText.js +26 -0
  26. package/es/components/FilterSummary/FilterSummary.js +21 -7
  27. package/es/components/Guidebanner/Guidebanner.docs-page.js +15 -0
  28. package/es/components/Guidebanner/Guidebanner.js +221 -0
  29. package/es/components/Guidebanner/GuidebannerElement.js +72 -0
  30. package/es/components/Guidebanner/GuidebannerElementButton.js +80 -0
  31. package/es/components/Guidebanner/GuidebannerElementLink.js +57 -0
  32. package/es/components/Guidebanner/index.js +11 -0
  33. package/es/components/NonLinearReading/NonLinearReading.docs-page.js +15 -0
  34. package/es/components/NonLinearReading/NonLinearReading.js +89 -0
  35. package/es/components/NonLinearReading/index.js +8 -0
  36. package/es/components/SidePanel/SidePanel.js +9 -8
  37. package/es/components/TagSet/TagSet.js +22 -5
  38. package/es/components/WebTerminal/WebTerminal.js +5 -3
  39. package/es/global/js/package-settings.js +6 -1
  40. package/lib/components/Carousel/Carousel.docs-page.js +21 -0
  41. package/lib/components/Carousel/Carousel.js +329 -0
  42. package/lib/components/Carousel/CarouselItem.js +54 -0
  43. package/lib/components/Carousel/index.js +19 -0
  44. package/lib/components/Carousel/utils.js +105 -0
  45. package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +4 -2
  46. package/lib/components/Datagrid/Datagrid/addons/Filtering/hooks/useFilters.js +4 -3
  47. package/lib/components/Datagrid/Extensions/Filtering/Filtering.docs-page.js +7 -1
  48. package/lib/components/Datagrid/utils/handleFilterTagLabelText.js +32 -0
  49. package/lib/components/FilterSummary/FilterSummary.js +24 -7
  50. package/lib/components/Guidebanner/Guidebanner.docs-page.js +25 -0
  51. package/lib/components/Guidebanner/Guidebanner.js +229 -0
  52. package/lib/components/Guidebanner/GuidebannerElement.js +77 -0
  53. package/lib/components/Guidebanner/GuidebannerElementButton.js +85 -0
  54. package/lib/components/Guidebanner/GuidebannerElementLink.js +62 -0
  55. package/lib/components/Guidebanner/index.js +33 -0
  56. package/lib/components/NonLinearReading/NonLinearReading.docs-page.js +25 -0
  57. package/lib/components/NonLinearReading/NonLinearReading.js +97 -0
  58. package/lib/components/NonLinearReading/index.js +12 -0
  59. package/lib/components/SidePanel/SidePanel.js +9 -8
  60. package/lib/components/TagSet/TagSet.js +22 -5
  61. package/lib/components/WebTerminal/WebTerminal.js +4 -2
  62. package/lib/global/js/package-settings.js +6 -1
  63. package/package.json +5 -4
  64. package/scss/components/Carousel/_carbon-imports.scss +6 -0
  65. package/scss/components/Carousel/_carousel.scss +72 -0
  66. package/scss/components/Carousel/_index-with-carbon.scss +9 -0
  67. package/scss/components/Carousel/_index.scss +8 -0
  68. package/scss/components/Checklist/_carbon-imports.scss +11 -0
  69. package/scss/components/Checklist/_checklist.scss +0 -1
  70. package/scss/components/Checklist/_index-with-carbon.scss +9 -0
  71. package/scss/components/FilterSummary/_filter-summary.scss +6 -1
  72. package/scss/components/Guidebanner/_carbon-imports.scss +6 -0
  73. package/scss/components/Guidebanner/_guidebanner.scss +248 -0
  74. package/scss/components/Guidebanner/_index-with-carbon.scss +9 -0
  75. package/scss/components/Guidebanner/_index.scss +8 -0
  76. package/scss/components/NonLinearReading/_carbon-imports.scss +6 -0
  77. package/scss/components/NonLinearReading/_index-with-carbon.scss +9 -0
  78. package/scss/components/NonLinearReading/_index.scss +8 -0
  79. package/scss/components/NonLinearReading/_non-linear-reading.scss +122 -0
  80. package/scss/components/WebTerminal/_web-terminal.scss +1 -2
  81. package/scss/components/_Canary/_canary.scss +1 -2
  82. package/scss/components/_Canary/_carbon-imports.scss +7 -0
  83. package/scss/components/_Canary/_index-with-carbon.scss +8 -0
  84. package/scss/components/_Canary/_index.scss +7 -0
  85. package/scss/components/_index-with-carbon.scss +1 -1
  86. package/scss/components/_index.scss +5 -2
  87. /package/es/components/Datagrid/{Extensions → Datagrid.stories}/ColumnAlignment/ColumnAlignment.docs-page.js +0 -0
  88. /package/lib/components/Datagrid/{Extensions → Datagrid.stories}/ColumnAlignment/ColumnAlignment.docs-page.js +0 -0
@@ -2,13 +2,13 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _extends from "@babel/runtime/helpers/extends";
3
3
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
5
- var _excluded = ["align", "allTagsModalTarget", "className", "maxVisible", "multiline", "overflowAlign", "overflowClassName", "overflowType", "allTagsModalTitle", "allTagsModalSearchLabel", "allTagsModalSearchPlaceholderText", "showAllTagsLabel", "tags"],
5
+ var _excluded = ["align", "allTagsModalTarget", "className", "maxVisible", "multiline", "overflowAlign", "overflowClassName", "overflowType", "allTagsModalTitle", "allTagsModalSearchLabel", "allTagsModalSearchPlaceholderText", "showAllTagsLabel", "tags", "containingElementRef", "measurementOffset"],
6
6
  _excluded2 = ["label", "id"],
7
7
  _excluded3 = ["label"];
8
8
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
9
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
10
  //
11
- // Copyright IBM Corp. 2020, 2022
11
+ // Copyright IBM Corp. 2020, 2023
12
12
  //
13
13
  // This source code is licensed under the Apache-2.0 license found in the
14
14
  // LICENSE file in the root directory of this source tree.
@@ -31,6 +31,7 @@ var allTagsModalSearchThreshold = 10;
31
31
  // Default values for props
32
32
  var defaults = {
33
33
  align: 'start',
34
+ measurementOffset: 0,
34
35
  overflowAlign: 'bottom',
35
36
  overflowType: 'default'
36
37
  };
@@ -51,6 +52,9 @@ export var TagSet = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
51
52
  allTagsModalSearchPlaceholderText = _ref.allTagsModalSearchPlaceholderText,
52
53
  showAllTagsLabel = _ref.showAllTagsLabel,
53
54
  tags = _ref.tags,
55
+ containingElementRef = _ref.containingElementRef,
56
+ _ref$measurementOffse = _ref.measurementOffset,
57
+ measurementOffset = _ref$measurementOffse === void 0 ? defaults.measurementOffset : _ref$measurementOffse,
54
58
  rest = _objectWithoutProperties(_ref, _excluded);
55
59
  var _useState = useState(3),
56
60
  _useState2 = _slicedToArray(_useState, 2),
@@ -141,7 +145,9 @@ export var TagSet = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
141
145
  // how many will fit?
142
146
  var willFit = 0;
143
147
  if (sizingTags.length > 0) {
144
- var spaceAvailable = tagSetRef.current.offsetWidth;
148
+ var optionalContainingElement = containingElementRef === null || containingElementRef === void 0 ? void 0 : containingElementRef.current;
149
+ var measurementOffsetValue = typeof measurementOffset === 'number' ? measurementOffset : 0;
150
+ var spaceAvailable = optionalContainingElement ? optionalContainingElement.offsetWidth - measurementOffsetValue : tagSetRef.current.offsetWidth;
145
151
  for (var i in sizingTags) {
146
152
  var _sizingTags$i;
147
153
  var tagWidth = ((_sizingTags$i = sizingTags[i]) === null || _sizingTags$i === void 0 ? void 0 : _sizingTags$i.offsetWidth) || 0;
@@ -165,7 +171,7 @@ export var TagSet = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
165
171
  } else {
166
172
  setDisplayCount(maxVisible ? Math.min(willFit, maxVisible) : willFit);
167
173
  }
168
- }, [maxVisible, multiline, sizingTags, tagSetRef]);
174
+ }, [maxVisible, multiline, sizingTags, tagSetRef, measurementOffset, containingElementRef]);
169
175
  useEffect(function () {
170
176
  checkFullyVisibleTags();
171
177
  }, [checkFullyVisibleTags, maxVisible, multiline, sizingTags]);
@@ -187,7 +193,8 @@ export var TagSet = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
187
193
  setShowAllModalOpen(false);
188
194
  };
189
195
  useResizeObserver(sizingContainerRef, handleSizerTagsResize);
190
- useResizeObserver(tagSetRef, handleResize);
196
+ var resizeOption = containingElementRef ? containingElementRef : tagSetRef;
197
+ useResizeObserver(resizeOption, handleResize);
191
198
  return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
192
199
  className: cx([blockClass, className]),
193
200
  ref: tagSetRef
@@ -265,10 +272,20 @@ TagSet.propTypes = {
265
272
  * className
266
273
  */
267
274
  className: PropTypes.string,
275
+ /**
276
+ * Optional ref for custom resize container to measure available space
277
+ * Default will measure the available space of the TagSet container itself.
278
+ */
279
+ containingElementRef: PropTypes.object,
268
280
  /**
269
281
  * maximum visible tags
270
282
  */
271
283
  maxVisible: PropTypes.number,
284
+ /**
285
+ * Specify offset amount for measure available space, only used when `containingElementSelector`
286
+ * is also provided
287
+ */
288
+ measurementOffset: PropTypes.number,
272
289
  /**
273
290
  * display tags in multiple lines
274
291
  */
@@ -23,7 +23,7 @@ import { pkg } from '../../settings';
23
23
 
24
24
  // Carbon and package components we use.
25
25
  import { Close, Help } from '@carbon/react/icons';
26
- import { Button, OverflowMenu, OverflowMenuItem } from '@carbon/react';
26
+ import { Button, OverflowMenu, OverflowMenuItem, Theme } from '@carbon/react';
27
27
  import { moderate02 } from '@carbon/motion';
28
28
  import { useWebTerminal } from './hooks';
29
29
  import { getDevtoolsProps } from '../../global/js/utils/devtools';
@@ -158,9 +158,11 @@ export var WebTerminal = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
158
158
  onAnimationEnd: function onAnimationEnd(event) {
159
159
  return event.stopPropagation();
160
160
  }
161
- })), /*#__PURE__*/React.createElement("div", {
161
+ })), /*#__PURE__*/React.createElement(Theme, {
162
+ theme: "g100"
163
+ }, /*#__PURE__*/React.createElement("div", {
162
164
  className: "".concat(blockClass, "__body")
163
- }, children)) : null;
165
+ }, children))) : null;
164
166
  });
165
167
 
166
168
  // Return a placeholder if not released and not enabled by feature flag
@@ -73,7 +73,12 @@ var defaults = {
73
73
 
74
74
  // Novice to pro components not yet reviewed and released:
75
75
  Checklist: false,
76
- InlineTip: false
76
+ Guidebanner: false,
77
+ GuidebannerElement: false,
78
+ GuidebannerElementButton: false,
79
+ GuidebannerElementLink: false,
80
+ InlineTip: false,
81
+ NonLinearReading: false
77
82
  },
78
83
  // feature level flags
79
84
  feature: {
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+ var _react = _interopRequireDefault(require("react"));
10
+ var _StoryDocsPage = require("../../global/js/utils/StoryDocsPage");
11
+ var stories = _interopRequireWildcard(require("./Carousel.stories"));
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
+ var DocsPage = function DocsPage() {
15
+ return /*#__PURE__*/_react.default.createElement(_StoryDocsPage.StoryDocsPage, {
16
+ blocks: [{
17
+ story: stories.carousel
18
+ }]
19
+ });
20
+ };
21
+ var _default = exports.default = DocsPage;
@@ -0,0 +1,329 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.Carousel = void 0;
9
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
+ var _react = _interopRequireWildcard(require("react"));
12
+ var _propTypes = _interopRequireDefault(require("prop-types"));
13
+ var _CarouselItem = require("./CarouselItem");
14
+ var _classnames = _interopRequireDefault(require("classnames"));
15
+ var _devtools = require("../../global/js/utils/devtools");
16
+ var _settings = require("../../settings");
17
+ var _excluded = ["children", "className", "disableArrowScroll", "fadedEdgeColor", "onChangeIsScrollable", "onScroll"];
18
+ /**
19
+ * Copyright IBM Corp. 2023, 2023
20
+ *
21
+ * This source code is licensed under the Apache-2.0 license found in the
22
+ * LICENSE file in the root directory of this source tree.
23
+ */
24
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
25
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
26
+ // The block part of our conventional BEM class names (blockClass__E--M).
27
+ var blockClass = "".concat(_settings.pkg.prefix, "--carousel");
28
+ var componentName = 'Carousel';
29
+
30
+ // Default values for props
31
+ var defaults = {
32
+ disableArrowScroll: false,
33
+ onScroll: function onScroll() {},
34
+ onChangeIsScrollable: function onChangeIsScrollable() {}
35
+ };
36
+
37
+ /**
38
+ * The Carousel acts as a scaffold for other Novice to Pro content.
39
+ *
40
+ * This component is not intended for general use.
41
+ *
42
+ * Expected scrolling behavior.
43
+ * 1. Scroll the maximum number of visible items at a time.
44
+ * 2. The left-most item should always be left-aligned in the viewport.
45
+ *
46
+ * Exception.
47
+ * 1. After scrolling to the last (right-most) item,
48
+ * if some of its content remains hidden,
49
+ * then nudge it to the right until it is right-aligned.
50
+ * 2. From the right-aligned position, when scrolling left,
51
+ * the left-most item should again be left-aligned.
52
+ */
53
+ var Carousel = exports.Carousel = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
54
+ var children = _ref.children,
55
+ className = _ref.className,
56
+ _ref$disableArrowScro = _ref.disableArrowScroll,
57
+ disableArrowScroll = _ref$disableArrowScro === void 0 ? defaults.disableArrowScroll : _ref$disableArrowScro,
58
+ fadedEdgeColor = _ref.fadedEdgeColor,
59
+ _ref$onChangeIsScroll = _ref.onChangeIsScrollable,
60
+ onChangeIsScrollable = _ref$onChangeIsScroll === void 0 ? defaults.onChangeIsScrollable : _ref$onChangeIsScroll,
61
+ _ref$onScroll = _ref.onScroll,
62
+ onScroll = _ref$onScroll === void 0 ? defaults.onScroll : _ref$onScroll,
63
+ rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
64
+ var carouselRef = (0, _react.useRef)();
65
+ var scrollRef = (0, _react.useRef)();
66
+ // Array of refs used to reference this component's children DOM elements
67
+ var childElementsRef = (0, _react.useRef)(Array(_react.default.Children.count(children)).fill((0, _react.useRef)(null)));
68
+ var leftFadedEdgeColor = (fadedEdgeColor === null || fadedEdgeColor === void 0 ? void 0 : fadedEdgeColor.left) || fadedEdgeColor;
69
+ var rightFadedEdgeColor = (fadedEdgeColor === null || fadedEdgeColor === void 0 ? void 0 : fadedEdgeColor.right) || fadedEdgeColor;
70
+
71
+ // Trigger callbacks to report state of the carousel
72
+ var handleOnScroll = (0, _react.useCallback)(function () {
73
+ // viewport's width
74
+ var clientWidth = scrollRef.current.clientWidth;
75
+ // scroll position
76
+ var scrollLeft = parseInt(scrollRef.current.scrollLeft, 10);
77
+ // scrollable width
78
+ var scrollWidth = scrollRef.current.scrollWidth;
79
+
80
+ // The maximum scrollLeft achievable is the scrollable width - the viewport width.
81
+ var scrollLeftMax = scrollWidth - clientWidth;
82
+ // if isNaN(scrollLeft / scrollLeftMax), then set to zero
83
+ var scrollPercent = parseFloat((scrollLeft / scrollLeftMax).toFixed(2)) || 0;
84
+ if (!scrollRef.current) {
85
+ return;
86
+ }
87
+
88
+ // Callback 1: Does the carousel have enough content to enable scrolling?
89
+ onChangeIsScrollable(scrollWidth > clientWidth);
90
+
91
+ // Callback 2: Return the percentage of current scroll, between 0 and 1.
92
+ onScroll(scrollPercent);
93
+ }, [onChangeIsScrollable, onScroll]);
94
+
95
+ // Check if an individual child element is visible in the container
96
+ var getElementInView = (0, _react.useCallback)(function (containerRect, elementRect) {
97
+ // Is the element's left greater than or equal to the containers left
98
+ var elementLeftIsRightOfContainerLeft = elementRect.left >= containerRect.left;
99
+ // Is the element's right less than or equal to the containers right
100
+ var elementRightIsLeftOfContainerRight = elementRect.right <= containerRect.right;
101
+ return elementLeftIsRightOfContainerLeft && elementRightIsLeftOfContainerRight;
102
+ }, []);
103
+
104
+ // Get all elements that are visible in the container.
105
+ var getElementsInView = (0, _react.useCallback)(function () {
106
+ var containerRect = scrollRef.current.getBoundingClientRect();
107
+ var inViewElements = childElementsRef.current.filter(function (el) {
108
+ return getElementInView(containerRect, el.getBoundingClientRect());
109
+ });
110
+ return inViewElements;
111
+ }, [getElementInView]);
112
+
113
+ // Return container's and children's rect data
114
+ var getContainerAndChildRectData = (0, _react.useCallback)(function () {
115
+ // Get the rect of the container
116
+ var containerRect = scrollRef.current.getBoundingClientRect();
117
+ // Get all child elements that are in view of the container, and return their bounding rects.
118
+ var elementRectsInView = getElementsInView().map(function (el) {
119
+ return el.getBoundingClientRect();
120
+ });
121
+
122
+ // What is the overall width of the visible elements in the container
123
+ // Note: may end up being 0 if the container's width is less than the child's width
124
+ var visibleWidth = elementRectsInView.reduce(function (accumulator, currentValue) {
125
+ return accumulator + currentValue.width;
126
+ }, 0);
127
+ return {
128
+ containerRect: containerRect,
129
+ elementRectsInView: elementRectsInView,
130
+ visibleWidth: visibleWidth
131
+ };
132
+ }, [getElementsInView]);
133
+ var handleScrollNext = (0, _react.useCallback)(function () {
134
+ var _getContainerAndChild = getContainerAndChildRectData(),
135
+ containerRect = _getContainerAndChild.containerRect,
136
+ visibleWidth = _getContainerAndChild.visibleWidth;
137
+ // Set the scrollValue to the visibleWidth, but if the visibleWidth value is 0, set it to the container's width
138
+ var scrollValue = visibleWidth > 0 ? visibleWidth : containerRect.width;
139
+ // Increment the scrollLeft of the container
140
+ scrollRef.current.scrollLeft += scrollValue;
141
+ }, [getContainerAndChildRectData]);
142
+ var handleScrollPrev = (0, _react.useCallback)(function () {
143
+ var _getContainerAndChild2 = getContainerAndChildRectData(),
144
+ containerRect = _getContainerAndChild2.containerRect,
145
+ elementRectsInView = _getContainerAndChild2.elementRectsInView,
146
+ visibleWidth = _getContainerAndChild2.visibleWidth;
147
+ // Set the scrollValue to the visibleWidth minus the first child's left value,
148
+ // but if the visibleWidth value is 0, set it to the container's width plus the container's left value
149
+ var scrollValue = visibleWidth > 0 ? visibleWidth - elementRectsInView[0].left : containerRect.width + containerRect.left;
150
+
151
+ // Decrement the scrollLeft of the container
152
+ scrollRef.current.scrollLeft -= scrollValue;
153
+ }, [getContainerAndChildRectData]);
154
+ var handleScrollReset = (0, _react.useCallback)(function () {
155
+ // This doesn't trigger "scrollend"...
156
+ scrollRef.current.scrollLeft = 0;
157
+ // ...so trigger a callback manually.
158
+ handleOnScroll();
159
+ }, [handleOnScroll]);
160
+ var handleScrollToView = (0, _react.useCallback)(function (itemNumber) {
161
+ childElementsRef.current[itemNumber].scrollIntoView();
162
+ }, []);
163
+
164
+ // Trigger a callback after first render (and applied CSS).
165
+ (0, _react.useEffect)(function () {
166
+ // Normally, we can trigger a callback "immediately after first
167
+ // render", because we will be doing more "logical" work (update
168
+ // a state, show / hide a feature, etc.), and the final, applied
169
+ // CSS can "catch up" asynchronously without breaking anything.
170
+ setTimeout(function () {
171
+ // But, because we are making calculations based on the final,
172
+ // applied CSS, we must wait for one more "tick".
173
+ handleOnScroll();
174
+ }, 0);
175
+ // eslint-disable-next-line react-hooks/exhaustive-deps
176
+ }, []);
177
+
178
+ // On window.resize, reset carousel to zero.
179
+ (0, _react.useEffect)(function () {
180
+ var handleWindowResize = function handleWindowResize() {
181
+ scrollRef.current.scrollLeft = 0;
182
+ handleOnScroll();
183
+ };
184
+ window.addEventListener('resize', handleWindowResize);
185
+ return function () {
186
+ return window.removeEventListener('resize', handleWindowResize);
187
+ };
188
+ }, [handleOnScroll]);
189
+
190
+ // On scrollRef.scrollend, trigger a callback.
191
+ (0, _react.useEffect)(function () {
192
+ var handleScrollend = function handleScrollend() {
193
+ handleOnScroll();
194
+ };
195
+ var scrollDiv = scrollRef.current;
196
+ scrollDiv.addEventListener('scrollend', handleScrollend);
197
+ return function () {
198
+ return scrollDiv.removeEventListener('scrollend', handleScrollend);
199
+ };
200
+ }, [handleOnScroll]);
201
+
202
+ // Disable wheel scrolling
203
+ (0, _react.useEffect)(function () {
204
+ function handleWheel(event) {
205
+ // update the scroll position
206
+ event.stopPropagation();
207
+ event.preventDefault();
208
+ event.cancelBubble = false;
209
+ }
210
+ var scrollDiv = scrollRef.current;
211
+ if (scrollDiv) {
212
+ scrollDiv.addEventListener('wheel', handleWheel, {
213
+ passive: false
214
+ });
215
+ return function () {
216
+ scrollDiv.removeEventListener('wheel', handleWheel, {
217
+ passive: false
218
+ });
219
+ };
220
+ }
221
+ }, []);
222
+
223
+ // Enable arrow scrolling from within the carousel
224
+ (0, _react.useEffect)(function () {
225
+ function handleKeydown(event) {
226
+ var key = event.key;
227
+ if ((key === 'ArrowLeft' || key === 'ArrowRight') && disableArrowScroll) {
228
+ event.stopPropagation();
229
+ event.preventDefault();
230
+ event.cancelBubble = false;
231
+ }
232
+ }
233
+ var carouselDiv = carouselRef.current;
234
+ if (carouselDiv) {
235
+ carouselDiv.addEventListener('keydown', handleKeydown);
236
+ return function () {
237
+ return carouselDiv.removeEventListener('keydown', handleKeydown);
238
+ };
239
+ }
240
+ }, [disableArrowScroll]);
241
+
242
+ // Enable external function calls
243
+ (0, _react.useImperativeHandle)(ref, function () {
244
+ return {
245
+ scrollNext: function scrollNext() {
246
+ handleScrollNext();
247
+ },
248
+ scrollPrev: function scrollPrev() {
249
+ handleScrollPrev();
250
+ },
251
+ scrollReset: function scrollReset() {
252
+ handleScrollReset();
253
+ },
254
+ scrollToView: function scrollToView(itemNumber) {
255
+ handleScrollToView(itemNumber);
256
+ }
257
+ };
258
+ }, [handleScrollNext, handleScrollPrev, handleScrollReset, handleScrollToView]);
259
+ return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, rest, {
260
+ tabIndex: -1,
261
+ className: (0, _classnames.default)(blockClass, className),
262
+ ref: carouselRef,
263
+ role: "main"
264
+ }, (0, _devtools.getDevtoolsProps)(componentName)), /*#__PURE__*/_react.default.createElement("div", {
265
+ className: (0, _classnames.default)("".concat(blockClass, "__elements-container"))
266
+ }, /*#__PURE__*/_react.default.createElement("div", {
267
+ className: "".concat(blockClass, "__elements"),
268
+ ref: scrollRef
269
+ }, _react.default.Children.map(children, function (child, index) {
270
+ return /*#__PURE__*/_react.default.createElement(_CarouselItem.CarouselItem, {
271
+ key: index,
272
+ ref: function ref(element) {
273
+ return childElementsRef.current[index] = element;
274
+ }
275
+ }, child);
276
+ })), leftFadedEdgeColor && /*#__PURE__*/_react.default.createElement("div", {
277
+ className: "".concat(blockClass, "__elements-container--scrolled"),
278
+ style: {
279
+ background: "linear-gradient(90deg, ".concat(leftFadedEdgeColor, ", transparent)")
280
+ }
281
+ }), rightFadedEdgeColor && /*#__PURE__*/_react.default.createElement("div", {
282
+ className: "".concat(blockClass, "__elements-container--scroll-max"),
283
+ style: {
284
+ background: "linear-gradient(270deg, ".concat(rightFadedEdgeColor, ", transparent)")
285
+ }
286
+ })));
287
+ });
288
+ Carousel.displayName = componentName;
289
+
290
+ // The types and DocGen commentary for the component props,
291
+ // in alphabetical order (for consistency).
292
+ // See https://www.npmjs.com/package/prop-types#usage.
293
+ Carousel.propTypes = {
294
+ /**
295
+ * Provide the contents of the Carousel.
296
+ */
297
+ children: _propTypes.default.node.isRequired,
298
+ /**
299
+ * Provide an optional class to be applied to the containing node.
300
+ */
301
+ className: _propTypes.default.string,
302
+ /**
303
+ * Disables the ability of the Carousel to scroll
304
+ * use a keyboard's left and right arrow keys.
305
+ */
306
+ disableArrowScroll: _propTypes.default.bool,
307
+ /**
308
+ * Enables the edges of the component to have faded styling.
309
+ *
310
+ * Pass a single string (`$color`) to specify the same color for left and right.
311
+ *
312
+ * Or pass an object (`{ left: $color1, right: $color2 }`) to specify different colors.
313
+ */
314
+ fadedEdgeColor: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.shape({
315
+ left: _propTypes.default.string,
316
+ right: _propTypes.default.string
317
+ })]),
318
+ /**
319
+ * An optional callback function that returns `true`
320
+ * when the carousel has enough content to be scrollable,
321
+ * and `false` when there is not enough content.
322
+ */
323
+ onChangeIsScrollable: _propTypes.default.func,
324
+ /**
325
+ * An optional callback function that returns the scroll position as
326
+ * a value between 0 and 1.
327
+ */
328
+ onScroll: _propTypes.default.func
329
+ };
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.CarouselItem = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
+ var _react = _interopRequireDefault(require("react"));
11
+ var _propTypes = _interopRequireDefault(require("prop-types"));
12
+ var _classnames = _interopRequireDefault(require("classnames"));
13
+ var _devtools = require("../../global/js/utils/devtools");
14
+ var _settings = require("../../settings");
15
+ var _excluded = ["children", "className"];
16
+ /**
17
+ * Copyright IBM Corp. 2023, 2023
18
+ *
19
+ * This source code is licensed under the Apache-2.0 license found in the
20
+ * LICENSE file in the root directory of this source tree.
21
+ */
22
+ // Other standard imports.
23
+ // Carbon and package components we use.
24
+ /* TODO: @import(s) of carbon components and other package components. */ // The block part of our conventional BEM class names (blockClass__E--M).
25
+ var blockClass = "".concat(_settings.pkg.prefix, "--carousel__item");
26
+ var componentName = 'CarouselItem';
27
+
28
+ /**
29
+ * TODO: A description of the component.
30
+ */
31
+ var CarouselItem = exports.CarouselItem = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
32
+ var children = _ref.children,
33
+ className = _ref.className,
34
+ rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
35
+ return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, rest, {
36
+ className: (0, _classnames.default)(blockClass, className)
37
+ }, (0, _devtools.getDevtoolsProps)(componentName), {
38
+ ref: ref
39
+ }), children);
40
+ });
41
+ CarouselItem.displayName = componentName;
42
+ // The types and DocGen commentary for the component props,
43
+ // in alphabetical order (for consistency).
44
+ // See https://www.npmjs.com/package/prop-types#usage.
45
+ CarouselItem.propTypes = {
46
+ /**
47
+ * Provide the contents of the CarouselItem.
48
+ */
49
+ children: _propTypes.default.node.isRequired,
50
+ /**
51
+ * Provide an optional class to be applied to the containing node.
52
+ */
53
+ className: _propTypes.default.string
54
+ };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Carousel", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _Carousel.Carousel;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "CarouselItem", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _CarouselItem.CarouselItem;
16
+ }
17
+ });
18
+ var _Carousel = require("./Carousel");
19
+ var _CarouselItem = require("./CarouselItem");
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useWindowEvent = exports.useIsOverflow = exports.useIntersection = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _react = require("react");
10
+ /**
11
+ * Copyright IBM Corp. 2023, 2023
12
+ *
13
+ * This source code is licensed under the Apache-2.0 license found in the
14
+ * LICENSE file in the root directory of this source tree.
15
+ */
16
+
17
+ var useIntersection = exports.useIntersection = function useIntersection(element, threshold) {
18
+ var _useState = (0, _react.useState)(false),
19
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
20
+ isVisible = _useState2[0],
21
+ setState = _useState2[1];
22
+ (0, _react.useEffect)(function () {
23
+ var el = element.current;
24
+ var observer = new IntersectionObserver(function (_ref) {
25
+ var _ref2 = (0, _slicedToArray2.default)(_ref, 1),
26
+ entry = _ref2[0];
27
+ setState(entry.isIntersecting);
28
+ }, {
29
+ threshold: threshold
30
+ });
31
+ el && observer.observe(el);
32
+ return function () {
33
+ return observer.unobserve(el);
34
+ };
35
+ }, [element, threshold]);
36
+ return isVisible;
37
+ };
38
+ var useIsOverflow = exports.useIsOverflow = function useIsOverflow(ref) {
39
+ var _useState3 = (0, _react.useState)(),
40
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
41
+ isScrollable = _useState4[0],
42
+ setIsScrollable = _useState4[1];
43
+ var _useState5 = (0, _react.useState)(),
44
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
45
+ mutationObserver = _useState6[0],
46
+ setMutationObserver = _useState6[1];
47
+ var _useState7 = (0, _react.useState)(),
48
+ _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
49
+ resizeObserver = _useState8[0],
50
+ setResizeObserver = _useState8[1];
51
+ var checkOverflow = (0, _react.useCallback)(function () {
52
+ if (!ref.current) {
53
+ return;
54
+ }
55
+ var hasOverflow = ref.current.scrollWidth > ref.current.clientWidth;
56
+ setIsScrollable(hasOverflow);
57
+ }, [ref]);
58
+ (0, _react.useEffect)(function () {
59
+ if (!mutationObserver) {
60
+ return;
61
+ }
62
+ return function () {
63
+ if (mutationObserver) {
64
+ mutationObserver.disconnect();
65
+ }
66
+ if (resizeObserver) {
67
+ resizeObserver.disconnect();
68
+ }
69
+ };
70
+ });
71
+ (0, _react.useLayoutEffect)(function () {
72
+ var current = ref.current;
73
+ if (current) {
74
+ if ('ResizeObserver' in window && !resizeObserver) {
75
+ setResizeObserver(new ResizeObserver(checkOverflow).observe(current));
76
+ }
77
+ if ('MutationObserver' in window && !mutationObserver) {
78
+ setMutationObserver(new MutationObserver(checkOverflow).observe(current, {
79
+ attributes: false,
80
+ childList: true,
81
+ subtree: false
82
+ }));
83
+ }
84
+ checkOverflow();
85
+ }
86
+ }, [ref, checkOverflow, mutationObserver, resizeObserver]);
87
+ return isScrollable;
88
+ };
89
+ var useWindowEvent = exports.useWindowEvent = function useWindowEvent(eventName, callback) {
90
+ var savedCallback = (0, _react.useRef)(null);
91
+ (0, _react.useEffect)(function () {
92
+ savedCallback.current = callback;
93
+ });
94
+ (0, _react.useEffect)(function () {
95
+ function handler(event) {
96
+ if (savedCallback.current) {
97
+ savedCallback.current(event);
98
+ }
99
+ }
100
+ window.addEventListener(eventName, handler);
101
+ return function () {
102
+ window.removeEventListener(eventName, handler);
103
+ };
104
+ }, [eventName]);
105
+ };
@@ -101,7 +101,8 @@ var DatagridBatchActionsToolbar = function DatagridBatchActionsToolbar(datagridS
101
101
  };
102
102
  return /*#__PURE__*/_react.default.createElement(_react2.MenuButton, {
103
103
  label: batchActionMenuButtonLabelText,
104
- className: (0, _classnames.default)([menuClass, (0, _defineProperty2.default)({}, "".concat(menuClass, "-icon-only"), width <= minWidthBeforeOverflowIcon)])
104
+ className: (0, _classnames.default)([menuClass, (0, _defineProperty2.default)({}, "".concat(menuClass, "-icon-only"), width <= minWidthBeforeOverflowIcon)]),
105
+ tabIndex: totalSelected > 0 ? 0 : -1
105
106
  }, toolbarBatchActions === null || toolbarBatchActions === void 0 ? void 0 : toolbarBatchActions.map(function (batchAction, index) {
106
107
  var hidden = index < 2 && !displayAllInMenu;
107
108
  if (!hidden) {
@@ -147,7 +148,8 @@ var DatagridBatchActionsToolbar = function DatagridBatchActionsToolbar(datagridS
147
148
  onClick: function onClick(event) {
148
149
  return onClickHandler(event, batchAction);
149
150
  },
150
- iconDescription: batchAction.label
151
+ iconDescription: batchAction.label,
152
+ tabIndex: totalSelected > 0 ? 0 : -1
151
153
  }, batchAction.label);
152
154
  }
153
155
  })), renderBatchActionOverflow());