@carbon/ibm-products 1.61.1 → 1.62.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. package/css/index-full-carbon.css +172 -70
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +3 -3
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon-released-only.css +1768 -0
  6. package/css/index-without-carbon-released-only.css.map +1 -1
  7. package/css/index-without-carbon-released-only.min.css +3 -1
  8. package/css/index-without-carbon-released-only.min.css.map +1 -1
  9. package/css/index-without-carbon.css +172 -70
  10. package/css/index-without-carbon.css.map +1 -1
  11. package/css/index-without-carbon.min.css +3 -3
  12. package/css/index-without-carbon.min.css.map +1 -1
  13. package/css/index.css +172 -70
  14. package/css/index.css.map +1 -1
  15. package/css/index.min.css +3 -3
  16. package/css/index.min.css.map +1 -1
  17. package/es/components/Carousel/Carousel.js +194 -119
  18. package/es/components/Carousel/CarouselItem.js +8 -21
  19. package/es/components/Coachmark/Coachmark.js +17 -5
  20. package/es/components/Coachmark/CoachmarkDragbar.js +12 -5
  21. package/es/components/Coachmark/CoachmarkHeader.js +2 -1
  22. package/es/components/Coachmark/CoachmarkOverlay.js +105 -9
  23. package/es/components/CoachmarkBeacon/CoachmarkBeacon.js +5 -2
  24. package/es/components/CoachmarkFixed/CoachmarkFixed.js +26 -6
  25. package/es/components/CoachmarkOverlayElements/CoachmarkOverlayElements.js +34 -10
  26. package/es/components/CoachmarkStack/CoachmarkStack.js +19 -4
  27. package/es/components/CoachmarkStack/CoachmarkStackHome.js +45 -11
  28. package/es/components/Datagrid/Datagrid/DatagridContent.js +12 -9
  29. package/es/components/Datagrid/Datagrid/DatagridExpandedRow.js +6 -4
  30. package/es/components/Datagrid/Datagrid/DatagridHeaderRow.js +42 -25
  31. package/es/components/Datagrid/Datagrid/DatagridRefBody.js +4 -1
  32. package/es/components/Datagrid/Datagrid/DatagridRow.js +23 -11
  33. package/es/components/Datagrid/Datagrid/DatagridSelectAll.js +31 -12
  34. package/es/components/Datagrid/Datagrid/DatagridSimpleBody.js +4 -1
  35. package/es/components/Datagrid/Datagrid/DatagridToolbar.js +43 -23
  36. package/es/components/Datagrid/Datagrid/DatagridVirtualBody.js +18 -18
  37. package/es/components/Datagrid/Datagrid/addons/stateReducer.js +93 -14
  38. package/es/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +1 -1
  39. package/es/components/Datagrid/useActionsColumn.js +9 -9
  40. package/es/components/Datagrid/useDatagrid.js +13 -1
  41. package/es/components/Datagrid/useExpandedRow.js +3 -6
  42. package/es/components/Datagrid/useFlexResize.js +19 -9
  43. package/es/components/Datagrid/useFocusRowExpander.js +40 -0
  44. package/es/components/Datagrid/useInfiniteScroll.js +10 -9
  45. package/es/components/Datagrid/useNestedRowExpander.js +9 -0
  46. package/es/components/Datagrid/useNestedRows.js +0 -4
  47. package/es/components/Datagrid/useOnRowClick.js +6 -7
  48. package/es/components/Datagrid/useParentDimensions.js +6 -6
  49. package/es/components/Datagrid/useResizeTable.js +7 -7
  50. package/es/components/Datagrid/useRowExpander.js +9 -0
  51. package/es/components/Datagrid/useSelectAllToggle.js +2 -2
  52. package/es/components/Datagrid/useSelectRows.js +52 -30
  53. package/es/components/Datagrid/useSkeletonRows.js +6 -6
  54. package/es/components/Datagrid/useSortableColumns.js +4 -5
  55. package/es/components/Datagrid/useStickyColumn.js +13 -6
  56. package/es/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +1 -0
  57. package/es/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +1 -0
  58. package/es/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +1 -0
  59. package/es/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +1 -0
  60. package/es/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +1 -0
  61. package/es/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +1 -0
  62. package/es/components/EmptyStates/assets/ErrorIllustration.js +6 -4
  63. package/es/components/EmptyStates/assets/NoDataIllustration.js +6 -4
  64. package/es/components/EmptyStates/assets/NoTagsIllustration.js +6 -4
  65. package/es/components/EmptyStates/assets/NotFoundIllustration.js +6 -4
  66. package/es/components/EmptyStates/assets/NotificationsIllustration.js +6 -4
  67. package/es/components/EmptyStates/assets/UnauthorizedIllustration.js +6 -4
  68. package/es/components/Guidebanner/Guidebanner.js +9 -12
  69. package/es/global/js/hooks/index.js +3 -2
  70. package/es/global/js/hooks/usePrefix.js +11 -0
  71. package/es/global/js/package-settings.js +1 -4
  72. package/lib/components/Carousel/Carousel.js +190 -114
  73. package/lib/components/Carousel/CarouselItem.js +9 -25
  74. package/lib/components/Coachmark/Coachmark.js +16 -4
  75. package/lib/components/Coachmark/CoachmarkDragbar.js +12 -5
  76. package/lib/components/Coachmark/CoachmarkHeader.js +2 -1
  77. package/lib/components/Coachmark/CoachmarkOverlay.js +105 -8
  78. package/lib/components/CoachmarkBeacon/CoachmarkBeacon.js +5 -2
  79. package/lib/components/CoachmarkFixed/CoachmarkFixed.js +25 -5
  80. package/lib/components/CoachmarkOverlayElements/CoachmarkOverlayElements.js +34 -10
  81. package/lib/components/CoachmarkStack/CoachmarkStack.js +18 -3
  82. package/lib/components/CoachmarkStack/CoachmarkStackHome.js +44 -10
  83. package/lib/components/Datagrid/Datagrid/DatagridContent.js +12 -9
  84. package/lib/components/Datagrid/Datagrid/DatagridExpandedRow.js +6 -4
  85. package/lib/components/Datagrid/Datagrid/DatagridHeaderRow.js +42 -32
  86. package/lib/components/Datagrid/Datagrid/DatagridRefBody.js +4 -1
  87. package/lib/components/Datagrid/Datagrid/DatagridRow.js +17 -4
  88. package/lib/components/Datagrid/Datagrid/DatagridSelectAll.js +25 -5
  89. package/lib/components/Datagrid/Datagrid/DatagridSimpleBody.js +4 -1
  90. package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +43 -23
  91. package/lib/components/Datagrid/Datagrid/DatagridVirtualBody.js +12 -12
  92. package/lib/components/Datagrid/Datagrid/addons/stateReducer.js +96 -15
  93. package/lib/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +1 -1
  94. package/lib/components/Datagrid/useActionsColumn.js +9 -12
  95. package/lib/components/Datagrid/useDatagrid.js +13 -1
  96. package/lib/components/Datagrid/useExpandedRow.js +2 -5
  97. package/lib/components/Datagrid/useFlexResize.js +19 -9
  98. package/lib/components/Datagrid/useFocusRowExpander.js +46 -0
  99. package/lib/components/Datagrid/useInfiniteScroll.js +9 -9
  100. package/lib/components/Datagrid/useNestedRowExpander.js +9 -0
  101. package/lib/components/Datagrid/useNestedRows.js +0 -4
  102. package/lib/components/Datagrid/useOnRowClick.js +6 -7
  103. package/lib/components/Datagrid/useParentDimensions.js +5 -6
  104. package/lib/components/Datagrid/useResizeTable.js +6 -7
  105. package/lib/components/Datagrid/useRowExpander.js +9 -0
  106. package/lib/components/Datagrid/useSelectAllToggle.js +2 -2
  107. package/lib/components/Datagrid/useSelectRows.js +46 -23
  108. package/lib/components/Datagrid/useSkeletonRows.js +6 -6
  109. package/lib/components/Datagrid/useSortableColumns.js +4 -5
  110. package/lib/components/Datagrid/useStickyColumn.js +8 -0
  111. package/lib/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +1 -0
  112. package/lib/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +1 -0
  113. package/lib/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +1 -0
  114. package/lib/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +1 -0
  115. package/lib/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +1 -0
  116. package/lib/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +1 -0
  117. package/lib/components/EmptyStates/assets/ErrorIllustration.js +6 -4
  118. package/lib/components/EmptyStates/assets/NoDataIllustration.js +6 -4
  119. package/lib/components/EmptyStates/assets/NoTagsIllustration.js +6 -4
  120. package/lib/components/EmptyStates/assets/NotFoundIllustration.js +6 -4
  121. package/lib/components/EmptyStates/assets/NotificationsIllustration.js +6 -4
  122. package/lib/components/EmptyStates/assets/UnauthorizedIllustration.js +6 -4
  123. package/lib/components/Guidebanner/Guidebanner.js +9 -12
  124. package/lib/global/js/hooks/index.js +8 -1
  125. package/lib/global/js/hooks/usePrefix.js +19 -0
  126. package/lib/global/js/package-settings.js +1 -4
  127. package/package.json +2 -2
  128. package/scss/components/Carousel/_carousel.scss +1 -2
  129. package/scss/components/Checklist/_checklist.scss +13 -25
  130. package/scss/components/Coachmark/styles/_coachmark-dragbar.scss +1 -45
  131. package/scss/components/Coachmark/styles/_coachmark-header.scss +0 -33
  132. package/scss/components/Coachmark/styles/_coachmark-overlay.scss +113 -5
  133. package/scss/components/Coachmark/styles/_coachmark-tagline.scss +18 -0
  134. package/scss/components/CoachmarkBeacon/_coachmark-beacon.scss +19 -1
  135. package/scss/components/CoachmarkOverlayElement/_coachmark-overlay-element.scss +2 -0
  136. package/scss/components/CoachmarkOverlayElements/_coachmark-overlay-elements.scss +1 -0
  137. package/scss/components/CoachmarkStack/_coachmark-stack.scss +3 -0
  138. package/scss/components/Datagrid/styles/_datagrid.scss +31 -5
  139. package/scss/components/Datagrid/styles/_useExpandedRow.scss +21 -0
  140. package/scss/components/Datagrid/styles/_useNestedRows.scss +1 -1
  141. package/scss/components/Datagrid/styles/addons/_RowSizeDropdown.scss +9 -0
  142. package/scss/components/_index-released-only.scss +1 -0
  143. package/es/components/Carousel/utils.js +0 -98
  144. package/lib/components/Carousel/utils.js +0 -108
@@ -7,22 +7,16 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.Carousel = void 0;
9
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
10
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
12
11
  var _react = _interopRequireWildcard(require("react"));
13
- var _lodash = require("lodash");
14
12
  var _propTypes = _interopRequireDefault(require("prop-types"));
15
13
  var _CarouselItem = require("./CarouselItem");
16
- var _utils = require("./utils");
17
14
  var _classnames = _interopRequireDefault(require("classnames"));
18
15
  var _devtools = require("../../global/js/utils/devtools");
19
16
  var _settings = require("../../settings");
20
- var _excluded = ["children", "className", "disableArrowScroll", "fadedEdgeColor", "scrollableChange", "scrollTune"];
17
+ var _excluded = ["children", "className", "disableArrowScroll", "fadedEdgeColor", "onChangeIsScrollable", "onScroll"];
21
18
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
22
19
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
- // Carbon and package components we use.
24
- /* TODO: @import(s) of carbon components and other package components. */
25
-
26
20
  // The block part of our conventional BEM class names (blockClass__E--M).
27
21
  var blockClass = "".concat(_settings.pkg.prefix, "--carousel");
28
22
  var componentName = 'Carousel';
@@ -30,13 +24,25 @@ var componentName = 'Carousel';
30
24
  // Default values for props
31
25
  var defaults = {
32
26
  disableArrowScroll: false,
33
- scrollTune: 0
27
+ onScroll: function onScroll() {},
28
+ onChangeIsScrollable: function onChangeIsScrollable() {}
34
29
  };
35
30
 
36
31
  /**
37
32
  * The Carousel acts as a scaffold for other Novice to Pro content.
38
33
  *
39
34
  * This component is not intended for general use.
35
+ *
36
+ * Expected scrolling behavior.
37
+ * 1. Scroll the maximum number of visible items at a time.
38
+ * 2. The left-most item should always be left-aligned in the viewport.
39
+ *
40
+ * Exception.
41
+ * 1. After scrolling to the last (right-most) item,
42
+ * if some of its content remains hidden,
43
+ * then nudge it to the right until it is right-aligned.
44
+ * 2. From the right-aligned position, when scrolling left,
45
+ * the left-most item should again be left-aligned.
40
46
  */
41
47
  var Carousel = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
42
48
  var children = _ref.children,
@@ -44,93 +50,152 @@ var Carousel = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
44
50
  _ref$disableArrowScro = _ref.disableArrowScroll,
45
51
  disableArrowScroll = _ref$disableArrowScro === void 0 ? defaults.disableArrowScroll : _ref$disableArrowScro,
46
52
  fadedEdgeColor = _ref.fadedEdgeColor,
47
- scrollableChange = _ref.scrollableChange,
48
- _ref$scrollTune = _ref.scrollTune,
49
- scrollTune = _ref$scrollTune === void 0 ? defaults.scrollTune : _ref$scrollTune,
53
+ _ref$onChangeIsScroll = _ref.onChangeIsScrollable,
54
+ onChangeIsScrollable = _ref$onChangeIsScroll === void 0 ? defaults.onChangeIsScrollable : _ref$onChangeIsScroll,
55
+ _ref$onScroll = _ref.onScroll,
56
+ onScroll = _ref$onScroll === void 0 ? defaults.onScroll : _ref$onScroll,
50
57
  rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
51
- var carouselScrollPromiseDelay = 700;
52
- var totalViews = _react.default.Children.count(children) || 1;
58
+ var carouselRef = (0, _react.useRef)();
59
+ var scrollRef = (0, _react.useRef)();
60
+ // Array of refs used to reference this component's children DOM elements
61
+ var childElementsRef = (0, _react.useRef)(Array(_react.default.Children.count(children)).fill((0, _react.useRef)(null)));
53
62
  var leftFadedEdgeColor = (fadedEdgeColor === null || fadedEdgeColor === void 0 ? void 0 : fadedEdgeColor.left) || fadedEdgeColor;
54
63
  var rightFadedEdgeColor = (fadedEdgeColor === null || fadedEdgeColor === void 0 ? void 0 : fadedEdgeColor.right) || fadedEdgeColor;
55
- var _useState = (0, _react.useState)(0),
56
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
57
- currentViewID = _useState2[0],
58
- _setCurrentViewID = _useState2[1];
59
- var currentViewIDRef = (0, _react.useRef)(currentViewID);
60
- var scrollRef = (0, _react.useRef)();
61
- var carouselRef = (0, _react.useRef)();
62
- var mountedRef = (0, _react.useRef)(true);
63
- var isScrollable = (0, _utils.useIsOverflow)(scrollRef);
64
- // Scrolling has no complete callback, nor does it return a promise.
65
- // Since there is no way to tell when a scroll is finished we can set a timeout.
66
- // Chrome appears to be the slowest implementation.
67
- // Here is the spec: https://drafts.csswg.org/cssom-view/#concept-smooth-scroll
68
- // found issue: https://github.com/w3c/csswg-drafts/issues/3744
69
-
70
- var scrollNext = (0, _react.useCallback)(function () {
71
- return scrollToView(currentViewID + 1);
72
- }, [currentViewID, scrollToView]);
73
- var scrollPrev = (0, _react.useCallback)(function () {
74
- return scrollToView(currentViewID - 1);
75
- }, [currentViewID, scrollToView]);
76
- var scrollToView = (0, _react.useCallback)(function (viewID) {
77
- if (!isScrolling && scrollRef.current && mountedRef.current) {
78
- var _scrollRef$current;
79
- var targetViewID = (0, _lodash.clamp)(viewID, 0, totalViews - 1);
80
- setCurrentViewID(targetViewID);
81
- setIsScrolling(true);
82
- scrollRef.current.scrollLeft = ((_scrollRef$current = scrollRef.current) === null || _scrollRef$current === void 0 ? void 0 : _scrollRef$current.offsetWidth) * targetViewID + scrollTune;
83
- return scrollPromise();
64
+
65
+ // Trigger callbacks to report state of the carousel
66
+ var handleOnScroll = (0, _react.useCallback)(function () {
67
+ // viewport's width
68
+ var clientWidth = scrollRef.current.clientWidth;
69
+ // scroll position
70
+ var scrollLeft = parseInt(scrollRef.current.scrollLeft, 10);
71
+ // scrollable width
72
+ var scrollWidth = scrollRef.current.scrollWidth;
73
+
74
+ // The maximum scrollLeft achievable is the scrollable width - the viewport width.
75
+ var scrollLeftMax = scrollWidth - clientWidth;
76
+ // if isNaN(scrollLeft / scrollLeftMax), then set to zero
77
+ var scrollPercent = parseFloat((scrollLeft / scrollLeftMax).toFixed(2)) || 0;
78
+ if (!scrollRef.current) {
79
+ return;
84
80
  }
85
- return new Promise(function (resolve) {
86
- return resolveScroll(resolve);
81
+
82
+ // Callback 1: Does the carousel have enough content to enable scrolling?
83
+ onChangeIsScrollable(scrollWidth > clientWidth);
84
+
85
+ // Callback 2: Return the percentage of current scroll, between 0 and 1.
86
+ onScroll(scrollPercent);
87
+ }, [onChangeIsScrollable, onScroll]);
88
+
89
+ // Check if an individual child element is visible in the container
90
+ var getElementInView = (0, _react.useCallback)(function (containerRect, elementRect) {
91
+ // Is the element's left greater than or equal to the containers left
92
+ var elementLeftIsRightOfContainerLeft = elementRect.left >= containerRect.left;
93
+ // Is the element's right less than or equal to the containers right
94
+ var elementRightIsLeftOfContainerRight = elementRect.right <= containerRect.right;
95
+ return elementLeftIsRightOfContainerLeft && elementRightIsLeftOfContainerRight;
96
+ }, []);
97
+
98
+ // Get all elements that are visible in the container.
99
+ var getElementsInView = (0, _react.useCallback)(function () {
100
+ var containerRect = scrollRef.current.getBoundingClientRect();
101
+ var inViewElements = childElementsRef.current.filter(function (el) {
102
+ return getElementInView(containerRect, el.getBoundingClientRect());
87
103
  });
88
- }, [isScrolling, resolveScroll, scrollPromise, scrollTune, totalViews]);
89
- var scrollPromise = (0, _react.useCallback)(function () {
90
- return new Promise(function (resolve) {
91
- setTimeout(function () {
92
- return resolveScroll(resolve);
93
- }, carouselScrollPromiseDelay);
104
+ return inViewElements;
105
+ }, [getElementInView]);
106
+
107
+ // Return container's and children's rect data
108
+ var getContainerAndChildRectData = (0, _react.useCallback)(function () {
109
+ // Get the rect of the container
110
+ var containerRect = scrollRef.current.getBoundingClientRect();
111
+ // Get all child elements that are in view of the container, and return their bounding rects.
112
+ var elementRectsInView = getElementsInView().map(function (el) {
113
+ return el.getBoundingClientRect();
94
114
  });
95
- }, [resolveScroll]);
96
- var resolveScroll = (0, _react.useCallback)(function (resolve) {
97
- if (mountedRef.current) {
98
- setIsScrolling(false);
99
- var percentage = scrollPosition() / maxScroll();
100
- return resolve(parseFloat(percentage.toFixed(2)));
101
- }
115
+
116
+ // What is the overall width of the visible elements in the container
117
+ // Note: may end up being 0 if the container's width is less than the child's width
118
+ var visibleWidth = elementRectsInView.reduce(function (accumulator, currentValue) {
119
+ return accumulator + currentValue.width;
120
+ }, 0);
121
+ return {
122
+ containerRect: containerRect,
123
+ elementRectsInView: elementRectsInView,
124
+ visibleWidth: visibleWidth
125
+ };
126
+ }, [getElementsInView]);
127
+ var handleScrollNext = (0, _react.useCallback)(function () {
128
+ var _getContainerAndChild = getContainerAndChildRectData(),
129
+ containerRect = _getContainerAndChild.containerRect,
130
+ visibleWidth = _getContainerAndChild.visibleWidth;
131
+ // Set the scrollValue to the visibleWidth, but if the visibleWidth value is 0, set it to the container's width
132
+ var scrollValue = visibleWidth > 0 ? visibleWidth : containerRect.width;
133
+ // Increment the scrollLeft of the container
134
+ scrollRef.current.scrollLeft += scrollValue;
135
+ }, [getContainerAndChildRectData]);
136
+ var handleScrollPrev = (0, _react.useCallback)(function () {
137
+ var _getContainerAndChild2 = getContainerAndChildRectData(),
138
+ containerRect = _getContainerAndChild2.containerRect,
139
+ elementRectsInView = _getContainerAndChild2.elementRectsInView,
140
+ visibleWidth = _getContainerAndChild2.visibleWidth;
141
+ // Set the scrollValue to the visibleWidth minus the first child's left value,
142
+ // but if the visibleWidth value is 0, set it to the container's width plus the container's left value
143
+ var scrollValue = visibleWidth > 0 ? visibleWidth - elementRectsInView[0].left : containerRect.width + containerRect.left;
144
+
145
+ // Decrement the scrollLeft of the container
146
+ scrollRef.current.scrollLeft -= scrollValue;
147
+ }, [getContainerAndChildRectData]);
148
+ var handleScrollReset = (0, _react.useCallback)(function () {
149
+ // This doesn't trigger "scrollend"...
150
+ scrollRef.current.scrollLeft = 0;
151
+ // ...so trigger a callback manually.
152
+ handleOnScroll();
153
+ }, [handleOnScroll]);
154
+ var handleScrollToView = (0, _react.useCallback)(function (itemNumber) {
155
+ childElementsRef.current[itemNumber].scrollIntoView();
102
156
  }, []);
103
- var scrollPosition = function scrollPosition() {
104
- var _scrollRef$current2;
105
- return (_scrollRef$current2 = scrollRef.current) === null || _scrollRef$current2 === void 0 ? void 0 : _scrollRef$current2.scrollLeft;
106
- };
107
- var maxScroll = function maxScroll() {
108
- var _scrollRef$current3, _scrollRef$current4;
109
- return ((_scrollRef$current3 = scrollRef.current) === null || _scrollRef$current3 === void 0 ? void 0 : _scrollRef$current3.scrollWidth) - ((_scrollRef$current4 = scrollRef.current) === null || _scrollRef$current4 === void 0 ? void 0 : _scrollRef$current4.clientWidth);
110
- };
111
- var handleResize = (0, _lodash.debounce)(function () {
112
- scrollToView(currentViewIDRef.current);
113
- }, 200);
114
- var setCurrentViewID = function setCurrentViewID(val) {
115
- currentViewIDRef.current = val;
116
- _setCurrentViewID(val);
117
- };
118
- var _useState3 = (0, _react.useState)(false),
119
- _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
120
- isScrolling = _useState4[0],
121
- setIsScrolling = _useState4[1];
122
-
123
- // EFFECTS
124
- (0, _utils.useWindowEvent)('resize', handleResize);
125
- // SAVE POINT
126
157
 
158
+ // Trigger a callback after first render (and applied CSS).
127
159
  (0, _react.useEffect)(function () {
128
- if (scrollableChange && mountedRef.current) {
129
- scrollableChange(isScrollable);
130
- }
131
- }, [isScrollable, scrollableChange]);
160
+ // Normally, we can trigger a callback "immediately after first
161
+ // render", because we will be doing more "logical" work (update
162
+ // a state, show / hide a feature, etc.), and the final, applied
163
+ // CSS can "catch up" asynchronously without breaking anything.
164
+ setTimeout(function () {
165
+ // But, because we are making calculations based on the final,
166
+ // applied CSS, we must wait for one more "tick".
167
+ handleOnScroll();
168
+ }, 0);
169
+ // eslint-disable-next-line react-hooks/exhaustive-deps
170
+ }, []);
171
+
172
+ // On window.resize, reset carousel to zero.
132
173
  (0, _react.useEffect)(function () {
133
- function updateScrollPosition(event) {
174
+ var handleWindowResize = function handleWindowResize() {
175
+ scrollRef.current.scrollLeft = 0;
176
+ handleOnScroll();
177
+ };
178
+ window.addEventListener('resize', handleWindowResize);
179
+ return function () {
180
+ return window.removeEventListener('resize', handleWindowResize);
181
+ };
182
+ }, [handleOnScroll]);
183
+
184
+ // On scrollRef.scrollend, trigger a callback.
185
+ (0, _react.useEffect)(function () {
186
+ var handleScrollend = function handleScrollend() {
187
+ handleOnScroll();
188
+ };
189
+ var scrollDiv = scrollRef.current;
190
+ scrollDiv.addEventListener('scrollend', handleScrollend);
191
+ return function () {
192
+ return scrollDiv.removeEventListener('scrollend', handleScrollend);
193
+ };
194
+ }, [handleOnScroll]);
195
+
196
+ // Disable wheel scrolling
197
+ (0, _react.useEffect)(function () {
198
+ function handleWheel(event) {
134
199
  // update the scroll position
135
200
  event.stopPropagation();
136
201
  event.preventDefault();
@@ -138,18 +203,20 @@ var Carousel = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
138
203
  }
139
204
  var scrollDiv = scrollRef.current;
140
205
  if (scrollDiv) {
141
- scrollDiv.addEventListener('wheel', updateScrollPosition, {
206
+ scrollDiv.addEventListener('wheel', handleWheel, {
142
207
  passive: false
143
208
  });
144
209
  return function () {
145
- scrollDiv.removeEventListener('wheel', updateScrollPosition, {
210
+ scrollDiv.removeEventListener('wheel', handleWheel, {
146
211
  passive: false
147
212
  });
148
213
  };
149
214
  }
150
215
  }, []);
216
+
217
+ // Enable arrow scrolling from within the carousel
151
218
  (0, _react.useEffect)(function () {
152
- function keypress(event) {
219
+ function handleKeydown(event) {
153
220
  var key = event.key;
154
221
  if ((key === 'ArrowLeft' || key === 'ArrowRight') && disableArrowScroll) {
155
222
  event.stopPropagation();
@@ -157,27 +224,32 @@ var Carousel = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
157
224
  event.cancelBubble = false;
158
225
  }
159
226
  }
160
- var outerDiv = carouselRef.current;
161
- if (outerDiv) {
162
- outerDiv.addEventListener('keydown', keypress);
227
+ var carouselDiv = carouselRef.current;
228
+ if (carouselDiv) {
229
+ carouselDiv.addEventListener('keydown', handleKeydown);
163
230
  return function () {
164
- return outerDiv.removeEventListener('keydown', keypress);
231
+ return carouselDiv.removeEventListener('keydown', handleKeydown);
165
232
  };
166
233
  }
167
234
  }, [disableArrowScroll]);
168
- (0, _react.useEffect)(function () {
169
- return function () {
170
- mountedRef.current = false;
171
- };
172
- }, []);
235
+
236
+ // Enable external function calls
173
237
  (0, _react.useImperativeHandle)(ref, function () {
174
238
  return {
175
- scrollNext: scrollNext,
176
- scrollPrev: scrollPrev,
177
- scrollToView: scrollToView,
178
- maxScroll: maxScroll
239
+ scrollNext: function scrollNext() {
240
+ handleScrollNext();
241
+ },
242
+ scrollPrev: function scrollPrev() {
243
+ handleScrollPrev();
244
+ },
245
+ scrollReset: function scrollReset() {
246
+ handleScrollReset();
247
+ },
248
+ scrollToView: function scrollToView(itemNumber) {
249
+ handleScrollToView(itemNumber);
250
+ }
179
251
  };
180
- }, [scrollNext, scrollPrev, scrollToView]);
252
+ }, [handleScrollNext, handleScrollPrev, handleScrollReset, handleScrollToView]);
181
253
  return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, rest, {
182
254
  tabIndex: -1,
183
255
  className: (0, _classnames.default)(blockClass, className),
@@ -188,8 +260,13 @@ var Carousel = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
188
260
  }, /*#__PURE__*/_react.default.createElement("div", {
189
261
  className: "".concat(blockClass, "__elements"),
190
262
  ref: scrollRef
191
- }, _react.default.Children.map(children, function (child) {
192
- return /*#__PURE__*/_react.default.createElement(_CarouselItem.CarouselItem, null, child);
263
+ }, _react.default.Children.map(children, function (child, index) {
264
+ return /*#__PURE__*/_react.default.createElement(_CarouselItem.CarouselItem, {
265
+ key: index,
266
+ ref: function ref(element) {
267
+ return childElementsRef.current[index] = element;
268
+ }
269
+ }, child);
193
270
  })), leftFadedEdgeColor && /*#__PURE__*/_react.default.createElement("div", {
194
271
  className: "".concat(blockClass, "__elements-container--scrolled"),
195
272
  style: {
@@ -202,9 +279,6 @@ var Carousel = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
202
279
  }
203
280
  })));
204
281
  });
205
-
206
- // The display name of the component, used by React. Note that displayName
207
- // is used in preference to relying on function.name.
208
282
  exports.Carousel = Carousel;
209
283
  Carousel.displayName = componentName;
210
284
 
@@ -228,21 +302,23 @@ Carousel.propTypes = {
228
302
  /**
229
303
  * Enables the edges of the component to have faded styling.
230
304
  *
231
- * Pass a single string to specify the same color for left and right.
305
+ * Pass a single string (`$color`) to specify the same color for left and right.
232
306
  *
233
- * Pass `{ left: $color1, right: $color2 }` to specify different colors.
307
+ * Or pass an object (`{ left: $color1, right: $color2 }`) to specify different colors.
234
308
  */
235
309
  fadedEdgeColor: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.shape({
236
310
  left: _propTypes.default.string,
237
311
  right: _propTypes.default.string
238
312
  })]),
239
313
  /**
240
- * Determines how much of the Carousel moves into view on rotation.
314
+ * An optional callback function that returns `true`
315
+ * when the carousel has enough content to be scrollable,
316
+ * and `false` when there is not enough content.
241
317
  */
242
- scrollTune: _propTypes.default.number,
318
+ onChangeIsScrollable: _propTypes.default.func,
243
319
  /**
244
- * An optional callback function that returns `true`
245
- * when the carousel has completed scrolling a single item.
320
+ * An optional callback function that returns the scroll position as
321
+ * a value between 0 and 1.
246
322
  */
247
- scrollableChange: _propTypes.default.func
323
+ onScroll: _propTypes.default.func
248
324
  };
@@ -1,23 +1,18 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.CarouselItem = void 0;
9
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
9
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
12
- var _react = _interopRequireWildcard(require("react"));
10
+ var _react = _interopRequireDefault(require("react"));
13
11
  var _propTypes = _interopRequireDefault(require("prop-types"));
14
12
  var _classnames = _interopRequireDefault(require("classnames"));
15
- var _utils = require("./utils");
16
13
  var _devtools = require("../../global/js/utils/devtools");
17
14
  var _settings = require("../../settings");
18
15
  var _excluded = ["children", "className"];
19
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
20
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
16
  // Carbon and package components we use.
22
17
  /* TODO: @import(s) of carbon components and other package components. */
23
18
 
@@ -28,32 +23,21 @@ var componentName = 'CarouselItem';
28
23
  /**
29
24
  * TODO: A description of the component.
30
25
  */
31
- var CarouselItem = function CarouselItem(_ref) {
26
+ var CarouselItem = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
32
27
  var children = _ref.children,
33
28
  className = _ref.className,
34
29
  rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
35
- var itemRef = (0, _react.useRef)();
36
- var isInView = (0, _utils.useIntersection)(itemRef, 0.85);
37
- (0, _react.useEffect)(function () {
38
- var _itemRef$current;
39
- var matches = (_itemRef$current = itemRef.current) === null || _itemRef$current === void 0 ? void 0 : _itemRef$current.querySelectorAll('a, button, [role="button"], [tabindex]');
40
- if (matches) {
41
- var ti = isInView ? 0 : -1;
42
- (0, _toConsumableArray2.default)(matches).forEach(function (match) {
43
- match.tabIndex = ti;
44
- });
45
- }
46
- }, [isInView]);
47
30
  return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, rest, {
48
- className: (0, _classnames.default)(blockClass, className),
49
- ref: itemRef
50
- }, (0, _devtools.getDevtoolsProps)(componentName)), children);
51
- };
52
-
31
+ className: (0, _classnames.default)(blockClass, className)
32
+ }, (0, _devtools.getDevtoolsProps)(componentName), {
33
+ ref: ref
34
+ }), children);
35
+ });
36
+ exports.CarouselItem = CarouselItem;
37
+ CarouselItem.displayName = componentName;
53
38
  // The types and DocGen commentary for the component props,
54
39
  // in alphabetical order (for consistency).
55
40
  // See https://www.npmjs.com/package/prop-types#usage.
56
- exports.CarouselItem = CarouselItem;
57
41
  CarouselItem.propTypes = {
58
42
  /**
59
43
  * Provide the contents of the CarouselItem.
@@ -25,6 +25,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
25
25
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
26
26
  // The block part of our conventional BEM class names (blockClass__E--M).
27
27
  var blockClass = "".concat(_settings.pkg.prefix, "--coachmark");
28
+ var overlayBlockClass = "".concat(blockClass, "-overlay");
28
29
  var componentName = 'Coachmark';
29
30
  var defaults = {
30
31
  align: 'bottom',
@@ -86,7 +87,18 @@ var Coachmark = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
86
87
  var closeOverlay = function closeOverlay() {
87
88
  setIsOpen(false);
88
89
  };
89
- var handleClose = function handleClose() {
90
+ var escFunction = (0, _react.useCallback)(function (event) {
91
+ if (event.key === 'Escape') {
92
+ handleClose();
93
+ }
94
+ }, [handleClose]);
95
+ (0, _react.useEffect)(function () {
96
+ document.addEventListener('keydown', escFunction, false);
97
+ return function () {
98
+ document.removeEventListener('keydown', escFunction, false);
99
+ };
100
+ }, [escFunction]);
101
+ var handleClose = (0, _react.useCallback)(function () {
90
102
  if (isStacked) {
91
103
  // If stacked, do not unmount,
92
104
  // only call its ("parent") onClose method.
@@ -95,7 +107,7 @@ var Coachmark = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
95
107
  setIsOpen(false);
96
108
  onClose();
97
109
  }
98
- };
110
+ }, [isStacked, onClose]);
99
111
  var handleTargetClick = function handleTargetClick(e) {
100
112
  setTargetRect(e.target.getBoundingClientRect());
101
113
  setTargetOffset({
@@ -116,6 +128,7 @@ var Coachmark = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
116
128
  var contextValue = {
117
129
  buttonProps: {
118
130
  'aria-expanded': isOpen,
131
+ tabIndex: 0,
119
132
  onClick: handleTargetClick,
120
133
  // Compensate for accidental open/close on double-click.
121
134
  // Only open on double-click.
@@ -167,7 +180,7 @@ var Coachmark = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
167
180
  kind: overlayKind,
168
181
  onClose: handleClose,
169
182
  theme: theme,
170
- className: overlayClassName
183
+ className: (0, _classnames.default)(overlayClassName, "".concat(overlayBlockClass, "--is-visible"))
171
184
  }, children), portalNode)));
172
185
  });
173
186
 
@@ -189,7 +202,6 @@ Coachmark.propTypes = {
189
202
  * @see COACHMARK_ALIGNMENT
190
203
  */
191
204
  align: _propTypes.default.oneOf(['bottom', 'bottom-left', 'bottom-right', 'left', 'left-top', 'left-bottom', 'right', 'right-top', 'right-bottom', 'top', 'top-left', 'top-right']),
192
- // TODO: UPDATE COMMENT HERE - UPDATE MDX TO HAVE DIRECTION TO USE ONLY OVERLAY ELEMENTS>...
193
205
  /**
194
206
  * Coachmark should use a single CoachmarkOverlayElements component as a child.
195
207
  * @see CoachmarkOverlayElements
@@ -16,7 +16,7 @@ var _iconsReact = require("@carbon/icons-react");
16
16
  var _carbonComponentsReact = require("carbon-components-react");
17
17
  var _devtools = require("../../global/js/utils/devtools");
18
18
  var _settings = require("../../settings");
19
- var _excluded = ["closeIconDescription", "onClose", "onDrag", "showCloseButton", "theme"];
19
+ var _excluded = ["a11yKeyboardHandler", "closeIconDescription", "onClose", "onDrag", "showCloseButton", "theme"];
20
20
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
21
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22
22
  // Carbon and package components we use.
@@ -24,6 +24,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
24
24
 
25
25
  // The block part of our conventional BEM class names (blockClass__E--M).
26
26
  var blockClass = "".concat(_settings.pkg.prefix, "--coachmark-dragbar");
27
+ var overlayBlockClass = "".concat(_settings.pkg.prefix, "--coachmark-overlay");
27
28
  var componentName = 'CoachmarkDragbar';
28
29
  var defaults = {
29
30
  closeIconDescription: 'Close',
@@ -38,7 +39,8 @@ var defaults = {
38
39
  * of other Novice to Pro components.
39
40
  */
40
41
  var CoachmarkDragbar = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
41
- var _ref$closeIconDescrip = _ref.closeIconDescription,
42
+ var a11yKeyboardHandler = _ref.a11yKeyboardHandler,
43
+ _ref$closeIconDescrip = _ref.closeIconDescription,
42
44
  closeIconDescription = _ref$closeIconDescrip === void 0 ? defaults.closeIconDescription : _ref$closeIconDescrip,
43
45
  _ref$onClose = _ref.onClose,
44
46
  onClose = _ref$onClose === void 0 ? defaults.onClose : _ref$onClose,
@@ -88,15 +90,16 @@ var CoachmarkDragbar = /*#__PURE__*/_react.default.forwardRef(function (_ref, re
88
90
  // role="main"
89
91
  }, (0, _devtools.getDevtoolsProps)(componentName)), /*#__PURE__*/_react.default.createElement("button", {
90
92
  type: "button",
91
- className: "".concat(blockClass, "__handle"),
92
- onMouseDown: handleDragStart
93
+ className: "".concat(overlayBlockClass, "__handle"),
94
+ onMouseDown: handleDragStart,
95
+ onKeyDown: a11yKeyboardHandler
93
96
  }, /*#__PURE__*/_react.default.createElement(_iconsReact.Draggable16, null)), showCloseButton && /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.Button, {
94
97
  kind: "ghost",
95
98
  size: "sm",
96
99
  renderIcon: _iconsReact.Close16,
97
100
  iconDescription: closeIconDescription,
98
101
  hasIconOnly: true,
99
- className: "".concat(blockClass, "--close-btn"),
102
+ className: "".concat(overlayBlockClass, "--close-btn"),
100
103
  onClick: onClose
101
104
  }));
102
105
  });
@@ -113,6 +116,10 @@ CoachmarkDragbar.displayName = componentName;
113
116
  // in alphabetical order (for consistency).
114
117
  // See https://www.npmjs.com/package/prop-types#usage.
115
118
  CoachmarkDragbar.propTypes = {
119
+ /**
120
+ * Handler to manage keyboard interactions with the dragbar.
121
+ */
122
+ a11yKeyboardHandler: _propTypes.default.func.isRequired,
116
123
  /**
117
124
  * Tooltip text and aria label for the Close button icon.
118
125
  */
@@ -17,6 +17,7 @@ var _settings = require("../../settings");
17
17
  var _excluded = ["closeIconDescription", "onClose", "showCloseButton", "theme"];
18
18
  // The block part of our conventional BEM class names (blockClass__E--M).
19
19
  var blockClass = "".concat(_settings.pkg.prefix, "--coachmark-header");
20
+ var overlayBlockClass = "".concat(_settings.pkg.prefix, "--coachmark-overlay");
20
21
  var componentName = 'CoachmarkHeader';
21
22
  var defaults = {
22
23
  closeIconDescription: 'Close',
@@ -49,7 +50,7 @@ var CoachmarkHeader = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
49
50
  renderIcon: _iconsReact.Close16,
50
51
  iconDescription: closeIconDescription,
51
52
  hasIconOnly: true,
52
- className: "".concat(blockClass, "--close-btn"),
53
+ className: "".concat(overlayBlockClass, "--close-btn"),
53
54
  onClick: onClose
54
55
  }));
55
56
  });