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