@carbon/ibm-products 1.55.1 → 1.56.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. package/css/index-full-carbon.css +639 -16
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +4 -4
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon.css +582 -9
  6. package/css/index-without-carbon.css.map +1 -1
  7. package/css/index-without-carbon.min.css +2 -2
  8. package/css/index-without-carbon.min.css.map +1 -1
  9. package/css/index.css +620 -12
  10. package/css/index.css.map +1 -1
  11. package/css/index.min.css +4 -4
  12. package/css/index.min.css.map +1 -1
  13. package/es/components/Carousel/Carousel.js +15 -5
  14. package/es/components/Coachmark/Coachmark.js +243 -0
  15. package/es/components/Coachmark/CoachmarkDragbar.js +137 -0
  16. package/es/components/Coachmark/CoachmarkHeader.js +88 -0
  17. package/es/components/Coachmark/CoachmarkOverlay.js +139 -0
  18. package/es/components/Coachmark/CoachmarkTagline.js +93 -0
  19. package/es/components/Coachmark/index.js +10 -0
  20. package/es/components/Coachmark/utils/constants.js +76 -0
  21. package/es/components/Coachmark/utils/context.js +5 -0
  22. package/es/components/Coachmark/utils/enums.js +40 -0
  23. package/es/components/Coachmark/utils/helpers.js +11 -0
  24. package/es/components/Coachmark/utils/hooks.js +54 -0
  25. package/es/components/CoachmarkBeacon/CoachmarkBeacon.js +90 -0
  26. package/es/components/CoachmarkBeacon/index.js +8 -0
  27. package/es/components/CoachmarkButton/CoachmarkButton.js +72 -0
  28. package/es/components/CoachmarkButton/index.js +8 -0
  29. package/es/components/CoachmarkFixed/CoachmarkFixed.js +201 -0
  30. package/es/components/CoachmarkFixed/index.js +8 -0
  31. package/es/components/CoachmarkOverlayElement/CoachmarkOverlayElement.js +86 -0
  32. package/es/components/CoachmarkOverlayElement/index.js +8 -0
  33. package/es/components/CoachmarkOverlayElements/CoachmarkOverlayElements.js +175 -0
  34. package/es/components/CoachmarkOverlayElements/index.js +8 -0
  35. package/es/components/CoachmarkStack/CoachmarkStack.js +260 -0
  36. package/es/components/CoachmarkStack/CoachmarkStackHome.js +157 -0
  37. package/es/components/CoachmarkStack/index.js +8 -0
  38. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +1 -4
  39. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsTearsheet.js +2 -5
  40. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/DraggableItemsList.js +33 -17
  41. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/TearsheetWrapper.js +0 -1
  42. package/es/components/Datagrid/useDefaultStringRenderer.js +2 -1
  43. package/es/components/Datagrid/useSortableColumns.js +8 -4
  44. package/es/components/NotificationsPanel/NotificationsPanel.js +3 -2
  45. package/es/components/index.js +7 -0
  46. package/es/global/js/package-settings.js +8 -1
  47. package/es/global/js/utils/test-helper.js +3 -3
  48. package/lib/components/Carousel/Carousel.js +15 -5
  49. package/lib/components/Coachmark/Coachmark.js +247 -0
  50. package/lib/components/Coachmark/CoachmarkDragbar.js +137 -0
  51. package/lib/components/Coachmark/CoachmarkHeader.js +85 -0
  52. package/lib/components/Coachmark/CoachmarkOverlay.js +139 -0
  53. package/lib/components/Coachmark/CoachmarkTagline.js +90 -0
  54. package/lib/components/Coachmark/index.js +38 -0
  55. package/lib/components/Coachmark/utils/constants.js +82 -0
  56. package/lib/components/Coachmark/utils/context.js +13 -0
  57. package/lib/components/Coachmark/utils/enums.js +49 -0
  58. package/lib/components/Coachmark/utils/helpers.js +17 -0
  59. package/lib/components/Coachmark/utils/hooks.js +60 -0
  60. package/lib/components/CoachmarkBeacon/CoachmarkBeacon.js +87 -0
  61. package/lib/components/CoachmarkBeacon/index.js +12 -0
  62. package/lib/components/CoachmarkButton/CoachmarkButton.js +69 -0
  63. package/lib/components/CoachmarkButton/index.js +12 -0
  64. package/lib/components/CoachmarkFixed/CoachmarkFixed.js +201 -0
  65. package/lib/components/CoachmarkFixed/index.js +12 -0
  66. package/lib/components/CoachmarkOverlayElement/CoachmarkOverlayElement.js +83 -0
  67. package/lib/components/CoachmarkOverlayElement/index.js +12 -0
  68. package/lib/components/CoachmarkOverlayElements/CoachmarkOverlayElements.js +176 -0
  69. package/lib/components/CoachmarkOverlayElements/index.js +12 -0
  70. package/lib/components/CoachmarkStack/CoachmarkStack.js +264 -0
  71. package/lib/components/CoachmarkStack/CoachmarkStackHome.js +160 -0
  72. package/lib/components/CoachmarkStack/index.js +12 -0
  73. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +1 -4
  74. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsTearsheet.js +2 -5
  75. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/DraggableItemsList.js +33 -17
  76. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/TearsheetWrapper.js +0 -1
  77. package/lib/components/Datagrid/useDefaultStringRenderer.js +2 -1
  78. package/lib/components/Datagrid/useSortableColumns.js +8 -4
  79. package/lib/components/NotificationsPanel/NotificationsPanel.js +3 -2
  80. package/lib/components/index.js +49 -0
  81. package/lib/global/js/package-settings.js +8 -1
  82. package/lib/global/js/utils/test-helper.js +3 -3
  83. package/package.json +8 -8
  84. package/scss/components/Carousel/_carousel.scss +3 -0
  85. package/scss/components/Coachmark/_index.scss +11 -0
  86. package/scss/components/Coachmark/_storybook-styles.scss +20 -0
  87. package/scss/components/Coachmark/styles/_coachmark-dragbar.scss +74 -0
  88. package/scss/components/Coachmark/styles/_coachmark-header.scss +58 -0
  89. package/scss/components/Coachmark/styles/_coachmark-overlay.scss +327 -0
  90. package/scss/components/Coachmark/styles/_coachmark-tagline.scss +118 -0
  91. package/scss/components/CoachmarkBeacon/_coachmark-beacon.scss +166 -0
  92. package/scss/components/CoachmarkBeacon/_index.scss +8 -0
  93. package/scss/components/CoachmarkBeacon/_storybook-styles.scss +19 -0
  94. package/scss/components/CoachmarkButton/_coachmark-button.scss +34 -0
  95. package/scss/components/CoachmarkButton/_index.scss +8 -0
  96. package/scss/components/CoachmarkButton/_storybook-styles.scss +19 -0
  97. package/scss/components/CoachmarkFixed/_coachmark-fixed.scss +34 -0
  98. package/scss/components/CoachmarkFixed/_index.scss +8 -0
  99. package/scss/components/CoachmarkFixed/_storybook-styles.scss +10 -0
  100. package/scss/components/CoachmarkOverlayElement/_coachmark-overlay-element.scss +50 -0
  101. package/scss/components/CoachmarkOverlayElement/_index.scss +8 -0
  102. package/scss/components/CoachmarkOverlayElement/_storybook-styles.scss +19 -0
  103. package/scss/components/CoachmarkOverlayElements/_coachmark-overlay-elements.scss +40 -0
  104. package/scss/components/CoachmarkOverlayElements/_index.scss +8 -0
  105. package/scss/components/CoachmarkOverlayElements/_storybook-styles.scss +19 -0
  106. package/scss/components/CoachmarkStack/_coachmark-stack.scss +85 -0
  107. package/scss/components/CoachmarkStack/_index.scss +8 -0
  108. package/scss/components/CoachmarkStack/_storybook-styles.scss +10 -0
  109. package/scss/components/Datagrid/styles/_useColumnCenterAlign.scss +9 -9
  110. package/scss/components/_index.scss +7 -1
@@ -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
+ };
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.CoachmarkHeader = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
+ var _react = _interopRequireDefault(require("react"));
11
+ var _propTypes = _interopRequireDefault(require("prop-types"));
12
+ var _classnames = _interopRequireDefault(require("classnames"));
13
+ var _iconsReact = require("@carbon/icons-react");
14
+ var _carbonComponentsReact = require("carbon-components-react");
15
+ var _devtools = require("../../global/js/utils/devtools");
16
+ var _settings = require("../../settings");
17
+ var _excluded = ["closeIconDescription", "onClose", "showCloseButton", "theme"];
18
+ // The block part of our conventional BEM class names (blockClass__E--M).
19
+ var blockClass = "".concat(_settings.pkg.prefix, "--coachmark-header");
20
+ var componentName = 'CoachmarkHeader';
21
+ var defaults = {
22
+ closeIconDescription: 'Close',
23
+ onClose: function onClose() {},
24
+ showCloseButton: true,
25
+ theme: 'light'
26
+ };
27
+
28
+ /**
29
+ * DO NOT USE. This component is for the exclusive use
30
+ * of other Novice to Pro components.
31
+ */
32
+ var CoachmarkHeader = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
33
+ var _ref$closeIconDescrip = _ref.closeIconDescription,
34
+ closeIconDescription = _ref$closeIconDescrip === void 0 ? defaults.closeIconDescription : _ref$closeIconDescrip,
35
+ _ref$onClose = _ref.onClose,
36
+ onClose = _ref$onClose === void 0 ? defaults.onClose : _ref$onClose,
37
+ _ref$showCloseButton = _ref.showCloseButton,
38
+ showCloseButton = _ref$showCloseButton === void 0 ? defaults.showCloseButton : _ref$showCloseButton,
39
+ _ref$theme = _ref.theme,
40
+ theme = _ref$theme === void 0 ? defaults.theme : _ref$theme,
41
+ rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
42
+ return /*#__PURE__*/_react.default.createElement("header", (0, _extends2.default)({}, rest, {
43
+ className: (0, _classnames.default)(blockClass, "".concat(blockClass, "__").concat(theme)),
44
+ ref: ref
45
+ // role="main"
46
+ }, (0, _devtools.getDevtoolsProps)(componentName)), showCloseButton && /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.Button, {
47
+ kind: "ghost",
48
+ size: "sm",
49
+ renderIcon: _iconsReact.Close16,
50
+ iconDescription: closeIconDescription,
51
+ hasIconOnly: true,
52
+ className: "".concat(blockClass, "--close-btn"),
53
+ onClick: onClose
54
+ }));
55
+ });
56
+
57
+ // Return a placeholder if not released and not enabled by feature flag
58
+ exports.CoachmarkHeader = CoachmarkHeader;
59
+ exports.CoachmarkHeader = CoachmarkHeader = _settings.pkg.checkComponentEnabled(CoachmarkHeader, componentName);
60
+
61
+ // The display name of the component, used by React. Note that displayName
62
+ // is used in preference to relying on function.name.
63
+ CoachmarkHeader.displayName = componentName;
64
+
65
+ // The types and DocGen commentary for the component props,
66
+ // in alphabetical order (for consistency).
67
+ // See https://www.npmjs.com/package/prop-types#usage.
68
+ CoachmarkHeader.propTypes = {
69
+ /**
70
+ * Tooltip text and aria label for the Close button icon.
71
+ */
72
+ closeIconDescription: _propTypes.default.string,
73
+ /**
74
+ * Function to call when the close button is clicked.
75
+ */
76
+ onClose: _propTypes.default.func,
77
+ /**
78
+ * Show/hide the "X" close button.
79
+ */
80
+ showCloseButton: _propTypes.default.bool,
81
+ /**
82
+ * Determines the theme of the component.
83
+ */
84
+ theme: _propTypes.default.oneOf(['light', 'dark'])
85
+ };
@@ -0,0 +1,139 @@
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.CoachmarkOverlay = void 0;
9
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
+ var _react = _interopRequireWildcard(require("react"));
12
+ var _propTypes = _interopRequireDefault(require("prop-types"));
13
+ var _classnames = _interopRequireDefault(require("classnames"));
14
+ var _devtools = require("../../global/js/utils/devtools");
15
+ var _settings = require("../../settings");
16
+ var _CoachmarkDragbar = require("./CoachmarkDragbar");
17
+ var _CoachmarkHeader = require("./CoachmarkHeader");
18
+ var _constants = require("./utils/constants");
19
+ var _context = require("./utils/context");
20
+ var _enums = require("./utils/enums");
21
+ var _excluded = ["children", "onClose", "fixedIsVisible", "className", "kind", "theme"];
22
+ 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); }
23
+ 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; }
24
+ // The block part of our conventional BEM class names (blockClass__E--M).
25
+ var blockClass = "".concat(_settings.pkg.prefix, "--coachmark-overlay");
26
+ var componentName = 'CoachmarkOverlay';
27
+
28
+ // NOTE: the component SCSS is not imported here: it is rolled up separately.
29
+
30
+ var defaults = {
31
+ kind: _enums.COACHMARK_OVERLAY_KIND.FLOATING,
32
+ theme: 'light'
33
+ };
34
+
35
+ /**
36
+ * DO NOT USE. This component is for the exclusive use
37
+ * of other Novice to Pro components.
38
+ */
39
+ var CoachmarkOverlay = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
40
+ var children = _ref.children,
41
+ onClose = _ref.onClose,
42
+ fixedIsVisible = _ref.fixedIsVisible,
43
+ className = _ref.className,
44
+ _ref$kind = _ref.kind,
45
+ kind = _ref$kind === void 0 ? defaults.kind : _ref$kind,
46
+ _ref$theme = _ref.theme,
47
+ theme = _ref$theme === void 0 ? defaults.theme : _ref$theme,
48
+ rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
49
+ var overlayRef = (0, _react.useRef)();
50
+ var coachmark = (0, _context.useCoachmark)();
51
+ var isBeacon = kind === _enums.COACHMARK_OVERLAY_KIND.TOOLTIP;
52
+ var isDraggable = kind === _enums.COACHMARK_OVERLAY_KIND.FLOATING;
53
+ var styledTune = {};
54
+ // TODO: check this... this feels like it should be in a hook with no dep array.
55
+ if (isBeacon || isDraggable) {
56
+ if (coachmark.targetRect) {
57
+ styledTune = {
58
+ left: coachmark.targetRect.x + window.scrollX,
59
+ top: coachmark.targetRect.y + window.scrollY
60
+ };
61
+ }
62
+ if (isBeacon) {
63
+ // Compensate for radius of beacon
64
+ styledTune.left += 16;
65
+ styledTune.top += 16;
66
+ } else if (isDraggable) {
67
+ // Compensate for width and height of target element
68
+ var offsetTune = (0, _constants.getOffsetTune)(coachmark, kind);
69
+ styledTune.left += offsetTune.left;
70
+ styledTune.top += offsetTune.top;
71
+ }
72
+ }
73
+ function handleDrag(movementX, movementY) {
74
+ var overlay = overlayRef.current;
75
+ var _overlay$getBoundingC = overlay.getBoundingClientRect(),
76
+ x = _overlay$getBoundingC.x,
77
+ y = _overlay$getBoundingC.y;
78
+ overlay.style.transform = 'none';
79
+ overlay.style.position = 'fixed';
80
+ overlay.style.left = "".concat(x + movementX, "px");
81
+ overlay.style.top = "".concat(y + movementY, "px");
82
+ overlay.style.bottom = 'auto';
83
+ }
84
+ return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, rest, {
85
+ className: (0, _classnames.default)(blockClass, "".concat(blockClass, "--").concat(kind), "".concat(blockClass, "__").concat(theme), (isBeacon || isDraggable) && "".concat(blockClass, "--").concat(coachmark.align), fixedIsVisible && "".concat(blockClass, "--is-visible"), className),
86
+ ref: overlayRef,
87
+ style: styledTune
88
+ }, (0, _devtools.getDevtoolsProps)(componentName)), isDraggable ? /*#__PURE__*/_react.default.createElement(_CoachmarkDragbar.CoachmarkDragbar, {
89
+ onDrag: handleDrag,
90
+ onClose: onClose
91
+ }) : /*#__PURE__*/_react.default.createElement(_CoachmarkHeader.CoachmarkHeader, {
92
+ onClose: onClose
93
+ }), /*#__PURE__*/_react.default.createElement("div", {
94
+ className: "".concat(blockClass, "__body"),
95
+ ref: ref
96
+ }, children), isBeacon && /*#__PURE__*/_react.default.createElement("span", {
97
+ className: "".concat(blockClass, "__caret")
98
+ }));
99
+ });
100
+
101
+ // Return a placeholder if not released and not enabled by feature flag
102
+ exports.CoachmarkOverlay = CoachmarkOverlay;
103
+ exports.CoachmarkOverlay = CoachmarkOverlay = _settings.pkg.checkComponentEnabled(CoachmarkOverlay, componentName);
104
+
105
+ // The display name of the component, used by React. Note that displayName
106
+ // is used in preference to relying on function.name.
107
+ CoachmarkOverlay.displayName = componentName;
108
+
109
+ // The types and DocGen commentary for the component props,
110
+ // in alphabetical order (for consistency).
111
+ // See https://www.npmjs.com/package/prop-types#usage.
112
+ CoachmarkOverlay.propTypes = {
113
+ /**
114
+ * The CoachmarkOverlayElements child components.
115
+ * Validation is handled in the parent Coachmark component.
116
+ */
117
+ children: _propTypes.default.node.isRequired,
118
+ /**
119
+ * Optional class name for this component.
120
+ */
121
+ className: _propTypes.default.string,
122
+ /**
123
+ * The visibility of CoachmarkOverlay is
124
+ * managed in the parent Coachmark component.
125
+ */
126
+ fixedIsVisible: _propTypes.default.bool.isRequired,
127
+ /**
128
+ * What kind or style of Coachmark to render.
129
+ */
130
+ kind: _propTypes.default.oneOf(Object.values(_enums.COACHMARK_OVERLAY_KIND)),
131
+ /**
132
+ * Function to call when the Coachmark closes.
133
+ */
134
+ onClose: _propTypes.default.func.isRequired,
135
+ /**
136
+ * Determines the theme of the component.
137
+ */
138
+ theme: _propTypes.default.oneOf(['light', 'dark'])
139
+ };