@carbon/ibm-products 1.55.2 → 1.56.0
Sign up to get free protection for your applications and to get access to all the features.
- package/css/index-full-carbon.css +579 -0
- 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.css +579 -0
- 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 +579 -0
- 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.js +15 -5
- package/es/components/Coachmark/Coachmark.js +243 -0
- package/es/components/Coachmark/CoachmarkDragbar.js +137 -0
- package/es/components/Coachmark/CoachmarkHeader.js +88 -0
- package/es/components/Coachmark/CoachmarkOverlay.js +139 -0
- package/es/components/Coachmark/CoachmarkTagline.js +93 -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 +90 -0
- package/es/components/CoachmarkBeacon/index.js +8 -0
- package/es/components/CoachmarkButton/CoachmarkButton.js +72 -0
- package/es/components/CoachmarkButton/index.js +8 -0
- package/es/components/CoachmarkFixed/CoachmarkFixed.js +201 -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 +175 -0
- package/es/components/CoachmarkOverlayElements/index.js +8 -0
- package/es/components/CoachmarkStack/CoachmarkStack.js +260 -0
- package/es/components/CoachmarkStack/CoachmarkStackHome.js +157 -0
- package/es/components/CoachmarkStack/index.js +8 -0
- package/es/components/NotificationsPanel/NotificationsPanel.js +3 -2
- package/es/components/index.js +7 -0
- package/es/global/js/package-settings.js +8 -1
- package/lib/components/Carousel/Carousel.js +15 -5
- package/lib/components/Coachmark/Coachmark.js +247 -0
- package/lib/components/Coachmark/CoachmarkDragbar.js +137 -0
- package/lib/components/Coachmark/CoachmarkHeader.js +85 -0
- package/lib/components/Coachmark/CoachmarkOverlay.js +139 -0
- package/lib/components/Coachmark/CoachmarkTagline.js +90 -0
- package/lib/components/Coachmark/index.js +38 -0
- package/lib/components/Coachmark/utils/constants.js +82 -0
- package/lib/components/Coachmark/utils/context.js +13 -0
- package/lib/components/Coachmark/utils/enums.js +49 -0
- package/lib/components/Coachmark/utils/helpers.js +17 -0
- package/lib/components/Coachmark/utils/hooks.js +60 -0
- package/lib/components/CoachmarkBeacon/CoachmarkBeacon.js +87 -0
- package/lib/components/CoachmarkBeacon/index.js +12 -0
- package/lib/components/CoachmarkButton/CoachmarkButton.js +69 -0
- package/lib/components/CoachmarkButton/index.js +12 -0
- package/lib/components/CoachmarkFixed/CoachmarkFixed.js +201 -0
- package/lib/components/CoachmarkFixed/index.js +12 -0
- package/lib/components/CoachmarkOverlayElement/CoachmarkOverlayElement.js +83 -0
- package/lib/components/CoachmarkOverlayElement/index.js +12 -0
- package/lib/components/CoachmarkOverlayElements/CoachmarkOverlayElements.js +176 -0
- package/lib/components/CoachmarkOverlayElements/index.js +12 -0
- package/lib/components/CoachmarkStack/CoachmarkStack.js +264 -0
- package/lib/components/CoachmarkStack/CoachmarkStackHome.js +160 -0
- package/lib/components/CoachmarkStack/index.js +12 -0
- package/lib/components/NotificationsPanel/NotificationsPanel.js +3 -2
- package/lib/components/index.js +49 -0
- package/lib/global/js/package-settings.js +8 -1
- package/package.json +2 -2
- package/scss/components/Carousel/_carousel.scss +3 -0
- package/scss/components/Coachmark/_index.scss +11 -0
- package/scss/components/Coachmark/_storybook-styles.scss +20 -0
- package/scss/components/Coachmark/styles/_coachmark-dragbar.scss +74 -0
- package/scss/components/Coachmark/styles/_coachmark-header.scss +58 -0
- package/scss/components/Coachmark/styles/_coachmark-overlay.scss +327 -0
- package/scss/components/Coachmark/styles/_coachmark-tagline.scss +118 -0
- package/scss/components/CoachmarkBeacon/_coachmark-beacon.scss +166 -0
- package/scss/components/CoachmarkBeacon/_index.scss +8 -0
- package/scss/components/CoachmarkBeacon/_storybook-styles.scss +19 -0
- package/scss/components/CoachmarkButton/_coachmark-button.scss +34 -0
- package/scss/components/CoachmarkButton/_index.scss +8 -0
- package/scss/components/CoachmarkButton/_storybook-styles.scss +19 -0
- package/scss/components/CoachmarkFixed/_coachmark-fixed.scss +34 -0
- package/scss/components/CoachmarkFixed/_index.scss +8 -0
- package/scss/components/CoachmarkFixed/_storybook-styles.scss +10 -0
- package/scss/components/CoachmarkOverlayElement/_coachmark-overlay-element.scss +50 -0
- package/scss/components/CoachmarkOverlayElement/_index.scss +8 -0
- package/scss/components/CoachmarkOverlayElement/_storybook-styles.scss +19 -0
- package/scss/components/CoachmarkOverlayElements/_coachmark-overlay-elements.scss +40 -0
- package/scss/components/CoachmarkOverlayElements/_index.scss +8 -0
- package/scss/components/CoachmarkOverlayElements/_storybook-styles.scss +19 -0
- package/scss/components/CoachmarkStack/_coachmark-stack.scss +85 -0
- package/scss/components/CoachmarkStack/_index.scss +8 -0
- package/scss/components/CoachmarkStack/_storybook-styles.scss +10 -0
- package/scss/components/_index.scss +7 -1
@@ -0,0 +1,157 @@
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
3
|
+
var _excluded = ["className", "description", "media", "navLinkLabels", "onClickNavItem", "onClose", "portalTarget", "closeButtonLabel", "title"];
|
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, { forwardRef } from 'react';
|
12
|
+
import pconsole from '../../global/js/utils/pconsole';
|
13
|
+
import PropTypes from 'prop-types';
|
14
|
+
import cx from 'classnames';
|
15
|
+
import { Idea20 } from '@carbon/icons-react';
|
16
|
+
import { Button } from 'carbon-components-react';
|
17
|
+
import { getDevtoolsProps } from '../../global/js/utils/devtools';
|
18
|
+
import { pkg /*, carbon */ } from '../../settings';
|
19
|
+
import { createPortal } from 'react-dom';
|
20
|
+
import { CoachmarkHeader } from '../Coachmark/CoachmarkHeader';
|
21
|
+
import { SteppedAnimatedMedia } from '../SteppedAnimatedMedia';
|
22
|
+
|
23
|
+
// Carbon and package components we use.
|
24
|
+
/* TODO: @import(s) of carbon components and other package components. */
|
25
|
+
|
26
|
+
// The block part of our conventional BEM class names (blockClass__E--M).
|
27
|
+
var blockClass = "".concat(pkg.prefix, "--coachmark-stacked-home");
|
28
|
+
var overlayClass = "".concat(pkg.prefix, "--coachmark-overlay");
|
29
|
+
var componentName = 'CoachmarkStackHome';
|
30
|
+
|
31
|
+
/**
|
32
|
+
* DO NOT USE. This component is for the exclusive use
|
33
|
+
* of other Novice to Pro components.
|
34
|
+
*/
|
35
|
+
export var CoachmarkStackHome = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
36
|
+
var _document$querySelect;
|
37
|
+
var className = _ref.className,
|
38
|
+
description = _ref.description,
|
39
|
+
media = _ref.media,
|
40
|
+
navLinkLabels = _ref.navLinkLabels,
|
41
|
+
onClickNavItem = _ref.onClickNavItem,
|
42
|
+
onClose = _ref.onClose,
|
43
|
+
portalTarget = _ref.portalTarget,
|
44
|
+
closeButtonLabel = _ref.closeButtonLabel,
|
45
|
+
title = _ref.title,
|
46
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
47
|
+
if (!navLinkLabels) {
|
48
|
+
return pconsole.warn("".concat(componentName, " is a Novice to Pro internal component and is not intended for general use."));
|
49
|
+
}
|
50
|
+
var portalNode = portalTarget ? (_document$querySelect = document.querySelector(portalTarget)) !== null && _document$querySelect !== void 0 ? _document$querySelect : document.querySelector('body') : document.querySelector('body');
|
51
|
+
return /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
52
|
+
className: cx(blockClass, className),
|
53
|
+
ref: ref,
|
54
|
+
role: "main"
|
55
|
+
}, getDevtoolsProps(componentName)), /*#__PURE__*/React.createElement(CoachmarkHeader, {
|
56
|
+
onClose: onClose
|
57
|
+
}), /*#__PURE__*/React.createElement("div", {
|
58
|
+
className: "".concat(overlayClass, "__body")
|
59
|
+
}, /*#__PURE__*/React.createElement("div", {
|
60
|
+
className: "".concat(overlayClass, "-element")
|
61
|
+
}, !media && /*#__PURE__*/React.createElement(Idea20, {
|
62
|
+
className: "".concat(blockClass, "__icon-idea")
|
63
|
+
}), media && (media.render ? media.render() : /*#__PURE__*/React.createElement(SteppedAnimatedMedia, {
|
64
|
+
className: "".concat(overlayClass, "__element-stepped-media"),
|
65
|
+
filePaths: media.filePaths,
|
66
|
+
playStep: 0
|
67
|
+
})), /*#__PURE__*/React.createElement("div", {
|
68
|
+
className: "".concat(overlayClass, "-element__content")
|
69
|
+
}, title && /*#__PURE__*/React.createElement("h2", {
|
70
|
+
className: "".concat(overlayClass, "-element__title")
|
71
|
+
}, title), description && /*#__PURE__*/React.createElement("p", {
|
72
|
+
className: "".concat(overlayClass, "-element__body")
|
73
|
+
}, description)), /*#__PURE__*/React.createElement("ul", {
|
74
|
+
className: "".concat(blockClass, "__nav-links")
|
75
|
+
}, navLinkLabels.map(function (label, index) {
|
76
|
+
return /*#__PURE__*/React.createElement("li", {
|
77
|
+
key: index
|
78
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
79
|
+
kind: "ghost",
|
80
|
+
size: "sm",
|
81
|
+
onClick: function onClick() {
|
82
|
+
onClickNavItem(index + 1);
|
83
|
+
}
|
84
|
+
}, label));
|
85
|
+
})), closeButtonLabel && /*#__PURE__*/React.createElement("div", {
|
86
|
+
className: "".concat(overlayClass, "__footer")
|
87
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
88
|
+
size: "sm",
|
89
|
+
onClick: onClose
|
90
|
+
}, closeButtonLabel))))), portalNode);
|
91
|
+
});
|
92
|
+
|
93
|
+
// Return a placeholder if not released and not enabled by feature flag
|
94
|
+
CoachmarkStackHome = pkg.checkComponentEnabled(CoachmarkStackHome, componentName);
|
95
|
+
|
96
|
+
// The display name of the component, used by React. Note that displayName
|
97
|
+
// is used in preference to relying on function.name.
|
98
|
+
CoachmarkStackHome.displayName = componentName;
|
99
|
+
|
100
|
+
// The types and DocGen commentary for the component props,
|
101
|
+
// in alphabetical order (for consistency).
|
102
|
+
// See https://www.npmjs.com/package/prop-types#usage.
|
103
|
+
CoachmarkStackHome.propTypes = {
|
104
|
+
/**
|
105
|
+
* Optional class name for this component.
|
106
|
+
*/
|
107
|
+
className: PropTypes.string,
|
108
|
+
/**
|
109
|
+
* The label for the button that will close the stack
|
110
|
+
*/
|
111
|
+
closeButtonLabel: PropTypes.string,
|
112
|
+
/**
|
113
|
+
* The description of the Coachmark.
|
114
|
+
*/
|
115
|
+
description: PropTypes.node.isRequired,
|
116
|
+
/**
|
117
|
+
* The object describing an image in one of two shapes.
|
118
|
+
*
|
119
|
+
* If a single media element is required, use `{render}`.
|
120
|
+
*
|
121
|
+
* If a stepped animation is required, use `{filePaths}`.
|
122
|
+
*
|
123
|
+
* @see {@link MEDIA_PROP_TYPE}.
|
124
|
+
*/
|
125
|
+
media: PropTypes.oneOfType([PropTypes.shape({
|
126
|
+
render: PropTypes.func
|
127
|
+
}), PropTypes.shape({
|
128
|
+
filePaths: PropTypes.arrayOf(PropTypes.string)
|
129
|
+
})]),
|
130
|
+
/**
|
131
|
+
* The labels used to link to the stackable Coachmarks.
|
132
|
+
*/
|
133
|
+
navLinkLabels: PropTypes.arrayOf(PropTypes.string).isRequired,
|
134
|
+
/**
|
135
|
+
* For internal use only by CoachmarkStack and CoachmarkStackHome.
|
136
|
+
*/
|
137
|
+
onClickNavItem: PropTypes.func.isRequired,
|
138
|
+
/**
|
139
|
+
* Function to call when the stack closes.
|
140
|
+
*/
|
141
|
+
onClose: PropTypes.func.isRequired,
|
142
|
+
/**
|
143
|
+
* By default, the CoachmarkStackHome will be appended to the end of `document.body`.
|
144
|
+
* The CoachmarkStackHome will remain persistent as the user navigates the app until
|
145
|
+
* the user closes the CoachmarkStackHome.
|
146
|
+
*
|
147
|
+
* Alternatively, the app developer can tightly couple the CoachmarkStackHome to a DOM
|
148
|
+
* element or other component by specifying a CSS selector. The CoachmarkStackHome will
|
149
|
+
* remain visible as long as that element remains visible or mounted. When the
|
150
|
+
* element is hidden or component is unmounted, the CoachmarkStackHome will disappear.
|
151
|
+
*/
|
152
|
+
portalTarget: PropTypes.string,
|
153
|
+
/**
|
154
|
+
* The title of the Coachmark.
|
155
|
+
*/
|
156
|
+
title: PropTypes.string.isRequired
|
157
|
+
};
|
@@ -20,6 +20,7 @@ import { getDevtoolsProps } from '../../global/js/utils/devtools';
|
|
20
20
|
import { useClickOutside } from '../../global/js/hooks';
|
21
21
|
import { pkg } from '../../settings';
|
22
22
|
import { timeAgo } from './utils';
|
23
|
+
import { prepareProps } from '../../global/js/utils/props-helper';
|
23
24
|
import { NotificationsEmptyState } from '../EmptyStates/NotificationsEmptyState';
|
24
25
|
|
25
26
|
// Carbon and package components we use.
|
@@ -289,10 +290,10 @@ export var NotificationsPanel = /*#__PURE__*/React.forwardRef(function (_ref, re
|
|
289
290
|
nowText: nowText
|
290
291
|
})), /*#__PURE__*/React.createElement("h6", {
|
291
292
|
className: notificationHeaderClassName
|
292
|
-
}, notification.title), notification.description && notification.description.length && renderDescription(notification.id), notification.link && notification.link.text && notification.link.url && /*#__PURE__*/React.createElement(Link, {
|
293
|
+
}, notification.title), notification.description && notification.description.length && renderDescription(notification.id), notification.link && notification.link.text && notification.link.url && /*#__PURE__*/React.createElement(Link, _extends({
|
293
294
|
href: notification.link.url,
|
294
295
|
className: "".concat(blockClass, "__notifications-link")
|
295
|
-
}, notification.link.text)), /*#__PURE__*/React.createElement(Button, {
|
296
|
+
}, prepareProps({}, notification.link, ['text', 'url'])), notification.link.text)), /*#__PURE__*/React.createElement(Button, {
|
296
297
|
kind: "ghost",
|
297
298
|
size: "small",
|
298
299
|
renderIcon: Close16,
|
package/es/components/index.js
CHANGED
@@ -46,4 +46,11 @@ export { InlineEdit } from './InlineEdit';
|
|
46
46
|
export { EditInPlace } from './EditInPlace';
|
47
47
|
export { Guidebanner } from './Guidebanner';
|
48
48
|
export { NonLinearReading } from './NonLinearReading';
|
49
|
+
export { Coachmark } from './Coachmark';
|
50
|
+
export { CoachmarkFixed } from './CoachmarkFixed';
|
51
|
+
export { CoachmarkBeacon } from './CoachmarkBeacon';
|
52
|
+
export { CoachmarkButton } from './CoachmarkButton';
|
53
|
+
export { CoachmarkOverlayElements } from './CoachmarkOverlayElements';
|
54
|
+
export { CoachmarkOverlayElement } from './CoachmarkOverlayElement';
|
55
|
+
export { CoachmarkStack } from './CoachmarkStack';
|
49
56
|
export { InlineTip } from './InlineTip';
|
@@ -74,7 +74,14 @@ var defaults = {
|
|
74
74
|
// Novice to pro components not yet reviewed and released:
|
75
75
|
InlineTip: false,
|
76
76
|
Guidebanner: false,
|
77
|
-
NonLinearReading: false
|
77
|
+
NonLinearReading: false,
|
78
|
+
Coachmark: false,
|
79
|
+
CoachmarkBeacon: false,
|
80
|
+
CoachmarkButton: false,
|
81
|
+
CoachmarkFixed: false,
|
82
|
+
CoachmarkOverlayElement: false,
|
83
|
+
CoachmarkOverlayElements: false,
|
84
|
+
CoachmarkStack: false
|
78
85
|
/* new component flags here - comment used by generate CLI */
|
79
86
|
},
|
80
87
|
|
@@ -59,6 +59,7 @@ var Carousel = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
59
59
|
var currentViewIDRef = (0, _react.useRef)(currentViewID);
|
60
60
|
var scrollRef = (0, _react.useRef)();
|
61
61
|
var carouselRef = (0, _react.useRef)();
|
62
|
+
var mountedRef = (0, _react.useRef)(true);
|
62
63
|
var isScrollable = (0, _utils.useIsOverflow)(scrollRef);
|
63
64
|
// Scrolling has no complete callback, nor does it return a promise.
|
64
65
|
// Since there is no way to tell when a scroll is finished we can set a timeout.
|
@@ -73,7 +74,7 @@ var Carousel = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
73
74
|
return scrollToView(currentViewID - 1);
|
74
75
|
}, [currentViewID, scrollToView]);
|
75
76
|
var scrollToView = (0, _react.useCallback)(function (viewID) {
|
76
|
-
if (!isScrolling) {
|
77
|
+
if (!isScrolling && scrollRef.current && mountedRef.current) {
|
77
78
|
var _scrollRef$current;
|
78
79
|
var targetViewID = (0, _lodash.clamp)(viewID, 0, totalViews - 1);
|
79
80
|
setCurrentViewID(targetViewID);
|
@@ -93,9 +94,11 @@ var Carousel = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
93
94
|
});
|
94
95
|
}, [resolveScroll]);
|
95
96
|
var resolveScroll = (0, _react.useCallback)(function (resolve) {
|
96
|
-
|
97
|
-
|
98
|
-
|
97
|
+
if (mountedRef.current) {
|
98
|
+
setIsScrolling(false);
|
99
|
+
var percentage = scrollPosition() / maxScroll();
|
100
|
+
return resolve(parseFloat(percentage.toFixed(2)));
|
101
|
+
}
|
99
102
|
}, []);
|
100
103
|
var scrollPosition = function scrollPosition() {
|
101
104
|
var _scrollRef$current2;
|
@@ -119,8 +122,10 @@ var Carousel = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
119
122
|
|
120
123
|
// EFFECTS
|
121
124
|
(0, _utils.useWindowEvent)('resize', handleResize);
|
125
|
+
// SAVE POINT
|
126
|
+
|
122
127
|
(0, _react.useEffect)(function () {
|
123
|
-
if (scrollableChange) {
|
128
|
+
if (scrollableChange && mountedRef.current) {
|
124
129
|
scrollableChange(isScrollable);
|
125
130
|
}
|
126
131
|
}, [isScrollable, scrollableChange]);
|
@@ -160,6 +165,11 @@ var Carousel = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
160
165
|
};
|
161
166
|
}
|
162
167
|
}, [disableArrowScroll]);
|
168
|
+
(0, _react.useEffect)(function () {
|
169
|
+
return function () {
|
170
|
+
mountedRef.current = false;
|
171
|
+
};
|
172
|
+
}, []);
|
163
173
|
(0, _react.useImperativeHandle)(ref, function () {
|
164
174
|
return {
|
165
175
|
scrollNext: scrollNext,
|
@@ -0,0 +1,247 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.Coachmark = void 0;
|
9
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
11
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
13
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
14
|
+
var _propTypes = _interopRequireWildcard(require("prop-types"));
|
15
|
+
var _reactDom = require("react-dom");
|
16
|
+
var _CoachmarkOverlay = require("./CoachmarkOverlay");
|
17
|
+
var _context = require("./utils/context");
|
18
|
+
var _enums = require("./utils/enums");
|
19
|
+
var _hooks = require("./utils/hooks");
|
20
|
+
var _devtools = require("../../global/js/utils/devtools");
|
21
|
+
var _settings = require("../../settings");
|
22
|
+
var _lodash = require("lodash");
|
23
|
+
var _excluded = ["align", "children", "className", "onClose", "overlayClassName", "overlayKind", "overlayRef", "portalTarget", "positionTune", "target", "theme"];
|
24
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
25
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
26
|
+
// The block part of our conventional BEM class names (blockClass__E--M).
|
27
|
+
var blockClass = "".concat(_settings.pkg.prefix, "--coachmark");
|
28
|
+
var componentName = 'Coachmark';
|
29
|
+
var defaults = {
|
30
|
+
align: 'bottom',
|
31
|
+
onClose: function onClose() {},
|
32
|
+
overlayKind: 'tooltip',
|
33
|
+
theme: 'light'
|
34
|
+
};
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Coachmarks are used to call out specific functionality or concepts
|
38
|
+
* within the UI that may not be intuitive but are important for the
|
39
|
+
* user to gain understanding of the product's main value and discover new use cases.
|
40
|
+
*/
|
41
|
+
|
42
|
+
var Coachmark = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
43
|
+
var _document$querySelect;
|
44
|
+
var _ref$align = _ref.align,
|
45
|
+
align = _ref$align === void 0 ? defaults.align : _ref$align,
|
46
|
+
children = _ref.children,
|
47
|
+
className = _ref.className,
|
48
|
+
_ref$onClose = _ref.onClose,
|
49
|
+
onClose = _ref$onClose === void 0 ? defaults.onClose : _ref$onClose,
|
50
|
+
overlayClassName = _ref.overlayClassName,
|
51
|
+
_ref$overlayKind = _ref.overlayKind,
|
52
|
+
overlayKind = _ref$overlayKind === void 0 ? defaults.overlayKind : _ref$overlayKind,
|
53
|
+
overlayRef = _ref.overlayRef,
|
54
|
+
portalTarget = _ref.portalTarget,
|
55
|
+
positionTune = _ref.positionTune,
|
56
|
+
target = _ref.target,
|
57
|
+
_ref$theme = _ref.theme,
|
58
|
+
theme = _ref$theme === void 0 ? defaults.theme : _ref$theme,
|
59
|
+
rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
60
|
+
var isBeacon = overlayKind === _enums.COACHMARK_OVERLAY_KIND.TOOLTIP;
|
61
|
+
var isStacked = overlayKind === _enums.COACHMARK_OVERLAY_KIND.STACKED;
|
62
|
+
var portalNode = portalTarget ? (_document$querySelect = document.querySelector(portalTarget)) !== null && _document$querySelect !== void 0 ? _document$querySelect : document.querySelector('body') : document.querySelector('body');
|
63
|
+
var _useState = (0, _react.useState)(isStacked),
|
64
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
65
|
+
isOpen = _useState2[0],
|
66
|
+
setIsOpen = _useState2[1];
|
67
|
+
var _useState3 = (0, _react.useState)(false),
|
68
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
69
|
+
shouldResetPosition = _useState4[0],
|
70
|
+
setShouldResetPosition = _useState4[1];
|
71
|
+
var _useState5 = (0, _react.useState)(),
|
72
|
+
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
73
|
+
targetRect = _useState6[0],
|
74
|
+
setTargetRect = _useState6[1];
|
75
|
+
var _useState7 = (0, _react.useState)({
|
76
|
+
x: 0,
|
77
|
+
y: 0
|
78
|
+
}),
|
79
|
+
_useState8 = (0, _slicedToArray2.default)(_useState7, 2),
|
80
|
+
targetOffset = _useState8[0],
|
81
|
+
setTargetOffset = _useState8[1];
|
82
|
+
var overlayBackupRef = (0, _react.useRef)();
|
83
|
+
var backupRef = (0, _react.useRef)();
|
84
|
+
var _coachmarkRef = ref || backupRef;
|
85
|
+
var _overlayRef = overlayRef || overlayBackupRef;
|
86
|
+
var closeOverlay = function closeOverlay() {
|
87
|
+
setIsOpen(false);
|
88
|
+
};
|
89
|
+
var handleClose = function handleClose() {
|
90
|
+
if (isStacked) {
|
91
|
+
// If stacked, do not unmount,
|
92
|
+
// only call its ("parent") onClose method.
|
93
|
+
onClose();
|
94
|
+
} else {
|
95
|
+
setIsOpen(false);
|
96
|
+
onClose();
|
97
|
+
}
|
98
|
+
};
|
99
|
+
var handleTargetClick = function handleTargetClick(e) {
|
100
|
+
setTargetRect(e.target.getBoundingClientRect());
|
101
|
+
setTargetOffset({
|
102
|
+
x: e.target.offsetLeft,
|
103
|
+
y: e.target.offsetTop
|
104
|
+
});
|
105
|
+
if (isBeacon) {
|
106
|
+
// toggle open/closed for beacons
|
107
|
+
setIsOpen(function (prevIsOpen) {
|
108
|
+
return !prevIsOpen;
|
109
|
+
});
|
110
|
+
} else {
|
111
|
+
// reset position for all other kinds
|
112
|
+
setIsOpen(false);
|
113
|
+
setShouldResetPosition(true);
|
114
|
+
}
|
115
|
+
};
|
116
|
+
var contextValue = {
|
117
|
+
buttonProps: {
|
118
|
+
'aria-expanded': isOpen,
|
119
|
+
onClick: handleTargetClick,
|
120
|
+
// Compensate for accidental open/close on double-click.
|
121
|
+
// Only open on double-click.
|
122
|
+
onDoubleClick: handleTargetClick
|
123
|
+
},
|
124
|
+
closeButtonProps: {
|
125
|
+
onClick: handleClose
|
126
|
+
},
|
127
|
+
targetRect: targetRect,
|
128
|
+
targetOffset: targetOffset,
|
129
|
+
align: align,
|
130
|
+
positionTune: positionTune
|
131
|
+
};
|
132
|
+
var handleResize = (0, _lodash.throttle)(function () {
|
133
|
+
closeOverlay();
|
134
|
+
}, 2000);
|
135
|
+
|
136
|
+
// instead of toggling on/off,
|
137
|
+
// keep open and reset to original position
|
138
|
+
(0, _react.useEffect)(function () {
|
139
|
+
if (shouldResetPosition) {
|
140
|
+
setShouldResetPosition(false);
|
141
|
+
setIsOpen(true);
|
142
|
+
}
|
143
|
+
}, [shouldResetPosition]);
|
144
|
+
|
145
|
+
// On unmount:
|
146
|
+
// - DO NOT "Close()" the coachmark.
|
147
|
+
// - This triggers a "signal" to close it forever.
|
148
|
+
// - "Closing" should only ever be a user-triggered event.
|
149
|
+
// - DO "hide" the coachmark.
|
150
|
+
// - The app is doing the action for the user.
|
151
|
+
// - The user will have the opportunity to open it again.
|
152
|
+
(0, _react.useEffect)(function () {
|
153
|
+
return function () {
|
154
|
+
return setIsOpen(false);
|
155
|
+
};
|
156
|
+
}, []);
|
157
|
+
(0, _hooks.useClickOutsideElement)(_coachmarkRef, _overlayRef, overlayKind, closeOverlay);
|
158
|
+
(0, _hooks.useWindowEvent)('resize', handleResize);
|
159
|
+
return /*#__PURE__*/_react.default.createElement(_context.CoachmarkContext.Provider, {
|
160
|
+
value: contextValue
|
161
|
+
}, /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
162
|
+
className: (0, _classnames.default)(blockClass, "".concat(blockClass, "__").concat(theme), className),
|
163
|
+
ref: _coachmarkRef
|
164
|
+
}, rest, (0, _devtools.getDevtoolsProps)(componentName)), target, isOpen && /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/_react.default.createElement(_CoachmarkOverlay.CoachmarkOverlay, {
|
165
|
+
ref: _overlayRef,
|
166
|
+
fixedIsVisible: false,
|
167
|
+
kind: overlayKind,
|
168
|
+
onClose: handleClose,
|
169
|
+
theme: theme,
|
170
|
+
className: overlayClassName
|
171
|
+
}, children), portalNode)));
|
172
|
+
});
|
173
|
+
|
174
|
+
// Return a placeholder if not released and not enabled by feature flag
|
175
|
+
exports.Coachmark = Coachmark;
|
176
|
+
exports.Coachmark = Coachmark = _settings.pkg.checkComponentEnabled(Coachmark, componentName);
|
177
|
+
|
178
|
+
// The display name of the component, used by React. Note that displayName
|
179
|
+
// is used in preference to relying on function.name.
|
180
|
+
Coachmark.displayName = componentName;
|
181
|
+
|
182
|
+
// The types and DocGen commentary for the component props,
|
183
|
+
// in alphabetical order (for consistency).
|
184
|
+
// See https://www.npmjs.com/package/prop-types#usage.
|
185
|
+
Coachmark.propTypes = {
|
186
|
+
/**
|
187
|
+
* Where to render the Coachmark relative to its target.
|
188
|
+
* Applies only to Floating and Tooltip Coachmarks.
|
189
|
+
* @see COACHMARK_ALIGNMENT
|
190
|
+
*/
|
191
|
+
align: _propTypes.default.oneOf(['bottom', 'bottom-left', 'bottom-right', 'left', 'left-top', 'left-bottom', 'right', 'right-top', 'right-bottom', 'top', 'top-left', 'top-right']),
|
192
|
+
// TODO: UPDATE COMMENT HERE - UPDATE MDX TO HAVE DIRECTION TO USE ONLY OVERLAY ELEMENTS>...
|
193
|
+
/**
|
194
|
+
* Coachmark should use a single CoachmarkOverlayElements component as a child.
|
195
|
+
* @see CoachmarkOverlayElements
|
196
|
+
*/
|
197
|
+
children: _propTypes.default.node.isRequired,
|
198
|
+
/**
|
199
|
+
* Optional class name for this component.
|
200
|
+
*/
|
201
|
+
className: _propTypes.default.string,
|
202
|
+
/**
|
203
|
+
* Function to call when the Coachmark closes.
|
204
|
+
*/
|
205
|
+
onClose: _propTypes.default.func,
|
206
|
+
/**
|
207
|
+
* Optional class name for the Coachmark Overlay component.
|
208
|
+
*/
|
209
|
+
overlayClassName: _propTypes.default.string,
|
210
|
+
/**
|
211
|
+
* What kind or style of Coachmark to render.
|
212
|
+
*/
|
213
|
+
overlayKind: _propTypes.default.oneOf(['tooltip', 'floating', 'stacked']),
|
214
|
+
overlayRef: _propTypes.default.oneOfType([
|
215
|
+
// Either a function
|
216
|
+
_propTypes.default.func,
|
217
|
+
// Or the instance of a DOM native element (see the note about SSR)
|
218
|
+
_propTypes.default.shape({
|
219
|
+
current: _propTypes.default.instanceOf(_propTypes.Component)
|
220
|
+
})]),
|
221
|
+
/**
|
222
|
+
* By default, the Coachmark will be appended to the end of `document.body`.
|
223
|
+
* The Coachmark will remain persistent as the user navigates the app until
|
224
|
+
* the user closes the Coachmark.
|
225
|
+
*
|
226
|
+
* Alternatively, the app developer can tightly couple the Coachmark to a DOM
|
227
|
+
* element or other component by specifying a CSS selector. The Coachmark will
|
228
|
+
* remain visible as long as that element remains visible or mounted. When the
|
229
|
+
* element is hidden or component is unmounted, the Coachmark will disappear.
|
230
|
+
*/
|
231
|
+
portalTarget: _propTypes.default.string,
|
232
|
+
/**
|
233
|
+
* Fine tune the position of the target in pixels. Applies only to Beacons.
|
234
|
+
*/
|
235
|
+
positionTune: _propTypes.default.shape({
|
236
|
+
x: _propTypes.default.number,
|
237
|
+
y: _propTypes.default.number
|
238
|
+
}),
|
239
|
+
/**
|
240
|
+
* The optional button or beacon that the user will click to show the Coachmark.
|
241
|
+
*/
|
242
|
+
target: _propTypes.default.node,
|
243
|
+
/**
|
244
|
+
* Determines the theme of the component.
|
245
|
+
*/
|
246
|
+
theme: _propTypes.default.oneOf(['light', 'dark'])
|
247
|
+
};
|
@@ -0,0 +1,137 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.CoachmarkDragbar = void 0;
|
9
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
11
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
13
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
14
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
15
|
+
var _iconsReact = require("@carbon/icons-react");
|
16
|
+
var _carbonComponentsReact = require("carbon-components-react");
|
17
|
+
var _devtools = require("../../global/js/utils/devtools");
|
18
|
+
var _settings = require("../../settings");
|
19
|
+
var _excluded = ["closeIconDescription", "onClose", "onDrag", "showCloseButton", "theme"];
|
20
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
21
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
22
|
+
// Carbon and package components we use.
|
23
|
+
/* TODO: @import(s) of carbon components and other package components. */
|
24
|
+
|
25
|
+
// The block part of our conventional BEM class names (blockClass__E--M).
|
26
|
+
var blockClass = "".concat(_settings.pkg.prefix, "--coachmark-dragbar");
|
27
|
+
var componentName = 'CoachmarkDragbar';
|
28
|
+
var defaults = {
|
29
|
+
closeIconDescription: 'Close',
|
30
|
+
onDrag: function onDrag() {},
|
31
|
+
onClose: function onClose() {},
|
32
|
+
showCloseButton: true,
|
33
|
+
theme: 'light'
|
34
|
+
};
|
35
|
+
|
36
|
+
/**
|
37
|
+
* DO NOT USE. This component is for the exclusive use
|
38
|
+
* of other Novice to Pro components.
|
39
|
+
*/
|
40
|
+
var CoachmarkDragbar = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
41
|
+
var _ref$closeIconDescrip = _ref.closeIconDescription,
|
42
|
+
closeIconDescription = _ref$closeIconDescrip === void 0 ? defaults.closeIconDescription : _ref$closeIconDescrip,
|
43
|
+
_ref$onClose = _ref.onClose,
|
44
|
+
onClose = _ref$onClose === void 0 ? defaults.onClose : _ref$onClose,
|
45
|
+
_ref$onDrag = _ref.onDrag,
|
46
|
+
onDrag = _ref$onDrag === void 0 ? defaults.onDrag : _ref$onDrag,
|
47
|
+
_ref$showCloseButton = _ref.showCloseButton,
|
48
|
+
showCloseButton = _ref$showCloseButton === void 0 ? defaults.showCloseButton : _ref$showCloseButton,
|
49
|
+
_ref$theme = _ref.theme,
|
50
|
+
theme = _ref$theme === void 0 ? defaults.theme : _ref$theme,
|
51
|
+
rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
52
|
+
var _useState = (0, _react.useState)(false),
|
53
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
54
|
+
isDragging = _useState2[0],
|
55
|
+
setIsDragging = _useState2[1];
|
56
|
+
(0, _react.useEffect)(function () {
|
57
|
+
var handleDragStop = function handleDragStop() {
|
58
|
+
return setIsDragging(false);
|
59
|
+
};
|
60
|
+
window.addEventListener('mouseup', handleDragStop);
|
61
|
+
return function () {
|
62
|
+
window.removeEventListener('mouseup', handleDragStop);
|
63
|
+
};
|
64
|
+
}, []);
|
65
|
+
(0, _react.useEffect)(function () {
|
66
|
+
var handleDrag = function handleDrag(event) {
|
67
|
+
onDrag(event.movementX, event.movementY);
|
68
|
+
};
|
69
|
+
if (isDragging) {
|
70
|
+
window.addEventListener('mousemove', handleDrag);
|
71
|
+
}
|
72
|
+
return function () {
|
73
|
+
window.removeEventListener('mousemove', handleDrag);
|
74
|
+
};
|
75
|
+
}, [isDragging, onDrag]);
|
76
|
+
var handleDragStart = function handleDragStart() {
|
77
|
+
return setIsDragging(true);
|
78
|
+
};
|
79
|
+
return /*#__PURE__*/_react.default.createElement("header", (0, _extends2.default)({}, rest, {
|
80
|
+
className: (0, _classnames.default)(blockClass, // Apply the block class to the main HTML element
|
81
|
+
"".concat(blockClass, "__").concat(theme),
|
82
|
+
// example: `${blockClass}__template-string-class-${kind}-n-${size}`,
|
83
|
+
{
|
84
|
+
// switched classes dependant on props or state
|
85
|
+
// example: [`${blockClass}__here-if-small`]: size === 'sm',
|
86
|
+
}),
|
87
|
+
ref: ref
|
88
|
+
// role="main"
|
89
|
+
}, (0, _devtools.getDevtoolsProps)(componentName)), /*#__PURE__*/_react.default.createElement("button", {
|
90
|
+
type: "button",
|
91
|
+
className: "".concat(blockClass, "__handle"),
|
92
|
+
onMouseDown: handleDragStart
|
93
|
+
}, /*#__PURE__*/_react.default.createElement(_iconsReact.Draggable16, null)), showCloseButton && /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.Button, {
|
94
|
+
kind: "ghost",
|
95
|
+
size: "sm",
|
96
|
+
renderIcon: _iconsReact.Close16,
|
97
|
+
iconDescription: closeIconDescription,
|
98
|
+
hasIconOnly: true,
|
99
|
+
className: "".concat(blockClass, "--close-btn"),
|
100
|
+
onClick: onClose
|
101
|
+
}));
|
102
|
+
});
|
103
|
+
|
104
|
+
// Return a placeholder if not released and not enabled by feature flag
|
105
|
+
exports.CoachmarkDragbar = CoachmarkDragbar;
|
106
|
+
exports.CoachmarkDragbar = CoachmarkDragbar = _settings.pkg.checkComponentEnabled(CoachmarkDragbar, componentName);
|
107
|
+
|
108
|
+
// The display name of the component, used by React. Note that displayName
|
109
|
+
// is used in preference to relying on function.name.
|
110
|
+
CoachmarkDragbar.displayName = componentName;
|
111
|
+
|
112
|
+
// The types and DocGen commentary for the component props,
|
113
|
+
// in alphabetical order (for consistency).
|
114
|
+
// See https://www.npmjs.com/package/prop-types#usage.
|
115
|
+
CoachmarkDragbar.propTypes = {
|
116
|
+
/**
|
117
|
+
* Tooltip text and aria label for the Close button icon.
|
118
|
+
*/
|
119
|
+
closeIconDescription: _propTypes.default.string,
|
120
|
+
/**
|
121
|
+
* Function to call when the close button is clicked.
|
122
|
+
*/
|
123
|
+
onClose: _propTypes.default.func,
|
124
|
+
/**
|
125
|
+
* Function to call when the user clicks and drags the Coachmark.
|
126
|
+
* For internal use only by the parent CoachmarkOverlay.
|
127
|
+
*/
|
128
|
+
onDrag: _propTypes.default.func,
|
129
|
+
/**
|
130
|
+
* Show/hide the "X" close button.
|
131
|
+
*/
|
132
|
+
showCloseButton: _propTypes.default.bool,
|
133
|
+
/**
|
134
|
+
* Determines the theme of the component.
|
135
|
+
*/
|
136
|
+
theme: _propTypes.default.oneOf(['light', 'dark'])
|
137
|
+
};
|