@carbon/ibm-products 2.22.0 → 2.24.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -1
- package/css/index-full-carbon.css +29490 -28295
- 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 +81 -104
- 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 +24399 -350
- 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 +17204 -123
- 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/Card/Card.js +1 -2
- package/es/components/Card/CardHeader.js +2 -2
- package/es/components/Carousel/Carousel.js +5 -3
- package/es/components/Coachmark/Coachmark.js +255 -0
- package/es/components/Coachmark/CoachmarkDragbar.js +146 -0
- package/es/components/Coachmark/CoachmarkHeader.js +91 -0
- package/es/components/Coachmark/CoachmarkOverlay.js +235 -0
- package/es/components/Coachmark/CoachmarkTagline.js +97 -0
- package/es/components/Coachmark/index.js +10 -0
- package/es/components/Coachmark/utils/constants.js +76 -0
- package/es/components/Coachmark/utils/context.js +5 -0
- package/es/components/Coachmark/utils/enums.js +40 -0
- package/es/components/Coachmark/utils/helpers.js +11 -0
- package/es/components/Coachmark/utils/hooks.js +54 -0
- package/es/components/CoachmarkBeacon/CoachmarkBeacon.js +93 -0
- package/es/components/CoachmarkBeacon/index.js +8 -0
- package/es/components/CoachmarkButton/CoachmarkButton.js +90 -0
- package/es/components/CoachmarkButton/index.js +8 -0
- package/es/components/CoachmarkFixed/CoachmarkFixed.js +226 -0
- package/es/components/CoachmarkFixed/index.js +8 -0
- package/es/components/CoachmarkOverlayElement/CoachmarkOverlayElement.js +86 -0
- package/es/components/CoachmarkOverlayElement/index.js +8 -0
- package/es/components/CoachmarkOverlayElements/CoachmarkOverlayElements.js +216 -0
- package/es/components/CoachmarkOverlayElements/index.js +8 -0
- package/es/components/CoachmarkStack/CoachmarkStack.js +283 -0
- package/es/components/CoachmarkStack/CoachmarkStackHome.js +192 -0
- package/es/components/CoachmarkStack/index.js +8 -0
- package/es/components/Datagrid/Datagrid/DatagridHeaderRow.js +14 -4
- package/es/components/Datagrid/Datagrid/DatagridSelectAll.js +4 -1
- package/es/components/Datagrid/Datagrid/DraggableElement.js +1 -1
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js +1 -1
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +4 -1
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsTearsheet.js +1 -1
- package/es/components/Datagrid/Datagrid/addons/Slug/ColumnHeaderSlug.js +26 -0
- package/es/components/Datagrid/Datagrid.docs-page.js +2 -2
- package/es/components/Datagrid/useActionsColumn.js +16 -12
- package/es/components/Datagrid/useDefaultStringRenderer.js +3 -3
- package/es/components/Datagrid/useNestedRowExpander.js +2 -2
- package/es/components/Datagrid/useSortableColumns.js +15 -5
- package/es/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +7 -2
- package/es/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +8 -3
- package/es/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +7 -2
- package/es/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +7 -2
- package/es/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +7 -2
- package/es/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +7 -2
- package/es/components/EmptyStates/assets/ErrorIllustration.js +5 -5
- package/es/components/EmptyStates/assets/NoDataIllustration.js +5 -5
- package/es/components/EmptyStates/assets/NoTagsIllustration.js +5 -5
- package/es/components/EmptyStates/assets/NotFoundIllustration.js +5 -5
- package/es/components/EmptyStates/assets/NotificationsIllustration.js +5 -5
- package/es/components/EmptyStates/assets/UnauthorizedIllustration.js +5 -5
- package/es/components/FilterSummary/FilterSummary.js +100 -19
- package/es/components/InterstitialScreen/InterstitialScreen.js +427 -0
- package/es/components/InterstitialScreen/index.js +8 -0
- package/es/components/InterstitialScreenView/InterstitialScreenView.js +75 -0
- package/es/components/InterstitialScreenView/index.js +8 -0
- package/es/components/InterstitialScreenViewModule/InterstitialScreenViewModule.js +83 -0
- package/es/components/InterstitialScreenViewModule/index.js +8 -0
- package/es/components/PageHeader/PageHeaderUtils.js +2 -2
- package/es/components/SearchBar/SearchBar.js +227 -0
- package/es/components/SearchBar/index.js +8 -0
- package/es/components/TagSet/TagSet.js +11 -3
- package/es/components/index.js +12 -1
- package/es/global/js/hooks/useResizeObserver.js +2 -2
- package/es/global/js/package-settings.js +14 -0
- package/lib/components/Card/Card.js +3 -4
- package/lib/components/Card/CardHeader.js +2 -2
- package/lib/components/Carousel/Carousel.js +5 -3
- package/lib/components/Coachmark/Coachmark.js +264 -0
- package/lib/components/Coachmark/CoachmarkDragbar.js +151 -0
- package/lib/components/Coachmark/CoachmarkHeader.js +95 -0
- package/lib/components/Coachmark/CoachmarkOverlay.js +243 -0
- package/lib/components/Coachmark/CoachmarkTagline.js +101 -0
- package/lib/components/Coachmark/index.js +38 -0
- package/lib/components/Coachmark/utils/constants.js +81 -0
- package/lib/components/Coachmark/utils/context.js +11 -0
- package/lib/components/Coachmark/utils/enums.js +46 -0
- package/lib/components/Coachmark/utils/helpers.js +17 -0
- package/lib/components/Coachmark/utils/hooks.js +59 -0
- package/lib/components/CoachmarkBeacon/CoachmarkBeacon.js +97 -0
- package/lib/components/CoachmarkBeacon/index.js +12 -0
- package/lib/components/CoachmarkButton/CoachmarkButton.js +93 -0
- package/lib/components/CoachmarkButton/index.js +12 -0
- package/lib/components/CoachmarkFixed/CoachmarkFixed.js +232 -0
- package/lib/components/CoachmarkFixed/index.js +12 -0
- package/lib/components/CoachmarkOverlayElement/CoachmarkOverlayElement.js +90 -0
- package/lib/components/CoachmarkOverlayElement/index.js +12 -0
- package/lib/components/CoachmarkOverlayElements/CoachmarkOverlayElements.js +222 -0
- package/lib/components/CoachmarkOverlayElements/index.js +12 -0
- package/lib/components/CoachmarkStack/CoachmarkStack.js +288 -0
- package/lib/components/CoachmarkStack/CoachmarkStackHome.js +198 -0
- package/lib/components/CoachmarkStack/index.js +12 -0
- package/lib/components/Datagrid/Datagrid/DatagridHeaderRow.js +14 -4
- package/lib/components/Datagrid/Datagrid/DatagridSelectAll.js +4 -1
- package/lib/components/Datagrid/Datagrid/DraggableElement.js +1 -1
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js +1 -1
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +4 -1
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsTearsheet.js +1 -1
- package/lib/components/Datagrid/Datagrid/addons/Slug/ColumnHeaderSlug.js +36 -0
- package/lib/components/Datagrid/Datagrid.docs-page.js +2 -2
- package/lib/components/Datagrid/useActionsColumn.js +15 -11
- package/lib/components/Datagrid/useDefaultStringRenderer.js +3 -3
- package/lib/components/Datagrid/useNestedRowExpander.js +2 -2
- package/lib/components/Datagrid/useSortableColumns.js +15 -5
- package/lib/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +7 -2
- package/lib/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +8 -3
- package/lib/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +7 -2
- package/lib/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +7 -2
- package/lib/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +7 -2
- package/lib/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +7 -2
- package/lib/components/EmptyStates/assets/ErrorIllustration.js +5 -5
- package/lib/components/EmptyStates/assets/NoDataIllustration.js +5 -5
- package/lib/components/EmptyStates/assets/NoTagsIllustration.js +5 -5
- package/lib/components/EmptyStates/assets/NotFoundIllustration.js +5 -5
- package/lib/components/EmptyStates/assets/NotificationsIllustration.js +5 -5
- package/lib/components/EmptyStates/assets/UnauthorizedIllustration.js +5 -5
- package/lib/components/FilterSummary/FilterSummary.js +103 -23
- package/lib/components/InterstitialScreen/InterstitialScreen.js +434 -0
- package/lib/components/InterstitialScreen/index.js +12 -0
- package/lib/components/InterstitialScreenView/InterstitialScreenView.js +77 -0
- package/lib/components/InterstitialScreenView/index.js +12 -0
- package/lib/components/InterstitialScreenViewModule/InterstitialScreenViewModule.js +85 -0
- package/lib/components/InterstitialScreenViewModule/index.js +12 -0
- package/lib/components/PageHeader/PageHeaderUtils.js +2 -2
- package/lib/components/SearchBar/SearchBar.js +233 -0
- package/lib/components/SearchBar/index.js +12 -0
- package/lib/components/TagSet/TagSet.js +11 -3
- package/lib/components/index.js +78 -1
- package/lib/global/js/hooks/useResizeObserver.js +2 -2
- package/lib/global/js/package-settings.js +14 -0
- package/package.json +5 -5
- package/scss/components/Card/_card.scss +6 -5
- package/scss/components/Coachmark/_carbon-imports.scss +10 -0
- package/scss/components/Coachmark/_coachmark-dragbar.scss +27 -0
- package/scss/components/Coachmark/_coachmark-header.scss +20 -0
- package/scss/components/Coachmark/_coachmark-overlay.scss +431 -0
- package/scss/components/Coachmark/_coachmark-tagline.scss +140 -0
- package/scss/components/Coachmark/_coachmark.scss +30 -0
- package/scss/components/Coachmark/_index-with-carbon.scss +9 -0
- package/scss/components/Coachmark/_index.scss +8 -0
- package/scss/components/CoachmarkBeacon/_carbon-imports.scss +9 -0
- package/scss/components/CoachmarkBeacon/_coachmark-beacon.scss +166 -0
- package/scss/components/CoachmarkBeacon/_index-with-carbon.scss +9 -0
- package/scss/components/CoachmarkBeacon/_index.scss +8 -0
- package/scss/components/CoachmarkButton/_carbon-imports.scss +9 -0
- package/scss/components/CoachmarkButton/_coachmark-button.scss +25 -0
- package/scss/components/CoachmarkButton/_index-with-carbon.scss +9 -0
- package/scss/components/CoachmarkButton/_index.scss +8 -0
- package/scss/components/CoachmarkFixed/_carbon-imports.scss +9 -0
- package/scss/components/CoachmarkFixed/_coachmark-fixed.scss +25 -0
- package/scss/components/CoachmarkFixed/_index-with-carbon.scss +9 -0
- package/scss/components/CoachmarkFixed/_index.scss +8 -0
- package/scss/components/CoachmarkOverlayElement/_carbon-imports.scss +9 -0
- package/scss/components/CoachmarkOverlayElement/_coachmark-overlay-element.scss +52 -0
- package/scss/components/CoachmarkOverlayElement/_index-with-carbon.scss +9 -0
- package/scss/components/CoachmarkOverlayElement/_index.scss +8 -0
- package/scss/components/CoachmarkOverlayElements/_carbon-imports.scss +9 -0
- package/scss/components/CoachmarkOverlayElements/_coachmark-overlay-elements.scss +47 -0
- package/scss/components/CoachmarkOverlayElements/_index-with-carbon.scss +9 -0
- package/scss/components/CoachmarkOverlayElements/_index.scss +8 -0
- package/scss/components/CoachmarkStack/_carbon-imports.scss +9 -0
- package/scss/components/CoachmarkStack/_coachmark-stack.scss +95 -0
- package/scss/components/CoachmarkStack/_index-with-carbon.scss +9 -0
- package/scss/components/CoachmarkStack/_index.scss +8 -0
- package/scss/components/CreateSidePanel/_create-side-panel.scss +1 -38
- package/scss/components/Datagrid/styles/_datagrid.scss +15 -0
- package/scss/components/EditSidePanel/_edit-side-panel.scss +0 -18
- package/scss/components/FilterSummary/_filter-summary.scss +22 -1
- package/scss/components/InterstitialScreen/_carbon-imports.scss +9 -0
- package/scss/components/InterstitialScreen/_index-with-carbon.scss +9 -0
- package/scss/components/InterstitialScreen/_index.scss +8 -0
- package/scss/components/InterstitialScreen/_interstitial-screen.scss +276 -0
- package/scss/components/InterstitialScreenView/_carbon-imports.scss +9 -0
- package/scss/components/InterstitialScreenView/_index-with-carbon.scss +9 -0
- package/scss/components/InterstitialScreenView/_index.scss +8 -0
- package/scss/components/InterstitialScreenView/_interstitial-screen-view.scss +25 -0
- package/scss/components/InterstitialScreenViewModule/_carbon-imports.scss +9 -0
- package/scss/components/InterstitialScreenViewModule/_index-with-carbon.scss +9 -0
- package/scss/components/InterstitialScreenViewModule/_index.scss +8 -0
- package/scss/components/InterstitialScreenViewModule/_interstitial-screen-view-module.scss +59 -0
- package/scss/components/PageHeader/_page-header.scss +0 -1
- package/scss/components/SearchBar/_carbon-imports.scss +9 -0
- package/scss/components/SearchBar/_index-with-carbon.scss +9 -0
- package/scss/components/SearchBar/_index.scss +8 -0
- package/scss/components/SearchBar/_search-bar.scss +26 -0
- package/scss/components/SidePanel/_side-panel.scss +12 -7
- package/scss/components/_index-with-carbon.scss +11 -0
- package/scss/components/_index.scss +11 -0
@@ -0,0 +1,235 @@
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
4
|
+
var _excluded = ["children", "onClose", "fixedIsVisible", "className", "kind", "theme"];
|
5
|
+
/**
|
6
|
+
* Copyright IBM Corp. 2023, 2024
|
7
|
+
*
|
8
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
9
|
+
* LICENSE file in the root directory of this source tree.
|
10
|
+
*/
|
11
|
+
|
12
|
+
// Import portions of React that are needed.
|
13
|
+
import React, { forwardRef, useRef, useState, useEffect } from 'react';
|
14
|
+
import uuidv4 from '../../global/js/utils/uuidv4';
|
15
|
+
// Other standard imports.
|
16
|
+
import PropTypes from 'prop-types';
|
17
|
+
import cx from 'classnames';
|
18
|
+
import { getDevtoolsProps } from '../../global/js/utils/devtools';
|
19
|
+
import { pkg /*, carbon */ } from '../../settings';
|
20
|
+
import { CoachmarkDragbar } from './CoachmarkDragbar';
|
21
|
+
import { CoachmarkHeader } from './CoachmarkHeader';
|
22
|
+
import { getOffsetTune } from './utils/constants';
|
23
|
+
import { useCoachmark } from './utils/context';
|
24
|
+
import { COACHMARK_OVERLAY_KIND } from './utils/enums';
|
25
|
+
|
26
|
+
// The block part of our conventional BEM class names (blockClass__E--M).
|
27
|
+
var blockClass = "".concat(pkg.prefix, "--coachmark-overlay");
|
28
|
+
var componentName = 'CoachmarkOverlay';
|
29
|
+
|
30
|
+
// NOTE: the component SCSS is not imported here: it is rolled up separately.
|
31
|
+
|
32
|
+
var defaults = {
|
33
|
+
kind: COACHMARK_OVERLAY_KIND.FLOATING,
|
34
|
+
theme: 'light'
|
35
|
+
};
|
36
|
+
|
37
|
+
/**
|
38
|
+
* DO NOT USE. This component is for the exclusive use
|
39
|
+
* of other Novice to Pro components.
|
40
|
+
*/
|
41
|
+
export var CoachmarkOverlay = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
42
|
+
var children = _ref.children,
|
43
|
+
onClose = _ref.onClose,
|
44
|
+
fixedIsVisible = _ref.fixedIsVisible,
|
45
|
+
className = _ref.className,
|
46
|
+
_ref$kind = _ref.kind,
|
47
|
+
kind = _ref$kind === void 0 ? defaults.kind : _ref$kind,
|
48
|
+
_ref$theme = _ref.theme,
|
49
|
+
theme = _ref$theme === void 0 ? defaults.theme : _ref$theme,
|
50
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
51
|
+
var _useWindowDimensions = useWindowDimensions(),
|
52
|
+
winHeight = _useWindowDimensions.winHeight,
|
53
|
+
winWidth = _useWindowDimensions.winWidth;
|
54
|
+
var _useState = useState(false),
|
55
|
+
_useState2 = _slicedToArray(_useState, 2),
|
56
|
+
a11yDragMode = _useState2[0],
|
57
|
+
setA11yDragMode = _useState2[1];
|
58
|
+
var overlayRef = useRef();
|
59
|
+
var coachmark = useCoachmark();
|
60
|
+
var isBeacon = kind === COACHMARK_OVERLAY_KIND.TOOLTIP;
|
61
|
+
var isDraggable = kind === COACHMARK_OVERLAY_KIND.FLOATING;
|
62
|
+
var isVisible = className && className.includes('is-visible');
|
63
|
+
var handleKeyPress = function handleKeyPress(event) {
|
64
|
+
var shiftKey = event.shiftKey,
|
65
|
+
key = event.key;
|
66
|
+
if (key === 'Enter' || key === ' ') {
|
67
|
+
setA11yDragMode(function (prevVal) {
|
68
|
+
return !prevVal;
|
69
|
+
});
|
70
|
+
} else if (a11yDragMode) {
|
71
|
+
var distanceToMove = shiftKey ? 128 : 32;
|
72
|
+
switch (key) {
|
73
|
+
case 'ArrowLeft':
|
74
|
+
handleDrag(distanceToMove * -1, 0);
|
75
|
+
break;
|
76
|
+
case 'ArrowRight':
|
77
|
+
handleDrag(distanceToMove, 0);
|
78
|
+
break;
|
79
|
+
case 'ArrowUp':
|
80
|
+
handleDrag(0, distanceToMove * -1);
|
81
|
+
break;
|
82
|
+
case 'ArrowDown':
|
83
|
+
handleDrag(0, distanceToMove);
|
84
|
+
break;
|
85
|
+
default:
|
86
|
+
break;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
};
|
90
|
+
var styledTune = {};
|
91
|
+
if (isBeacon || isDraggable) {
|
92
|
+
if (coachmark.targetRect) {
|
93
|
+
styledTune = {
|
94
|
+
left: coachmark.targetRect.x + window.scrollX,
|
95
|
+
top: coachmark.targetRect.y + window.scrollY
|
96
|
+
};
|
97
|
+
}
|
98
|
+
if (isBeacon) {
|
99
|
+
// Compensate for radius of beacon
|
100
|
+
styledTune.left += 16;
|
101
|
+
styledTune.top += 16;
|
102
|
+
} else if (isDraggable) {
|
103
|
+
// Compensate for width and height of target element
|
104
|
+
var offsetTune = getOffsetTune(coachmark, kind);
|
105
|
+
styledTune.left += offsetTune.left;
|
106
|
+
styledTune.top += offsetTune.top;
|
107
|
+
}
|
108
|
+
}
|
109
|
+
function handleDragBounds(x, y) {
|
110
|
+
var xRes = x;
|
111
|
+
var yRes = y;
|
112
|
+
var xMax = winWidth - 288;
|
113
|
+
var yMax = winHeight - 150;
|
114
|
+
if (xRes < 0) {
|
115
|
+
xRes = 0;
|
116
|
+
} else if (xRes > xMax) {
|
117
|
+
xRes = xMax;
|
118
|
+
}
|
119
|
+
if (yRes < 0) {
|
120
|
+
yRes = 0;
|
121
|
+
} else if (yRes > yMax) {
|
122
|
+
yRes = yMax;
|
123
|
+
}
|
124
|
+
return {
|
125
|
+
targetX: xRes,
|
126
|
+
targetY: yRes
|
127
|
+
};
|
128
|
+
}
|
129
|
+
function handleDrag(movementX, movementY) {
|
130
|
+
var overlay = overlayRef.current;
|
131
|
+
var _overlay$getBoundingC = overlay.getBoundingClientRect(),
|
132
|
+
x = _overlay$getBoundingC.x,
|
133
|
+
y = _overlay$getBoundingC.y;
|
134
|
+
var _handleDragBounds = handleDragBounds(x + movementX, y + movementY),
|
135
|
+
targetX = _handleDragBounds.targetX,
|
136
|
+
targetY = _handleDragBounds.targetY;
|
137
|
+
overlay.style.transform = 'none';
|
138
|
+
overlay.style.position = 'fixed';
|
139
|
+
overlay.style.left = "".concat(targetX, "px");
|
140
|
+
overlay.style.top = "".concat(targetY, "px");
|
141
|
+
overlay.style.bottom = 'auto';
|
142
|
+
}
|
143
|
+
var contentId = uuidv4();
|
144
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
145
|
+
className: cx(blockClass, "".concat(blockClass, "--").concat(kind), "".concat(blockClass, "__").concat(theme), (isBeacon || isDraggable) && "".concat(blockClass, "--").concat(coachmark.align), fixedIsVisible && "".concat(blockClass, "--is-visible"), a11yDragMode && "".concat(blockClass, "--is-dragmode"), className),
|
146
|
+
ref: overlayRef,
|
147
|
+
style: styledTune,
|
148
|
+
"aria-labelledby": contentId,
|
149
|
+
tabIndex: -1
|
150
|
+
}, getDevtoolsProps(componentName)), isDraggable ? /*#__PURE__*/React.createElement(CoachmarkDragbar, {
|
151
|
+
a11yKeyboardHandler: handleKeyPress,
|
152
|
+
onBlur: function onBlur() {
|
153
|
+
return setA11yDragMode(false);
|
154
|
+
},
|
155
|
+
onDrag: handleDrag,
|
156
|
+
theme: theme,
|
157
|
+
onClose: onClose
|
158
|
+
}) : /*#__PURE__*/React.createElement(CoachmarkHeader, {
|
159
|
+
onClose: onClose
|
160
|
+
}), /*#__PURE__*/React.createElement("div", {
|
161
|
+
className: "".concat(blockClass, "__body"),
|
162
|
+
ref: ref,
|
163
|
+
id: contentId
|
164
|
+
}, React.Children.map(children, function (child) {
|
165
|
+
return /*#__PURE__*/React.cloneElement(child, {
|
166
|
+
isVisible: isVisible
|
167
|
+
});
|
168
|
+
})), isBeacon && /*#__PURE__*/React.createElement("span", {
|
169
|
+
className: "".concat(blockClass, "__caret")
|
170
|
+
}));
|
171
|
+
});
|
172
|
+
function getWindowDimensions() {
|
173
|
+
var _window = window,
|
174
|
+
winWidth = _window.innerWidth,
|
175
|
+
winHeight = _window.innerHeight;
|
176
|
+
return {
|
177
|
+
winWidth: winWidth,
|
178
|
+
winHeight: winHeight
|
179
|
+
};
|
180
|
+
}
|
181
|
+
var useWindowDimensions = function useWindowDimensions() {
|
182
|
+
var _useState3 = useState(getWindowDimensions()),
|
183
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
184
|
+
windowDimensions = _useState4[0],
|
185
|
+
setWindowDimensions = _useState4[1];
|
186
|
+
useEffect(function () {
|
187
|
+
function handleResize() {
|
188
|
+
setWindowDimensions(getWindowDimensions());
|
189
|
+
}
|
190
|
+
window.addEventListener('resize', handleResize);
|
191
|
+
return function () {
|
192
|
+
return window.removeEventListener('resize', handleResize);
|
193
|
+
};
|
194
|
+
}, []);
|
195
|
+
return windowDimensions;
|
196
|
+
};
|
197
|
+
|
198
|
+
// Return a placeholder if not released and not enabled by feature flag
|
199
|
+
CoachmarkOverlay = pkg.checkComponentEnabled(CoachmarkOverlay, componentName);
|
200
|
+
|
201
|
+
// The display name of the component, used by React. Note that displayName
|
202
|
+
// is used in preference to relying on function.name.
|
203
|
+
CoachmarkOverlay.displayName = componentName;
|
204
|
+
|
205
|
+
// The types and DocGen commentary for the component props,
|
206
|
+
// in alphabetical order (for consistency).
|
207
|
+
// See https://www.npmjs.com/package/prop-types#usage.
|
208
|
+
CoachmarkOverlay.propTypes = {
|
209
|
+
/**
|
210
|
+
* The CoachmarkOverlayElements child components.
|
211
|
+
* Validation is handled in the parent Coachmark component.
|
212
|
+
*/
|
213
|
+
children: PropTypes.node.isRequired,
|
214
|
+
/**
|
215
|
+
* Optional class name for this component.
|
216
|
+
*/
|
217
|
+
className: PropTypes.string,
|
218
|
+
/**
|
219
|
+
* The visibility of CoachmarkOverlay is
|
220
|
+
* managed in the parent Coachmark component.
|
221
|
+
*/
|
222
|
+
fixedIsVisible: PropTypes.bool.isRequired,
|
223
|
+
/**
|
224
|
+
* What kind or style of Coachmark to render.
|
225
|
+
*/
|
226
|
+
kind: PropTypes.oneOf(Object.values(COACHMARK_OVERLAY_KIND)),
|
227
|
+
/**
|
228
|
+
* Function to call when the Coachmark closes.
|
229
|
+
*/
|
230
|
+
onClose: PropTypes.func.isRequired,
|
231
|
+
/**
|
232
|
+
* Determines the theme of the component.
|
233
|
+
*/
|
234
|
+
theme: PropTypes.oneOf(['light', 'dark'])
|
235
|
+
};
|
@@ -0,0 +1,97 @@
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
3
|
+
var _excluded = ["closeIconDescription", "onClose", "theme", "title"];
|
4
|
+
/**
|
5
|
+
* Copyright IBM Corp. 2023, 2024
|
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 portions of React that are needed.
|
12
|
+
import React from 'react';
|
13
|
+
|
14
|
+
// Other standard imports.
|
15
|
+
import PropTypes from 'prop-types';
|
16
|
+
import cx from 'classnames';
|
17
|
+
import { Close, Idea } from '@carbon/icons-react';
|
18
|
+
import { Button } from '@carbon/react';
|
19
|
+
import { useCoachmark } from './utils/context';
|
20
|
+
import { getDevtoolsProps } from '../../global/js/utils/devtools';
|
21
|
+
import { pkg /*, carbon */ } from '../../settings';
|
22
|
+
|
23
|
+
// The block part of our conventional BEM class names (blockClass__E--M).
|
24
|
+
var blockClass = "".concat(pkg.prefix, "--coachmark-tagline");
|
25
|
+
var componentName = 'CoachmarkTagline';
|
26
|
+
var defaults = {
|
27
|
+
closeIconDescription: 'Close',
|
28
|
+
onClose: function onClose() {},
|
29
|
+
theme: 'light'
|
30
|
+
};
|
31
|
+
|
32
|
+
/**
|
33
|
+
* DO NOT USE. This component is for the exclusive use
|
34
|
+
* of other Novice to Pro components.
|
35
|
+
*/
|
36
|
+
export var CoachmarkTagline = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
37
|
+
var _ref$closeIconDescrip = _ref.closeIconDescription,
|
38
|
+
closeIconDescription = _ref$closeIconDescrip === void 0 ? defaults.closeIconDescription : _ref$closeIconDescrip,
|
39
|
+
_ref$onClose = _ref.onClose,
|
40
|
+
onClose = _ref$onClose === void 0 ? defaults.onClose : _ref$onClose,
|
41
|
+
_ref$theme = _ref.theme,
|
42
|
+
theme = _ref$theme === void 0 ? defaults.theme : _ref$theme,
|
43
|
+
title = _ref.title,
|
44
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
45
|
+
var coachmark = useCoachmark();
|
46
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
47
|
+
className: cx(blockClass, "".concat(blockClass, "__").concat(theme), coachmark.isOpen && "".concat(blockClass, "--is-open")),
|
48
|
+
ref: ref
|
49
|
+
}, getDevtoolsProps(componentName)), /*#__PURE__*/React.createElement("button", _extends({
|
50
|
+
// {...rest}
|
51
|
+
className: "".concat(blockClass, "__cta"),
|
52
|
+
type: "button"
|
53
|
+
}, coachmark.buttonProps), /*#__PURE__*/React.createElement("div", {
|
54
|
+
className: "".concat(blockClass, "__idea")
|
55
|
+
}, /*#__PURE__*/React.createElement(Idea, {
|
56
|
+
size: 16
|
57
|
+
})), /*#__PURE__*/React.createElement("div", null, title)), /*#__PURE__*/React.createElement("div", {
|
58
|
+
className: "".concat(blockClass, "--close-btn-container")
|
59
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
60
|
+
kind: "ghost",
|
61
|
+
size: "sm",
|
62
|
+
renderIcon: Close,
|
63
|
+
iconDescription: closeIconDescription,
|
64
|
+
hasIconOnly: true,
|
65
|
+
className: "".concat(blockClass, "--close-btn"),
|
66
|
+
onClick: onClose
|
67
|
+
})));
|
68
|
+
});
|
69
|
+
|
70
|
+
// Return a placeholder if not released and not enabled by feature flag
|
71
|
+
CoachmarkTagline = pkg.checkComponentEnabled(CoachmarkTagline, componentName);
|
72
|
+
|
73
|
+
// The display name of the component, used by React. Note that displayName
|
74
|
+
// is used in preference to relying on function.name.
|
75
|
+
CoachmarkTagline.displayName = componentName;
|
76
|
+
|
77
|
+
// The types and DocGen commentary for the component props,
|
78
|
+
// in alphabetical order (for consistency).
|
79
|
+
// See https://www.npmjs.com/package/prop-types#usage.
|
80
|
+
CoachmarkTagline.propTypes = {
|
81
|
+
/**
|
82
|
+
* Tooltip text and aria label for the Close button icon.
|
83
|
+
*/
|
84
|
+
closeIconDescription: PropTypes.string,
|
85
|
+
/**
|
86
|
+
* Function to call when the close button is clicked.
|
87
|
+
*/
|
88
|
+
onClose: PropTypes.func,
|
89
|
+
/**
|
90
|
+
* Determines the theme of the component.
|
91
|
+
*/
|
92
|
+
theme: PropTypes.oneOf(['light', 'dark']),
|
93
|
+
/**
|
94
|
+
* The title of the tagline.
|
95
|
+
*/
|
96
|
+
title: PropTypes.string.isRequired
|
97
|
+
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright IBM Corp. 2023, 2024
|
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 { Coachmark } from './Coachmark';
|
9
|
+
export { BEACON_KIND, COACHMARK_OVERLAY_KIND, COACHMARK_ALIGNMENT } from './utils/enums';
|
10
|
+
export { useCoachmark } from './utils/context';
|
@@ -0,0 +1,76 @@
|
|
1
|
+
import { COACHMARK_ALIGNMENT, COACHMARK_OVERLAY_KIND } from './enums';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* If the coachmark's target is a link, button, etc. (i.e. not a beacon),
|
5
|
+
* this adjusts the coachmark's position based on the position and size of the target.
|
6
|
+
* @param {object} coachmark target reference
|
7
|
+
* @param {string} kind type of coachmark
|
8
|
+
* @returns {object} {top:number, left:number}
|
9
|
+
*/
|
10
|
+
|
11
|
+
export var getOffsetTune = function getOffsetTune(coachmark, kind) {
|
12
|
+
// for future reference
|
13
|
+
// const coachmarkTarget = {
|
14
|
+
// x: coachmark.targetOffset.x,
|
15
|
+
// y: coachmark.targetOffset.y,
|
16
|
+
// width: coachmark.targetRect.width,
|
17
|
+
// height: coachmark.targetRect.height,
|
18
|
+
// };
|
19
|
+
|
20
|
+
var _coachmark$targetRect = coachmark.targetRect,
|
21
|
+
width = _coachmark$targetRect.width,
|
22
|
+
height = _coachmark$targetRect.height;
|
23
|
+
var distanceOffset = 24; // see also _coachmark-overlay.scss > $distance-offset
|
24
|
+
var top = 0;
|
25
|
+
var left = 0;
|
26
|
+
if (kind !== COACHMARK_OVERLAY_KIND.TOOLTIP) {
|
27
|
+
switch (coachmark.align) {
|
28
|
+
case COACHMARK_ALIGNMENT.TOP:
|
29
|
+
left = width / 2;
|
30
|
+
break;
|
31
|
+
case COACHMARK_ALIGNMENT.TOP_LEFT:
|
32
|
+
left = distanceOffset;
|
33
|
+
break;
|
34
|
+
case COACHMARK_ALIGNMENT.TOP_RIGHT:
|
35
|
+
left = width - distanceOffset;
|
36
|
+
break;
|
37
|
+
case COACHMARK_ALIGNMENT.BOTTOM:
|
38
|
+
top = height;
|
39
|
+
left = width / 2;
|
40
|
+
break;
|
41
|
+
case COACHMARK_ALIGNMENT.BOTTOM_LEFT:
|
42
|
+
top = height;
|
43
|
+
left = distanceOffset;
|
44
|
+
break;
|
45
|
+
case COACHMARK_ALIGNMENT.BOTTOM_RIGHT:
|
46
|
+
top = height;
|
47
|
+
left = width - distanceOffset;
|
48
|
+
break;
|
49
|
+
case COACHMARK_ALIGNMENT.LEFT:
|
50
|
+
top = height / 2;
|
51
|
+
break;
|
52
|
+
case COACHMARK_ALIGNMENT.LEFT_TOP:
|
53
|
+
top = distanceOffset;
|
54
|
+
break;
|
55
|
+
case COACHMARK_ALIGNMENT.LEFT_BOTTOM:
|
56
|
+
top = height - distanceOffset;
|
57
|
+
break;
|
58
|
+
case COACHMARK_ALIGNMENT.RIGHT:
|
59
|
+
top = height / 2;
|
60
|
+
left = width;
|
61
|
+
break;
|
62
|
+
case COACHMARK_ALIGNMENT.RIGHT_TOP:
|
63
|
+
top = distanceOffset;
|
64
|
+
left = width;
|
65
|
+
break;
|
66
|
+
case COACHMARK_ALIGNMENT.RIGHT_BOTTOM:
|
67
|
+
top = height - distanceOffset;
|
68
|
+
left = width;
|
69
|
+
break;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
return {
|
73
|
+
top: top,
|
74
|
+
left: left
|
75
|
+
};
|
76
|
+
};
|
@@ -0,0 +1,40 @@
|
|
1
|
+
/* eslint-disable max-len */
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Reserved for future expansion, i.e. "RING".
|
5
|
+
*/
|
6
|
+
export var BEACON_KIND = {
|
7
|
+
DEFAULT: 'default'
|
8
|
+
};
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Describes the style and behavior of a Coachmark.
|
12
|
+
* @param TOOLTIP includes a caret pointing to the animated beacon.
|
13
|
+
* @param FLOATING includes a drag handle across the top.
|
14
|
+
* @param FIXED is fixed to the bottom-right of the viewport.
|
15
|
+
* @param STACKED is fixed to the bottom-right of the viewport, includes links to show more, stackable Coachmarks if included.
|
16
|
+
*/
|
17
|
+
export var COACHMARK_OVERLAY_KIND = {
|
18
|
+
TOOLTIP: 'tooltip',
|
19
|
+
FLOATING: 'floating',
|
20
|
+
FIXED: 'fixed',
|
21
|
+
STACKED: 'stacked'
|
22
|
+
};
|
23
|
+
/**
|
24
|
+
* Where to render the Coachmark relative to its target.
|
25
|
+
* Applies only to Floating and Tooltip Coachmarks.
|
26
|
+
*/
|
27
|
+
export var COACHMARK_ALIGNMENT = {
|
28
|
+
BOTTOM: 'bottom',
|
29
|
+
BOTTOM_LEFT: 'bottom-left',
|
30
|
+
BOTTOM_RIGHT: 'bottom-right',
|
31
|
+
LEFT: 'left',
|
32
|
+
LEFT_TOP: 'left-top',
|
33
|
+
LEFT_BOTTOM: 'left-bottom',
|
34
|
+
RIGHT: 'right',
|
35
|
+
RIGHT_TOP: 'right-top',
|
36
|
+
RIGHT_BOTTOM: 'right-bottom',
|
37
|
+
TOP: 'top',
|
38
|
+
TOP_LEFT: 'top-left',
|
39
|
+
TOP_RIGHT: 'top-right'
|
40
|
+
};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
/* eslint-disable max-len */
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Clamp the given value between the upper bound `max` and the lower bound `min`
|
5
|
+
* @param {number} max
|
6
|
+
* @param {number} min
|
7
|
+
* @param {number} value
|
8
|
+
*/
|
9
|
+
export function clamp(max, min, value) {
|
10
|
+
return Math.min(max, Math.max(min, value));
|
11
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import { useEffect, useRef, useLayoutEffect } from 'react';
|
2
|
+
import { COACHMARK_OVERLAY_KIND } from './enums';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Detects when a user clicks outside of the element
|
6
|
+
* @param {object} coachmarkRef - The ref to the React element for the Coachmark to detect when the user clicks outside of its bounds.
|
7
|
+
* @param {object} overlayRef - The ref to the React element for the CoachmarkOverlay to detect when the user clicks outside of its bounds.
|
8
|
+
* @param {string} overlayKind - The overlayKind prop from the Coachmark. @see COACHMARK_OVERLAY_KIND
|
9
|
+
* @param {Function} callback The callback to call when the user mouses down.
|
10
|
+
*/
|
11
|
+
|
12
|
+
function useClickOutsideElement(coachmarkRef, overlayRef, overlayKind, callback) {
|
13
|
+
var cb = useRef();
|
14
|
+
var isTooltip = overlayKind === COACHMARK_OVERLAY_KIND.TOOLTIP;
|
15
|
+
useLayoutEffect(function () {
|
16
|
+
cb.current = callback;
|
17
|
+
}, [callback]);
|
18
|
+
useEffect(function () {
|
19
|
+
function handleClickOutside(event) {
|
20
|
+
var isOverlayOutside = overlayRef.current && !overlayRef.current.contains(event.target);
|
21
|
+
var isOutsideCoachmark = coachmarkRef.current && !coachmarkRef.current.contains(event.target);
|
22
|
+
if (isOverlayOutside && isOutsideCoachmark) {
|
23
|
+
callCallback();
|
24
|
+
}
|
25
|
+
}
|
26
|
+
function callCallback() {
|
27
|
+
if (isTooltip) {
|
28
|
+
cb.current();
|
29
|
+
}
|
30
|
+
}
|
31
|
+
document.addEventListener('mousedown', handleClickOutside);
|
32
|
+
return function () {
|
33
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
34
|
+
};
|
35
|
+
}, [coachmarkRef, overlayRef, isTooltip]);
|
36
|
+
}
|
37
|
+
var useWindowEvent = function useWindowEvent(eventName, callback) {
|
38
|
+
var savedCallback = useRef(null);
|
39
|
+
useEffect(function () {
|
40
|
+
savedCallback.current = callback;
|
41
|
+
});
|
42
|
+
useEffect(function () {
|
43
|
+
function handler(event) {
|
44
|
+
if (savedCallback.current) {
|
45
|
+
savedCallback.current(event);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
window.addEventListener(eventName, handler);
|
49
|
+
return function () {
|
50
|
+
window.removeEventListener(eventName, handler);
|
51
|
+
};
|
52
|
+
}, [eventName]);
|
53
|
+
};
|
54
|
+
export { useClickOutsideElement, useWindowEvent };
|
@@ -0,0 +1,93 @@
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
3
|
+
var _excluded = ["label", "className", "kind"];
|
4
|
+
/**
|
5
|
+
* Copyright IBM Corp. 2023, 2024
|
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 portions of React that are needed.
|
12
|
+
import React from 'react';
|
13
|
+
|
14
|
+
// Other standard imports.
|
15
|
+
import PropTypes from 'prop-types';
|
16
|
+
import cx from 'classnames';
|
17
|
+
import { useCoachmark } from '../Coachmark';
|
18
|
+
import { getDevtoolsProps } from '../../global/js/utils/devtools';
|
19
|
+
import { pkg /*, carbon */ } from '../../settings';
|
20
|
+
|
21
|
+
// The block part of our conventional BEM class names (blockClass__E--M).
|
22
|
+
var blockClass = "".concat(pkg.prefix, "--coachmark-beacon");
|
23
|
+
var componentName = 'CoachmarkBeacon';
|
24
|
+
var defaults = {
|
25
|
+
kind: 'default'
|
26
|
+
};
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Use beacon for the target prop of a Coachmark component.
|
30
|
+
*/
|
31
|
+
export var CoachmarkBeacon = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
32
|
+
var _coachmark$positionTu, _coachmark$positionTu2, _coachmark$positionTu3, _coachmark$positionTu4;
|
33
|
+
var label = _ref.label,
|
34
|
+
className = _ref.className,
|
35
|
+
_ref$kind = _ref.kind,
|
36
|
+
kind = _ref$kind === void 0 ? defaults.kind : _ref$kind,
|
37
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
38
|
+
var coachmark = useCoachmark();
|
39
|
+
if (!coachmark) {
|
40
|
+
return /*#__PURE__*/React.createElement("div", null, "CoachmarkBeacon is to be use exclusively within the target prop of Coachmark");
|
41
|
+
}
|
42
|
+
var overlayPositionStyle = {
|
43
|
+
top: (_coachmark$positionTu = (_coachmark$positionTu2 = coachmark.positionTune) === null || _coachmark$positionTu2 === void 0 ? void 0 : _coachmark$positionTu2.y) !== null && _coachmark$positionTu !== void 0 ? _coachmark$positionTu : 0,
|
44
|
+
left: (_coachmark$positionTu3 = (_coachmark$positionTu4 = coachmark.positionTune) === null || _coachmark$positionTu4 === void 0 ? void 0 : _coachmark$positionTu4.x) !== null && _coachmark$positionTu3 !== void 0 ? _coachmark$positionTu3 : 0
|
45
|
+
};
|
46
|
+
return /*#__PURE__*/React.createElement("span", _extends({}, rest, {
|
47
|
+
className: cx(blockClass, "".concat(blockClass, "-").concat(kind), className),
|
48
|
+
ref: ref,
|
49
|
+
style: overlayPositionStyle
|
50
|
+
}, getDevtoolsProps(componentName), {
|
51
|
+
role: "tooltip"
|
52
|
+
}), /*#__PURE__*/React.createElement("button", _extends({
|
53
|
+
tabIndex: 0,
|
54
|
+
type: "button"
|
55
|
+
}, coachmark.buttonProps, {
|
56
|
+
"aria-label": label,
|
57
|
+
className: "".concat(blockClass, "__target")
|
58
|
+
}), /*#__PURE__*/React.createElement("svg", {
|
59
|
+
className: "".concat(blockClass, "__center"),
|
60
|
+
alt: ""
|
61
|
+
}, /*#__PURE__*/React.createElement("circle", {
|
62
|
+
r: 1,
|
63
|
+
cx: 38,
|
64
|
+
cy: 38
|
65
|
+
}))));
|
66
|
+
});
|
67
|
+
|
68
|
+
// Return a placeholder if not released and not enabled by feature flag
|
69
|
+
CoachmarkBeacon = pkg.checkComponentEnabled(CoachmarkBeacon, componentName);
|
70
|
+
|
71
|
+
// The display name of the component, used by React. Note that displayName
|
72
|
+
// is used in preference to relying on function.name.
|
73
|
+
CoachmarkBeacon.displayName = componentName;
|
74
|
+
|
75
|
+
// The types and DocGen commentary for the component props,
|
76
|
+
// in alphabetical order (for consistency).
|
77
|
+
// See https://www.npmjs.com/package/prop-types#usage.
|
78
|
+
CoachmarkBeacon.propTypes = {
|
79
|
+
/**
|
80
|
+
* Optional class name for this component.
|
81
|
+
*/
|
82
|
+
className: PropTypes.string,
|
83
|
+
/**
|
84
|
+
* What style of beacon.
|
85
|
+
* BEACON_KIND is an exported enum from the Coachmark and can be used for this value.
|
86
|
+
* @see {@link BEACON_KIND}
|
87
|
+
*/
|
88
|
+
kind: PropTypes.oneOf(['default']),
|
89
|
+
/**
|
90
|
+
* The aria label.
|
91
|
+
*/
|
92
|
+
label: PropTypes.string.isRequired
|
93
|
+
};
|