@carbon/ibm-products 2.17.2 → 2.18.0
Sign up to get free protection for your applications and to get access to all the features.
- package/css/index-full-carbon.css +13188 -12116
- package/css/index-full-carbon.css.map +1 -1
- package/css/index-full-carbon.min.css +1 -1
- package/css/index-full-carbon.min.css.map +1 -1
- package/css/index-without-carbon-released-only.css +5 -2
- package/css/index-without-carbon-released-only.css.map +1 -1
- package/css/index-without-carbon-released-only.min.css +1 -1
- package/css/index-without-carbon-released-only.min.css.map +1 -1
- package/css/index-without-carbon.css +5710 -6367
- package/css/index-without-carbon.css.map +1 -1
- package/css/index-without-carbon.min.css +1 -1
- package/css/index-without-carbon.min.css.map +1 -1
- package/css/index.css +5 -2
- package/css/index.css.map +1 -1
- package/css/index.min.css +1 -1
- package/css/index.min.css.map +1 -1
- package/es/components/Carousel/Carousel.docs-page.js +11 -0
- package/es/components/Carousel/Carousel.js +322 -0
- package/es/components/Carousel/CarouselItem.js +53 -0
- package/es/components/Carousel/index.js +9 -0
- package/es/components/Carousel/utils.js +98 -0
- package/es/components/Datagrid/Datagrid/addons/Filtering/hooks/useFilters.js +4 -3
- package/es/components/Datagrid/Extensions/Filtering/Filtering.docs-page.js +7 -1
- package/es/components/Datagrid/utils/handleFilterTagLabelText.js +26 -0
- package/es/components/FilterSummary/FilterSummary.js +21 -7
- package/es/components/Guidebanner/Guidebanner.docs-page.js +15 -0
- package/es/components/Guidebanner/Guidebanner.js +221 -0
- package/es/components/Guidebanner/GuidebannerElement.js +72 -0
- package/es/components/Guidebanner/GuidebannerElementButton.js +80 -0
- package/es/components/Guidebanner/GuidebannerElementLink.js +57 -0
- package/es/components/Guidebanner/index.js +11 -0
- package/es/components/NonLinearReading/NonLinearReading.docs-page.js +15 -0
- package/es/components/NonLinearReading/NonLinearReading.js +89 -0
- package/es/components/NonLinearReading/index.js +8 -0
- package/es/components/SidePanel/SidePanel.js +9 -8
- package/es/components/TagSet/TagSet.js +22 -5
- package/es/components/WebTerminal/WebTerminal.js +5 -3
- package/es/global/js/package-settings.js +6 -1
- package/lib/components/Carousel/Carousel.docs-page.js +21 -0
- package/lib/components/Carousel/Carousel.js +329 -0
- package/lib/components/Carousel/CarouselItem.js +54 -0
- package/lib/components/Carousel/index.js +19 -0
- package/lib/components/Carousel/utils.js +105 -0
- package/lib/components/Datagrid/Datagrid/addons/Filtering/hooks/useFilters.js +4 -3
- package/lib/components/Datagrid/Extensions/Filtering/Filtering.docs-page.js +7 -1
- package/lib/components/Datagrid/utils/handleFilterTagLabelText.js +32 -0
- package/lib/components/FilterSummary/FilterSummary.js +24 -7
- package/lib/components/Guidebanner/Guidebanner.docs-page.js +25 -0
- package/lib/components/Guidebanner/Guidebanner.js +229 -0
- package/lib/components/Guidebanner/GuidebannerElement.js +77 -0
- package/lib/components/Guidebanner/GuidebannerElementButton.js +85 -0
- package/lib/components/Guidebanner/GuidebannerElementLink.js +62 -0
- package/lib/components/Guidebanner/index.js +33 -0
- package/lib/components/NonLinearReading/NonLinearReading.docs-page.js +25 -0
- package/lib/components/NonLinearReading/NonLinearReading.js +97 -0
- package/lib/components/NonLinearReading/index.js +12 -0
- package/lib/components/SidePanel/SidePanel.js +9 -8
- package/lib/components/TagSet/TagSet.js +22 -5
- package/lib/components/WebTerminal/WebTerminal.js +4 -2
- package/lib/global/js/package-settings.js +6 -1
- package/package.json +3 -3
- package/scss/components/Carousel/_carbon-imports.scss +6 -0
- package/scss/components/Carousel/_carousel.scss +72 -0
- package/scss/components/Carousel/_index-with-carbon.scss +9 -0
- package/scss/components/Carousel/_index.scss +8 -0
- package/scss/components/FilterSummary/_filter-summary.scss +6 -1
- package/scss/components/Guidebanner/_carbon-imports.scss +6 -0
- package/scss/components/Guidebanner/_guidebanner.scss +248 -0
- package/scss/components/Guidebanner/_index-with-carbon.scss +9 -0
- package/scss/components/Guidebanner/_index.scss +8 -0
- package/scss/components/NonLinearReading/_carbon-imports.scss +6 -0
- package/scss/components/NonLinearReading/_index-with-carbon.scss +9 -0
- package/scss/components/NonLinearReading/_index.scss +8 -0
- package/scss/components/NonLinearReading/_non-linear-reading.scss +122 -0
- package/scss/components/WebTerminal/_web-terminal.scss +1 -2
- package/scss/components/_Canary/_canary.scss +1 -2
- package/scss/components/_Canary/_carbon-imports.scss +7 -0
- package/scss/components/_Canary/_index-with-carbon.scss +8 -0
- package/scss/components/_Canary/_index.scss +7 -0
- package/scss/components/_index-with-carbon.scss +1 -1
- package/scss/components/_index.scss +5 -2
- /package/es/components/Datagrid/{Extensions → Datagrid.stories}/ColumnAlignment/ColumnAlignment.docs-page.js +0 -0
- /package/lib/components/Datagrid/{Extensions → Datagrid.stories}/ColumnAlignment/ColumnAlignment.docs-page.js +0 -0
@@ -0,0 +1,322 @@
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
3
|
+
var _excluded = ["children", "className", "disableArrowScroll", "fadedEdgeColor", "onChangeIsScrollable", "onScroll"];
|
4
|
+
/**
|
5
|
+
* Copyright IBM Corp. 2023, 2023
|
6
|
+
*
|
7
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
9
|
+
*/
|
10
|
+
|
11
|
+
import React, { useCallback, useEffect, useImperativeHandle, useRef } from 'react';
|
12
|
+
import PropTypes from 'prop-types';
|
13
|
+
import { CarouselItem } from './CarouselItem';
|
14
|
+
import cx from 'classnames';
|
15
|
+
import { getDevtoolsProps } from '../../global/js/utils/devtools';
|
16
|
+
import { pkg } from '../../settings';
|
17
|
+
|
18
|
+
// The block part of our conventional BEM class names (blockClass__E--M).
|
19
|
+
var blockClass = "".concat(pkg.prefix, "--carousel");
|
20
|
+
var componentName = 'Carousel';
|
21
|
+
|
22
|
+
// Default values for props
|
23
|
+
var defaults = {
|
24
|
+
disableArrowScroll: false,
|
25
|
+
onScroll: function onScroll() {},
|
26
|
+
onChangeIsScrollable: function onChangeIsScrollable() {}
|
27
|
+
};
|
28
|
+
|
29
|
+
/**
|
30
|
+
* The Carousel acts as a scaffold for other Novice to Pro content.
|
31
|
+
*
|
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.
|
44
|
+
*/
|
45
|
+
var Carousel = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
46
|
+
var children = _ref.children,
|
47
|
+
className = _ref.className,
|
48
|
+
_ref$disableArrowScro = _ref.disableArrowScroll,
|
49
|
+
disableArrowScroll = _ref$disableArrowScro === void 0 ? defaults.disableArrowScroll : _ref$disableArrowScro,
|
50
|
+
fadedEdgeColor = _ref.fadedEdgeColor,
|
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,
|
55
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
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)));
|
60
|
+
var leftFadedEdgeColor = (fadedEdgeColor === null || fadedEdgeColor === void 0 ? void 0 : fadedEdgeColor.left) || fadedEdgeColor;
|
61
|
+
var rightFadedEdgeColor = (fadedEdgeColor === null || fadedEdgeColor === void 0 ? void 0 : fadedEdgeColor.right) || fadedEdgeColor;
|
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;
|
78
|
+
}
|
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());
|
101
|
+
});
|
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();
|
112
|
+
});
|
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();
|
154
|
+
}, []);
|
155
|
+
|
156
|
+
// Trigger a callback after first render (and applied CSS).
|
157
|
+
useEffect(function () {
|
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.
|
171
|
+
useEffect(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) {
|
197
|
+
// update the scroll position
|
198
|
+
event.stopPropagation();
|
199
|
+
event.preventDefault();
|
200
|
+
event.cancelBubble = false;
|
201
|
+
}
|
202
|
+
var scrollDiv = scrollRef.current;
|
203
|
+
if (scrollDiv) {
|
204
|
+
scrollDiv.addEventListener('wheel', handleWheel, {
|
205
|
+
passive: false
|
206
|
+
});
|
207
|
+
return function () {
|
208
|
+
scrollDiv.removeEventListener('wheel', handleWheel, {
|
209
|
+
passive: false
|
210
|
+
});
|
211
|
+
};
|
212
|
+
}
|
213
|
+
}, []);
|
214
|
+
|
215
|
+
// Enable arrow scrolling from within the carousel
|
216
|
+
useEffect(function () {
|
217
|
+
function handleKeydown(event) {
|
218
|
+
var key = event.key;
|
219
|
+
if ((key === 'ArrowLeft' || key === 'ArrowRight') && disableArrowScroll) {
|
220
|
+
event.stopPropagation();
|
221
|
+
event.preventDefault();
|
222
|
+
event.cancelBubble = false;
|
223
|
+
}
|
224
|
+
}
|
225
|
+
var carouselDiv = carouselRef.current;
|
226
|
+
if (carouselDiv) {
|
227
|
+
carouselDiv.addEventListener('keydown', handleKeydown);
|
228
|
+
return function () {
|
229
|
+
return carouselDiv.removeEventListener('keydown', handleKeydown);
|
230
|
+
};
|
231
|
+
}
|
232
|
+
}, [disableArrowScroll]);
|
233
|
+
|
234
|
+
// Enable external function calls
|
235
|
+
useImperativeHandle(ref, function () {
|
236
|
+
return {
|
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
|
+
}
|
249
|
+
};
|
250
|
+
}, [handleScrollNext, handleScrollPrev, handleScrollReset, handleScrollToView]);
|
251
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
252
|
+
tabIndex: -1,
|
253
|
+
className: cx(blockClass, className),
|
254
|
+
ref: carouselRef,
|
255
|
+
role: "main"
|
256
|
+
}, getDevtoolsProps(componentName)), /*#__PURE__*/React.createElement("div", {
|
257
|
+
className: cx("".concat(blockClass, "__elements-container"))
|
258
|
+
}, /*#__PURE__*/React.createElement("div", {
|
259
|
+
className: "".concat(blockClass, "__elements"),
|
260
|
+
ref: scrollRef
|
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);
|
268
|
+
})), leftFadedEdgeColor && /*#__PURE__*/React.createElement("div", {
|
269
|
+
className: "".concat(blockClass, "__elements-container--scrolled"),
|
270
|
+
style: {
|
271
|
+
background: "linear-gradient(90deg, ".concat(leftFadedEdgeColor, ", transparent)")
|
272
|
+
}
|
273
|
+
}), rightFadedEdgeColor && /*#__PURE__*/React.createElement("div", {
|
274
|
+
className: "".concat(blockClass, "__elements-container--scroll-max"),
|
275
|
+
style: {
|
276
|
+
background: "linear-gradient(270deg, ".concat(rightFadedEdgeColor, ", transparent)")
|
277
|
+
}
|
278
|
+
})));
|
279
|
+
});
|
280
|
+
Carousel.displayName = componentName;
|
281
|
+
|
282
|
+
// The types and DocGen commentary for the component props,
|
283
|
+
// in alphabetical order (for consistency).
|
284
|
+
// See https://www.npmjs.com/package/prop-types#usage.
|
285
|
+
Carousel.propTypes = {
|
286
|
+
/**
|
287
|
+
* Provide the contents of the Carousel.
|
288
|
+
*/
|
289
|
+
children: PropTypes.node.isRequired,
|
290
|
+
/**
|
291
|
+
* Provide an optional class to be applied to the containing node.
|
292
|
+
*/
|
293
|
+
className: PropTypes.string,
|
294
|
+
/**
|
295
|
+
* Disables the ability of the Carousel to scroll
|
296
|
+
* use a keyboard's left and right arrow keys.
|
297
|
+
*/
|
298
|
+
disableArrowScroll: PropTypes.bool,
|
299
|
+
/**
|
300
|
+
* Enables the edges of the component to have faded styling.
|
301
|
+
*
|
302
|
+
* Pass a single string (`$color`) to specify the same color for left and right.
|
303
|
+
*
|
304
|
+
* Or pass an object (`{ left: $color1, right: $color2 }`) to specify different colors.
|
305
|
+
*/
|
306
|
+
fadedEdgeColor: PropTypes.oneOfType([PropTypes.string, PropTypes.shape({
|
307
|
+
left: PropTypes.string,
|
308
|
+
right: PropTypes.string
|
309
|
+
})]),
|
310
|
+
/**
|
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.
|
314
|
+
*/
|
315
|
+
onChangeIsScrollable: PropTypes.func,
|
316
|
+
/**
|
317
|
+
* An optional callback function that returns the scroll position as
|
318
|
+
* a value between 0 and 1.
|
319
|
+
*/
|
320
|
+
onScroll: PropTypes.func
|
321
|
+
};
|
322
|
+
export { Carousel };
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
3
|
+
var _excluded = ["children", "className"];
|
4
|
+
/**
|
5
|
+
* Copyright IBM Corp. 2023, 2023
|
6
|
+
*
|
7
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
9
|
+
*/
|
10
|
+
|
11
|
+
import React from 'react';
|
12
|
+
|
13
|
+
// Other standard imports.
|
14
|
+
import PropTypes from 'prop-types';
|
15
|
+
import cx from 'classnames';
|
16
|
+
import { getDevtoolsProps } from '../../global/js/utils/devtools';
|
17
|
+
import { pkg } from '../../settings';
|
18
|
+
|
19
|
+
// Carbon and package components we use.
|
20
|
+
/* TODO: @import(s) of carbon components and other package components. */
|
21
|
+
|
22
|
+
// The block part of our conventional BEM class names (blockClass__E--M).
|
23
|
+
var blockClass = "".concat(pkg.prefix, "--carousel__item");
|
24
|
+
var componentName = 'CarouselItem';
|
25
|
+
|
26
|
+
/**
|
27
|
+
* TODO: A description of the component.
|
28
|
+
*/
|
29
|
+
var CarouselItem = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
30
|
+
var children = _ref.children,
|
31
|
+
className = _ref.className,
|
32
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
33
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
34
|
+
className: cx(blockClass, className)
|
35
|
+
}, getDevtoolsProps(componentName), {
|
36
|
+
ref: ref
|
37
|
+
}), children);
|
38
|
+
});
|
39
|
+
CarouselItem.displayName = componentName;
|
40
|
+
// The types and DocGen commentary for the component props,
|
41
|
+
// in alphabetical order (for consistency).
|
42
|
+
// See https://www.npmjs.com/package/prop-types#usage.
|
43
|
+
CarouselItem.propTypes = {
|
44
|
+
/**
|
45
|
+
* Provide the contents of the CarouselItem.
|
46
|
+
*/
|
47
|
+
children: PropTypes.node.isRequired,
|
48
|
+
/**
|
49
|
+
* Provide an optional class to be applied to the containing node.
|
50
|
+
*/
|
51
|
+
className: PropTypes.string
|
52
|
+
};
|
53
|
+
export { CarouselItem };
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright IBM Corp. 2023, 2023
|
3
|
+
*
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
|
8
|
+
export { Carousel } from './Carousel';
|
9
|
+
export { CarouselItem } from './CarouselItem';
|
@@ -0,0 +1,98 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
2
|
+
/**
|
3
|
+
* Copyright IBM Corp. 2023, 2023
|
4
|
+
*
|
5
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
7
|
+
*/
|
8
|
+
|
9
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
10
|
+
export var useIntersection = function useIntersection(element, threshold) {
|
11
|
+
var _useState = useState(false),
|
12
|
+
_useState2 = _slicedToArray(_useState, 2),
|
13
|
+
isVisible = _useState2[0],
|
14
|
+
setState = _useState2[1];
|
15
|
+
useEffect(function () {
|
16
|
+
var el = element.current;
|
17
|
+
var observer = new IntersectionObserver(function (_ref) {
|
18
|
+
var _ref2 = _slicedToArray(_ref, 1),
|
19
|
+
entry = _ref2[0];
|
20
|
+
setState(entry.isIntersecting);
|
21
|
+
}, {
|
22
|
+
threshold: threshold
|
23
|
+
});
|
24
|
+
el && observer.observe(el);
|
25
|
+
return function () {
|
26
|
+
return observer.unobserve(el);
|
27
|
+
};
|
28
|
+
}, [element, threshold]);
|
29
|
+
return isVisible;
|
30
|
+
};
|
31
|
+
export var useIsOverflow = function useIsOverflow(ref) {
|
32
|
+
var _useState3 = useState(),
|
33
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
34
|
+
isScrollable = _useState4[0],
|
35
|
+
setIsScrollable = _useState4[1];
|
36
|
+
var _useState5 = useState(),
|
37
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
38
|
+
mutationObserver = _useState6[0],
|
39
|
+
setMutationObserver = _useState6[1];
|
40
|
+
var _useState7 = useState(),
|
41
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
42
|
+
resizeObserver = _useState8[0],
|
43
|
+
setResizeObserver = _useState8[1];
|
44
|
+
var checkOverflow = useCallback(function () {
|
45
|
+
if (!ref.current) {
|
46
|
+
return;
|
47
|
+
}
|
48
|
+
var hasOverflow = ref.current.scrollWidth > ref.current.clientWidth;
|
49
|
+
setIsScrollable(hasOverflow);
|
50
|
+
}, [ref]);
|
51
|
+
useEffect(function () {
|
52
|
+
if (!mutationObserver) {
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
return function () {
|
56
|
+
if (mutationObserver) {
|
57
|
+
mutationObserver.disconnect();
|
58
|
+
}
|
59
|
+
if (resizeObserver) {
|
60
|
+
resizeObserver.disconnect();
|
61
|
+
}
|
62
|
+
};
|
63
|
+
});
|
64
|
+
useLayoutEffect(function () {
|
65
|
+
var current = ref.current;
|
66
|
+
if (current) {
|
67
|
+
if ('ResizeObserver' in window && !resizeObserver) {
|
68
|
+
setResizeObserver(new ResizeObserver(checkOverflow).observe(current));
|
69
|
+
}
|
70
|
+
if ('MutationObserver' in window && !mutationObserver) {
|
71
|
+
setMutationObserver(new MutationObserver(checkOverflow).observe(current, {
|
72
|
+
attributes: false,
|
73
|
+
childList: true,
|
74
|
+
subtree: false
|
75
|
+
}));
|
76
|
+
}
|
77
|
+
checkOverflow();
|
78
|
+
}
|
79
|
+
}, [ref, checkOverflow, mutationObserver, resizeObserver]);
|
80
|
+
return isScrollable;
|
81
|
+
};
|
82
|
+
export var useWindowEvent = function useWindowEvent(eventName, callback) {
|
83
|
+
var savedCallback = useRef(null);
|
84
|
+
useEffect(function () {
|
85
|
+
savedCallback.current = callback;
|
86
|
+
});
|
87
|
+
useEffect(function () {
|
88
|
+
function handler(event) {
|
89
|
+
if (savedCallback.current) {
|
90
|
+
savedCallback.current(event);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
window.addEventListener(eventName, handler);
|
94
|
+
return function () {
|
95
|
+
window.removeEventListener(eventName, handler);
|
96
|
+
};
|
97
|
+
}, [eventName]);
|
98
|
+
};
|
@@ -78,7 +78,7 @@ var useFilters = function useFilters(_ref2) {
|
|
78
78
|
/** Methods */
|
79
79
|
// If the user decides to cancel or click outside the flyout, it reverts back to the filters that were
|
80
80
|
// there when they opened the flyout
|
81
|
-
var revertToPreviousFilters = function
|
81
|
+
var revertToPreviousFilters = useCallback(function () {
|
82
82
|
setFiltersState(JSON.parse(prevFiltersRef.current));
|
83
83
|
setFiltersObjectArray(JSON.parse(prevFiltersObjectArrayRef.current));
|
84
84
|
setAllFilters(JSON.parse(lastAppliedFilters.current));
|
@@ -88,7 +88,7 @@ var useFilters = function useFilters(_ref2) {
|
|
88
88
|
holdingPrevFiltersRef.current = JSON.parse(prevFiltersRef.current);
|
89
89
|
holdingLastAppliedFiltersRef.current = JSON.parse(prevFiltersObjectArrayRef.current);
|
90
90
|
holdingPrevFiltersObjectArrayRef.current = JSON.parse(lastAppliedFilters.current);
|
91
|
-
};
|
91
|
+
}, [setAllFilters]);
|
92
92
|
var reset = useCallback(function () {
|
93
93
|
// When we reset we want the "initialFilters" to be an empty array
|
94
94
|
var resetFiltersArray = [];
|
@@ -352,6 +352,7 @@ var useFilters = function useFilters(_ref2) {
|
|
352
352
|
*/
|
353
353
|
useEffect(function () {
|
354
354
|
if (!panelOpen && previousState !== null && previousState !== void 0 && previousState.panelOpen) {
|
355
|
+
revertToPreviousFilters();
|
355
356
|
setAllFilters(holdingLastAppliedFiltersRef.current);
|
356
357
|
}
|
357
358
|
if (panelOpen && !(previousState !== null && previousState !== void 0 && previousState.panelOpen)) {
|
@@ -361,7 +362,7 @@ var useFilters = function useFilters(_ref2) {
|
|
361
362
|
setAllFilters(JSON.parse(prevFiltersObjectArrayRef.current));
|
362
363
|
}
|
363
364
|
}
|
364
|
-
}, [panelOpen, previousState, previousState === null || previousState === void 0 ? void 0 : previousState.panelOpen, reset, setAllFilters]);
|
365
|
+
}, [panelOpen, previousState, previousState === null || previousState === void 0 ? void 0 : previousState.panelOpen, reset, setAllFilters, revertToPreviousFilters]);
|
365
366
|
var cancel = function cancel() {
|
366
367
|
// Reverting to previous filters only applies when using batch actions
|
367
368
|
if (updateMethod === BATCH) {
|
@@ -41,6 +41,12 @@ export var DocsPage = function DocsPage() {
|
|
41
41
|
}, {
|
42
42
|
subTitle: 'Create your filters for panel variant',
|
43
43
|
description: 'Filter panel coming soon.'
|
44
|
+
}, {
|
45
|
+
subTitle: 'Customizing the filter tag labels',
|
46
|
+
description: 'You can customize the rendering of the filter tag labels by supplying the `renderLabel` property to your `filterProps` as seen below. Otherwise it will default to `key: value`.',
|
47
|
+
source: {
|
48
|
+
code: "\nfilterProps: {\n ...otherFilterProps,\n renderLabel: (key, value) => myCustomTagLabelFormatter(key, value),\n},\n "
|
49
|
+
}
|
44
50
|
}, {
|
45
51
|
subTitle: 'Putting it all together',
|
46
52
|
source: {
|
@@ -50,7 +56,7 @@ export var DocsPage = function DocsPage() {
|
|
50
56
|
subTitle: "`filterProps` types",
|
51
57
|
source: {
|
52
58
|
language: 'json',
|
53
|
-
code: "\nfilterProps: {\n /** The variation of filtering */\n variation: 'flyout'|'panel',\n /** The update method in which to filter, instant automatically\n applies the filters, batch the user has to click apply */\n updateMethod: 'batch'|'instant',\n /** Text for primary action button, default is 'Apply' */\n primaryActionLabel: string,\n /** Text for secondary action button, default is 'Cancel' */\n secondaryActionLabel: string,\n /** Text for flyout icon description */\n flyoutIconDescription: string,\n /** Array of objects to render filters in flyout */\n filters: object[]\n}\n "
|
59
|
+
code: "\nfilterProps: {\n /** The variation of filtering */\n variation: 'flyout'|'panel',\n /** The update method in which to filter, instant automatically\n applies the filters, batch the user has to click apply */\n updateMethod: 'batch'|'instant',\n /** Text for primary action button, default is 'Apply' */\n primaryActionLabel: string,\n /** Text for secondary action button, default is 'Cancel' */\n secondaryActionLabel: string,\n /** Text for flyout icon description */\n flyoutIconDescription: string,\n /** Array of objects to render filters in flyout */\n filters: object[]\n /** Applies custom formatting to filter tags */\n renderLabel: Function\n}\n "
|
54
60
|
}
|
55
61
|
}]
|
56
62
|
});
|
@@ -0,0 +1,26 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright IBM Corp. 2023, 2023
|
3
|
+
*
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
|
8
|
+
// Example usage for custom filter tag labels, in practice this
|
9
|
+
// is where a translation service would be utilized. This
|
10
|
+
// utility is for storybook demonstration purposes only.
|
11
|
+
export var handleFilterTagLabelText = function handleFilterTagLabelText(key, value) {
|
12
|
+
switch (key) {
|
13
|
+
case 'role':
|
14
|
+
return "Role: ".concat(value);
|
15
|
+
case 'joined':
|
16
|
+
return "Joined: ".concat(value);
|
17
|
+
case 'visits':
|
18
|
+
return "Visits: ".concat(value);
|
19
|
+
case 'passwordStrength':
|
20
|
+
return "Password strength: ".concat(value);
|
21
|
+
case 'status':
|
22
|
+
return "Status: ".concat(value);
|
23
|
+
default:
|
24
|
+
return "".concat(key, ": ").concat(value);
|
25
|
+
}
|
26
|
+
};
|
@@ -4,19 +4,21 @@ var _excluded = ["key", "value"];
|
|
4
4
|
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; }
|
5
5
|
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; }
|
6
6
|
/**
|
7
|
-
* Copyright IBM Corp. 2022,
|
7
|
+
* Copyright IBM Corp. 2022, 2023
|
8
8
|
*
|
9
9
|
* This source code is licensed under the Apache-2.0 license found in the
|
10
10
|
* LICENSE file in the root directory of this source tree.
|
11
11
|
*/
|
12
12
|
import { Button } from '@carbon/react';
|
13
|
-
import React from 'react';
|
13
|
+
import React, { useRef } from 'react';
|
14
14
|
import PropTypes from 'prop-types';
|
15
15
|
import cx from 'classnames';
|
16
16
|
import { TagSet } from '../TagSet';
|
17
17
|
import { pkg } from '../../settings';
|
18
|
+
import uuidv4 from '../../global/js/utils/uuidv4';
|
18
19
|
var blockClass = "".concat(pkg.prefix, "--filter-summary");
|
19
20
|
var FilterSummary = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
21
|
+
var _filterSummaryClearBu;
|
20
22
|
var _ref$className = _ref.className,
|
21
23
|
className = _ref$className === void 0 ? '' : _ref$className,
|
22
24
|
_ref$clearFiltersText = _ref.clearFiltersText,
|
@@ -28,7 +30,10 @@ var FilterSummary = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
28
30
|
_ref$renderLabel = _ref.renderLabel,
|
29
31
|
renderLabel = _ref$renderLabel === void 0 ? null : _ref$renderLabel,
|
30
32
|
_ref$overflowType = _ref.overflowType,
|
31
|
-
overflowType = _ref$overflowType === void 0 ? 'default' : _ref$overflowType
|
33
|
+
overflowType = _ref$overflowType === void 0 ? 'default' : _ref$overflowType,
|
34
|
+
_ref$clearButtonInlin = _ref.clearButtonInline,
|
35
|
+
clearButtonInline = _ref$clearButtonInlin === void 0 ? true : _ref$clearButtonInlin;
|
36
|
+
var filterSummaryId = "".concat(blockClass, "__").concat(uuidv4());
|
32
37
|
var tagFilters = filters.map(function (_ref2) {
|
33
38
|
var _renderLabel;
|
34
39
|
var key = _ref2.key,
|
@@ -39,26 +44,35 @@ var FilterSummary = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
39
44
|
label: (_renderLabel = renderLabel === null || renderLabel === void 0 ? void 0 : renderLabel(key, value)) !== null && _renderLabel !== void 0 ? _renderLabel : "".concat(key, ": ").concat(value)
|
40
45
|
});
|
41
46
|
});
|
47
|
+
var filterSummaryClearButton = useRef();
|
48
|
+
var filterSummaryRef = useRef();
|
49
|
+
var localRef = filterSummaryRef || ref;
|
42
50
|
return /*#__PURE__*/React.createElement("div", {
|
43
|
-
ref:
|
44
|
-
className: cx([blockClass, className])
|
51
|
+
ref: localRef,
|
52
|
+
className: cx([blockClass, className]),
|
53
|
+
id: filterSummaryId
|
45
54
|
}, /*#__PURE__*/React.createElement(TagSet, {
|
46
55
|
allTagsModalSearchLabel: "Search all tags",
|
47
56
|
allTagsModalSearchPlaceholderText: "Search all tags",
|
48
57
|
allTagsModalTitle: "All tags",
|
49
58
|
showAllTagsLabel: "View all tags",
|
50
59
|
tags: tagFilters,
|
51
|
-
overflowType: overflowType
|
60
|
+
overflowType: overflowType,
|
61
|
+
className: cx(_defineProperty({}, "".concat(blockClass, "__clear-button-inline"), clearButtonInline)),
|
62
|
+
containingElementRef: localRef,
|
63
|
+
measurementOffset: filterSummaryClearButton === null || filterSummaryClearButton === void 0 || (_filterSummaryClearBu = filterSummaryClearButton.current) === null || _filterSummaryClearBu === void 0 ? void 0 : _filterSummaryClearBu.offsetWidth
|
52
64
|
}), /*#__PURE__*/React.createElement(Button, {
|
53
65
|
kind: "ghost",
|
54
66
|
size: "sm",
|
55
|
-
onClick: clearFilters
|
67
|
+
onClick: clearFilters,
|
68
|
+
ref: filterSummaryClearButton
|
56
69
|
}, clearFiltersText));
|
57
70
|
});
|
58
71
|
var componentName = 'FilterSummary';
|
59
72
|
FilterSummary.displayName = componentName;
|
60
73
|
FilterSummary.propTypes = {
|
61
74
|
className: PropTypes.string,
|
75
|
+
clearButtonInline: PropTypes.bool,
|
62
76
|
clearFilters: PropTypes.func.isRequired,
|
63
77
|
clearFiltersText: PropTypes.string,
|
64
78
|
filters: PropTypes.arrayOf(PropTypes.object).isRequired,
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { StoryDocsPage } from '../../global/js/utils/StoryDocsPage';
|
3
|
+
import * as stories from './Guidebanner.stories';
|
4
|
+
var DocsPage = function DocsPage() {
|
5
|
+
return /*#__PURE__*/React.createElement(StoryDocsPage, {
|
6
|
+
blocks: [{
|
7
|
+
story: stories.collapsible
|
8
|
+
}, {
|
9
|
+
story: stories.manyInsights
|
10
|
+
}, {
|
11
|
+
story: stories.fewInsights
|
12
|
+
}]
|
13
|
+
});
|
14
|
+
};
|
15
|
+
export default DocsPage;
|