@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.
Files changed (95) hide show
  1. package/css/index-full-carbon.css +579 -0
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +1 -1
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon.css +579 -0
  6. package/css/index-without-carbon.css.map +1 -1
  7. package/css/index-without-carbon.min.css +1 -1
  8. package/css/index-without-carbon.min.css.map +1 -1
  9. package/css/index.css +579 -0
  10. package/css/index.css.map +1 -1
  11. package/css/index.min.css +1 -1
  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/NotificationsPanel/NotificationsPanel.js +3 -2
  39. package/es/components/index.js +7 -0
  40. package/es/global/js/package-settings.js +8 -1
  41. package/lib/components/Carousel/Carousel.js +15 -5
  42. package/lib/components/Coachmark/Coachmark.js +247 -0
  43. package/lib/components/Coachmark/CoachmarkDragbar.js +137 -0
  44. package/lib/components/Coachmark/CoachmarkHeader.js +85 -0
  45. package/lib/components/Coachmark/CoachmarkOverlay.js +139 -0
  46. package/lib/components/Coachmark/CoachmarkTagline.js +90 -0
  47. package/lib/components/Coachmark/index.js +38 -0
  48. package/lib/components/Coachmark/utils/constants.js +82 -0
  49. package/lib/components/Coachmark/utils/context.js +13 -0
  50. package/lib/components/Coachmark/utils/enums.js +49 -0
  51. package/lib/components/Coachmark/utils/helpers.js +17 -0
  52. package/lib/components/Coachmark/utils/hooks.js +60 -0
  53. package/lib/components/CoachmarkBeacon/CoachmarkBeacon.js +87 -0
  54. package/lib/components/CoachmarkBeacon/index.js +12 -0
  55. package/lib/components/CoachmarkButton/CoachmarkButton.js +69 -0
  56. package/lib/components/CoachmarkButton/index.js +12 -0
  57. package/lib/components/CoachmarkFixed/CoachmarkFixed.js +201 -0
  58. package/lib/components/CoachmarkFixed/index.js +12 -0
  59. package/lib/components/CoachmarkOverlayElement/CoachmarkOverlayElement.js +83 -0
  60. package/lib/components/CoachmarkOverlayElement/index.js +12 -0
  61. package/lib/components/CoachmarkOverlayElements/CoachmarkOverlayElements.js +176 -0
  62. package/lib/components/CoachmarkOverlayElements/index.js +12 -0
  63. package/lib/components/CoachmarkStack/CoachmarkStack.js +264 -0
  64. package/lib/components/CoachmarkStack/CoachmarkStackHome.js +160 -0
  65. package/lib/components/CoachmarkStack/index.js +12 -0
  66. package/lib/components/NotificationsPanel/NotificationsPanel.js +3 -2
  67. package/lib/components/index.js +49 -0
  68. package/lib/global/js/package-settings.js +8 -1
  69. package/package.json +2 -2
  70. package/scss/components/Carousel/_carousel.scss +3 -0
  71. package/scss/components/Coachmark/_index.scss +11 -0
  72. package/scss/components/Coachmark/_storybook-styles.scss +20 -0
  73. package/scss/components/Coachmark/styles/_coachmark-dragbar.scss +74 -0
  74. package/scss/components/Coachmark/styles/_coachmark-header.scss +58 -0
  75. package/scss/components/Coachmark/styles/_coachmark-overlay.scss +327 -0
  76. package/scss/components/Coachmark/styles/_coachmark-tagline.scss +118 -0
  77. package/scss/components/CoachmarkBeacon/_coachmark-beacon.scss +166 -0
  78. package/scss/components/CoachmarkBeacon/_index.scss +8 -0
  79. package/scss/components/CoachmarkBeacon/_storybook-styles.scss +19 -0
  80. package/scss/components/CoachmarkButton/_coachmark-button.scss +34 -0
  81. package/scss/components/CoachmarkButton/_index.scss +8 -0
  82. package/scss/components/CoachmarkButton/_storybook-styles.scss +19 -0
  83. package/scss/components/CoachmarkFixed/_coachmark-fixed.scss +34 -0
  84. package/scss/components/CoachmarkFixed/_index.scss +8 -0
  85. package/scss/components/CoachmarkFixed/_storybook-styles.scss +10 -0
  86. package/scss/components/CoachmarkOverlayElement/_coachmark-overlay-element.scss +50 -0
  87. package/scss/components/CoachmarkOverlayElement/_index.scss +8 -0
  88. package/scss/components/CoachmarkOverlayElement/_storybook-styles.scss +19 -0
  89. package/scss/components/CoachmarkOverlayElements/_coachmark-overlay-elements.scss +40 -0
  90. package/scss/components/CoachmarkOverlayElements/_index.scss +8 -0
  91. package/scss/components/CoachmarkOverlayElements/_storybook-styles.scss +19 -0
  92. package/scss/components/CoachmarkStack/_coachmark-stack.scss +85 -0
  93. package/scss/components/CoachmarkStack/_index.scss +8 -0
  94. package/scss/components/CoachmarkStack/_storybook-styles.scss +10 -0
  95. package/scss/components/_index.scss +7 -1
@@ -0,0 +1,243 @@
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 = ["align", "children", "className", "onClose", "overlayClassName", "overlayKind", "overlayRef", "portalTarget", "positionTune", "target", "theme"];
5
+ /**
6
+ * Copyright IBM Corp. 2023, 2023
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 React, { forwardRef, useEffect, useRef, useState } from 'react';
13
+ import cx from 'classnames';
14
+ import PropTypes, { Component } from 'prop-types';
15
+ import { createPortal } from 'react-dom';
16
+ import { CoachmarkOverlay } from './CoachmarkOverlay';
17
+ import { CoachmarkContext } from './utils/context';
18
+ import { COACHMARK_OVERLAY_KIND } from './utils/enums';
19
+ import { useClickOutsideElement, useWindowEvent } from './utils/hooks';
20
+ import { getDevtoolsProps } from '../../global/js/utils/devtools';
21
+ import { pkg /*, carbon */ } from '../../settings';
22
+ import { throttle } from 'lodash';
23
+ // The block part of our conventional BEM class names (blockClass__E--M).
24
+ var blockClass = "".concat(pkg.prefix, "--coachmark");
25
+ var componentName = 'Coachmark';
26
+ var defaults = {
27
+ align: 'bottom',
28
+ onClose: function onClose() {},
29
+ overlayKind: 'tooltip',
30
+ theme: 'light'
31
+ };
32
+
33
+ /**
34
+ * Coachmarks are used to call out specific functionality or concepts
35
+ * within the UI that may not be intuitive but are important for the
36
+ * user to gain understanding of the product's main value and discover new use cases.
37
+ */
38
+
39
+ export var Coachmark = /*#__PURE__*/forwardRef(function (_ref, ref) {
40
+ var _document$querySelect;
41
+ var _ref$align = _ref.align,
42
+ align = _ref$align === void 0 ? defaults.align : _ref$align,
43
+ children = _ref.children,
44
+ className = _ref.className,
45
+ _ref$onClose = _ref.onClose,
46
+ onClose = _ref$onClose === void 0 ? defaults.onClose : _ref$onClose,
47
+ overlayClassName = _ref.overlayClassName,
48
+ _ref$overlayKind = _ref.overlayKind,
49
+ overlayKind = _ref$overlayKind === void 0 ? defaults.overlayKind : _ref$overlayKind,
50
+ overlayRef = _ref.overlayRef,
51
+ portalTarget = _ref.portalTarget,
52
+ positionTune = _ref.positionTune,
53
+ target = _ref.target,
54
+ _ref$theme = _ref.theme,
55
+ theme = _ref$theme === void 0 ? defaults.theme : _ref$theme,
56
+ rest = _objectWithoutProperties(_ref, _excluded);
57
+ var isBeacon = overlayKind === COACHMARK_OVERLAY_KIND.TOOLTIP;
58
+ var isStacked = overlayKind === COACHMARK_OVERLAY_KIND.STACKED;
59
+ var portalNode = portalTarget ? (_document$querySelect = document.querySelector(portalTarget)) !== null && _document$querySelect !== void 0 ? _document$querySelect : document.querySelector('body') : document.querySelector('body');
60
+ var _useState = useState(isStacked),
61
+ _useState2 = _slicedToArray(_useState, 2),
62
+ isOpen = _useState2[0],
63
+ setIsOpen = _useState2[1];
64
+ var _useState3 = useState(false),
65
+ _useState4 = _slicedToArray(_useState3, 2),
66
+ shouldResetPosition = _useState4[0],
67
+ setShouldResetPosition = _useState4[1];
68
+ var _useState5 = useState(),
69
+ _useState6 = _slicedToArray(_useState5, 2),
70
+ targetRect = _useState6[0],
71
+ setTargetRect = _useState6[1];
72
+ var _useState7 = useState({
73
+ x: 0,
74
+ y: 0
75
+ }),
76
+ _useState8 = _slicedToArray(_useState7, 2),
77
+ targetOffset = _useState8[0],
78
+ setTargetOffset = _useState8[1];
79
+ var overlayBackupRef = useRef();
80
+ var backupRef = useRef();
81
+ var _coachmarkRef = ref || backupRef;
82
+ var _overlayRef = overlayRef || overlayBackupRef;
83
+ var closeOverlay = function closeOverlay() {
84
+ setIsOpen(false);
85
+ };
86
+ var handleClose = function handleClose() {
87
+ if (isStacked) {
88
+ // If stacked, do not unmount,
89
+ // only call its ("parent") onClose method.
90
+ onClose();
91
+ } else {
92
+ setIsOpen(false);
93
+ onClose();
94
+ }
95
+ };
96
+ var handleTargetClick = function handleTargetClick(e) {
97
+ setTargetRect(e.target.getBoundingClientRect());
98
+ setTargetOffset({
99
+ x: e.target.offsetLeft,
100
+ y: e.target.offsetTop
101
+ });
102
+ if (isBeacon) {
103
+ // toggle open/closed for beacons
104
+ setIsOpen(function (prevIsOpen) {
105
+ return !prevIsOpen;
106
+ });
107
+ } else {
108
+ // reset position for all other kinds
109
+ setIsOpen(false);
110
+ setShouldResetPosition(true);
111
+ }
112
+ };
113
+ var contextValue = {
114
+ buttonProps: {
115
+ 'aria-expanded': isOpen,
116
+ onClick: handleTargetClick,
117
+ // Compensate for accidental open/close on double-click.
118
+ // Only open on double-click.
119
+ onDoubleClick: handleTargetClick
120
+ },
121
+ closeButtonProps: {
122
+ onClick: handleClose
123
+ },
124
+ targetRect: targetRect,
125
+ targetOffset: targetOffset,
126
+ align: align,
127
+ positionTune: positionTune
128
+ };
129
+ var handleResize = throttle(function () {
130
+ closeOverlay();
131
+ }, 2000);
132
+
133
+ // instead of toggling on/off,
134
+ // keep open and reset to original position
135
+ useEffect(function () {
136
+ if (shouldResetPosition) {
137
+ setShouldResetPosition(false);
138
+ setIsOpen(true);
139
+ }
140
+ }, [shouldResetPosition]);
141
+
142
+ // On unmount:
143
+ // - DO NOT "Close()" the coachmark.
144
+ // - This triggers a "signal" to close it forever.
145
+ // - "Closing" should only ever be a user-triggered event.
146
+ // - DO "hide" the coachmark.
147
+ // - The app is doing the action for the user.
148
+ // - The user will have the opportunity to open it again.
149
+ useEffect(function () {
150
+ return function () {
151
+ return setIsOpen(false);
152
+ };
153
+ }, []);
154
+ useClickOutsideElement(_coachmarkRef, _overlayRef, overlayKind, closeOverlay);
155
+ useWindowEvent('resize', handleResize);
156
+ return /*#__PURE__*/React.createElement(CoachmarkContext.Provider, {
157
+ value: contextValue
158
+ }, /*#__PURE__*/React.createElement("div", _extends({
159
+ className: cx(blockClass, "".concat(blockClass, "__").concat(theme), className),
160
+ ref: _coachmarkRef
161
+ }, rest, getDevtoolsProps(componentName)), target, isOpen && /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement(CoachmarkOverlay, {
162
+ ref: _overlayRef,
163
+ fixedIsVisible: false,
164
+ kind: overlayKind,
165
+ onClose: handleClose,
166
+ theme: theme,
167
+ className: overlayClassName
168
+ }, children), portalNode)));
169
+ });
170
+
171
+ // Return a placeholder if not released and not enabled by feature flag
172
+ Coachmark = pkg.checkComponentEnabled(Coachmark, componentName);
173
+
174
+ // The display name of the component, used by React. Note that displayName
175
+ // is used in preference to relying on function.name.
176
+ Coachmark.displayName = componentName;
177
+
178
+ // The types and DocGen commentary for the component props,
179
+ // in alphabetical order (for consistency).
180
+ // See https://www.npmjs.com/package/prop-types#usage.
181
+ Coachmark.propTypes = {
182
+ /**
183
+ * Where to render the Coachmark relative to its target.
184
+ * Applies only to Floating and Tooltip Coachmarks.
185
+ * @see COACHMARK_ALIGNMENT
186
+ */
187
+ align: PropTypes.oneOf(['bottom', 'bottom-left', 'bottom-right', 'left', 'left-top', 'left-bottom', 'right', 'right-top', 'right-bottom', 'top', 'top-left', 'top-right']),
188
+ // TODO: UPDATE COMMENT HERE - UPDATE MDX TO HAVE DIRECTION TO USE ONLY OVERLAY ELEMENTS>...
189
+ /**
190
+ * Coachmark should use a single CoachmarkOverlayElements component as a child.
191
+ * @see CoachmarkOverlayElements
192
+ */
193
+ children: PropTypes.node.isRequired,
194
+ /**
195
+ * Optional class name for this component.
196
+ */
197
+ className: PropTypes.string,
198
+ /**
199
+ * Function to call when the Coachmark closes.
200
+ */
201
+ onClose: PropTypes.func,
202
+ /**
203
+ * Optional class name for the Coachmark Overlay component.
204
+ */
205
+ overlayClassName: PropTypes.string,
206
+ /**
207
+ * What kind or style of Coachmark to render.
208
+ */
209
+ overlayKind: PropTypes.oneOf(['tooltip', 'floating', 'stacked']),
210
+ overlayRef: PropTypes.oneOfType([
211
+ // Either a function
212
+ PropTypes.func,
213
+ // Or the instance of a DOM native element (see the note about SSR)
214
+ PropTypes.shape({
215
+ current: PropTypes.instanceOf(Component)
216
+ })]),
217
+ /**
218
+ * By default, the Coachmark will be appended to the end of `document.body`.
219
+ * The Coachmark will remain persistent as the user navigates the app until
220
+ * the user closes the Coachmark.
221
+ *
222
+ * Alternatively, the app developer can tightly couple the Coachmark to a DOM
223
+ * element or other component by specifying a CSS selector. The Coachmark will
224
+ * remain visible as long as that element remains visible or mounted. When the
225
+ * element is hidden or component is unmounted, the Coachmark will disappear.
226
+ */
227
+ portalTarget: PropTypes.string,
228
+ /**
229
+ * Fine tune the position of the target in pixels. Applies only to Beacons.
230
+ */
231
+ positionTune: PropTypes.shape({
232
+ x: PropTypes.number,
233
+ y: PropTypes.number
234
+ }),
235
+ /**
236
+ * The optional button or beacon that the user will click to show the Coachmark.
237
+ */
238
+ target: PropTypes.node,
239
+ /**
240
+ * Determines the theme of the component.
241
+ */
242
+ theme: PropTypes.oneOf(['light', 'dark'])
243
+ };
@@ -0,0 +1,137 @@
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 = ["closeIconDescription", "onClose", "onDrag", "showCloseButton", "theme"];
5
+ /**
6
+ * Copyright IBM Corp. 2023, 2023
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, { useEffect, useState } from 'react';
14
+
15
+ // Other standard imports.
16
+ import PropTypes from 'prop-types';
17
+ import cx from 'classnames';
18
+ import { Close16, Draggable16 } from '@carbon/icons-react';
19
+ import { Button } from 'carbon-components-react';
20
+ import { getDevtoolsProps } from '../../global/js/utils/devtools';
21
+ import { pkg /*, carbon */ } from '../../settings';
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-dragbar");
28
+ var componentName = 'CoachmarkDragbar';
29
+ var defaults = {
30
+ closeIconDescription: 'Close',
31
+ onDrag: function onDrag() {},
32
+ onClose: function onClose() {},
33
+ showCloseButton: true,
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 CoachmarkDragbar = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
42
+ var _ref$closeIconDescrip = _ref.closeIconDescription,
43
+ closeIconDescription = _ref$closeIconDescrip === void 0 ? defaults.closeIconDescription : _ref$closeIconDescrip,
44
+ _ref$onClose = _ref.onClose,
45
+ onClose = _ref$onClose === void 0 ? defaults.onClose : _ref$onClose,
46
+ _ref$onDrag = _ref.onDrag,
47
+ onDrag = _ref$onDrag === void 0 ? defaults.onDrag : _ref$onDrag,
48
+ _ref$showCloseButton = _ref.showCloseButton,
49
+ showCloseButton = _ref$showCloseButton === void 0 ? defaults.showCloseButton : _ref$showCloseButton,
50
+ _ref$theme = _ref.theme,
51
+ theme = _ref$theme === void 0 ? defaults.theme : _ref$theme,
52
+ rest = _objectWithoutProperties(_ref, _excluded);
53
+ var _useState = useState(false),
54
+ _useState2 = _slicedToArray(_useState, 2),
55
+ isDragging = _useState2[0],
56
+ setIsDragging = _useState2[1];
57
+ useEffect(function () {
58
+ var handleDragStop = function handleDragStop() {
59
+ return setIsDragging(false);
60
+ };
61
+ window.addEventListener('mouseup', handleDragStop);
62
+ return function () {
63
+ window.removeEventListener('mouseup', handleDragStop);
64
+ };
65
+ }, []);
66
+ useEffect(function () {
67
+ var handleDrag = function handleDrag(event) {
68
+ onDrag(event.movementX, event.movementY);
69
+ };
70
+ if (isDragging) {
71
+ window.addEventListener('mousemove', handleDrag);
72
+ }
73
+ return function () {
74
+ window.removeEventListener('mousemove', handleDrag);
75
+ };
76
+ }, [isDragging, onDrag]);
77
+ var handleDragStart = function handleDragStart() {
78
+ return setIsDragging(true);
79
+ };
80
+ return /*#__PURE__*/React.createElement("header", _extends({}, rest, {
81
+ className: cx(blockClass, // Apply the block class to the main HTML element
82
+ "".concat(blockClass, "__").concat(theme),
83
+ // example: `${blockClass}__template-string-class-${kind}-n-${size}`,
84
+ {
85
+ // switched classes dependant on props or state
86
+ // example: [`${blockClass}__here-if-small`]: size === 'sm',
87
+ }),
88
+ ref: ref
89
+ // role="main"
90
+ }, getDevtoolsProps(componentName)), /*#__PURE__*/React.createElement("button", {
91
+ type: "button",
92
+ className: "".concat(blockClass, "__handle"),
93
+ onMouseDown: handleDragStart
94
+ }, /*#__PURE__*/React.createElement(Draggable16, null)), showCloseButton && /*#__PURE__*/React.createElement(Button, {
95
+ kind: "ghost",
96
+ size: "sm",
97
+ renderIcon: Close16,
98
+ iconDescription: closeIconDescription,
99
+ hasIconOnly: true,
100
+ className: "".concat(blockClass, "--close-btn"),
101
+ onClick: onClose
102
+ }));
103
+ });
104
+
105
+ // Return a placeholder if not released and not enabled by feature flag
106
+ CoachmarkDragbar = 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.string,
120
+ /**
121
+ * Function to call when the close button is clicked.
122
+ */
123
+ onClose: PropTypes.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.func,
129
+ /**
130
+ * Show/hide the "X" close button.
131
+ */
132
+ showCloseButton: PropTypes.bool,
133
+ /**
134
+ * Determines the theme of the component.
135
+ */
136
+ theme: PropTypes.oneOf(['light', 'dark'])
137
+ };
@@ -0,0 +1,88 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["closeIconDescription", "onClose", "showCloseButton", "theme"];
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 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 { Close16 } from '@carbon/icons-react';
18
+ import { Button } from 'carbon-components-react';
19
+ import { getDevtoolsProps } from '../../global/js/utils/devtools';
20
+ import { pkg /*, carbon */ } from '../../settings';
21
+
22
+ // The block part of our conventional BEM class names (blockClass__E--M).
23
+ var blockClass = "".concat(pkg.prefix, "--coachmark-header");
24
+ var componentName = 'CoachmarkHeader';
25
+ var defaults = {
26
+ closeIconDescription: 'Close',
27
+ onClose: function onClose() {},
28
+ showCloseButton: true,
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 CoachmarkHeader = /*#__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$showCloseButton = _ref.showCloseButton,
42
+ showCloseButton = _ref$showCloseButton === void 0 ? defaults.showCloseButton : _ref$showCloseButton,
43
+ _ref$theme = _ref.theme,
44
+ theme = _ref$theme === void 0 ? defaults.theme : _ref$theme,
45
+ rest = _objectWithoutProperties(_ref, _excluded);
46
+ return /*#__PURE__*/React.createElement("header", _extends({}, rest, {
47
+ className: cx(blockClass, "".concat(blockClass, "__").concat(theme)),
48
+ ref: ref
49
+ // role="main"
50
+ }, getDevtoolsProps(componentName)), showCloseButton && /*#__PURE__*/React.createElement(Button, {
51
+ kind: "ghost",
52
+ size: "sm",
53
+ renderIcon: Close16,
54
+ iconDescription: closeIconDescription,
55
+ hasIconOnly: true,
56
+ className: "".concat(blockClass, "--close-btn"),
57
+ onClick: onClose
58
+ }));
59
+ });
60
+
61
+ // Return a placeholder if not released and not enabled by feature flag
62
+ CoachmarkHeader = pkg.checkComponentEnabled(CoachmarkHeader, componentName);
63
+
64
+ // The display name of the component, used by React. Note that displayName
65
+ // is used in preference to relying on function.name.
66
+ CoachmarkHeader.displayName = componentName;
67
+
68
+ // The types and DocGen commentary for the component props,
69
+ // in alphabetical order (for consistency).
70
+ // See https://www.npmjs.com/package/prop-types#usage.
71
+ CoachmarkHeader.propTypes = {
72
+ /**
73
+ * Tooltip text and aria label for the Close button icon.
74
+ */
75
+ closeIconDescription: PropTypes.string,
76
+ /**
77
+ * Function to call when the close button is clicked.
78
+ */
79
+ onClose: PropTypes.func,
80
+ /**
81
+ * Show/hide the "X" close button.
82
+ */
83
+ showCloseButton: PropTypes.bool,
84
+ /**
85
+ * Determines the theme of the component.
86
+ */
87
+ theme: PropTypes.oneOf(['light', 'dark'])
88
+ };
@@ -0,0 +1,139 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["children", "onClose", "fixedIsVisible", "className", "kind", "theme"];
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 portions of React that are needed.
12
+ import React, { forwardRef, useRef } from 'react';
13
+
14
+ // Other standard imports.
15
+ import PropTypes from 'prop-types';
16
+ import cx from 'classnames';
17
+ import { getDevtoolsProps } from '../../global/js/utils/devtools';
18
+ import { pkg /*, carbon */ } from '../../settings';
19
+ import { CoachmarkDragbar } from './CoachmarkDragbar';
20
+ import { CoachmarkHeader } from './CoachmarkHeader';
21
+ import { getOffsetTune } from './utils/constants';
22
+ import { useCoachmark } from './utils/context';
23
+ import { COACHMARK_OVERLAY_KIND } from './utils/enums';
24
+
25
+ // The block part of our conventional BEM class names (blockClass__E--M).
26
+ var blockClass = "".concat(pkg.prefix, "--coachmark-overlay");
27
+ var componentName = 'CoachmarkOverlay';
28
+
29
+ // NOTE: the component SCSS is not imported here: it is rolled up separately.
30
+
31
+ var defaults = {
32
+ kind: COACHMARK_OVERLAY_KIND.FLOATING,
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
+ export var CoachmarkOverlay = /*#__PURE__*/forwardRef(function (_ref, ref) {
41
+ var children = _ref.children,
42
+ onClose = _ref.onClose,
43
+ fixedIsVisible = _ref.fixedIsVisible,
44
+ className = _ref.className,
45
+ _ref$kind = _ref.kind,
46
+ kind = _ref$kind === void 0 ? defaults.kind : _ref$kind,
47
+ _ref$theme = _ref.theme,
48
+ theme = _ref$theme === void 0 ? defaults.theme : _ref$theme,
49
+ rest = _objectWithoutProperties(_ref, _excluded);
50
+ var overlayRef = useRef();
51
+ var coachmark = useCoachmark();
52
+ var isBeacon = kind === COACHMARK_OVERLAY_KIND.TOOLTIP;
53
+ var isDraggable = kind === COACHMARK_OVERLAY_KIND.FLOATING;
54
+ var styledTune = {};
55
+ // TODO: check this... this feels like it should be in a hook with no dep array.
56
+ if (isBeacon || isDraggable) {
57
+ if (coachmark.targetRect) {
58
+ styledTune = {
59
+ left: coachmark.targetRect.x + window.scrollX,
60
+ top: coachmark.targetRect.y + window.scrollY
61
+ };
62
+ }
63
+ if (isBeacon) {
64
+ // Compensate for radius of beacon
65
+ styledTune.left += 16;
66
+ styledTune.top += 16;
67
+ } else if (isDraggable) {
68
+ // Compensate for width and height of target element
69
+ var offsetTune = getOffsetTune(coachmark, kind);
70
+ styledTune.left += offsetTune.left;
71
+ styledTune.top += offsetTune.top;
72
+ }
73
+ }
74
+ function handleDrag(movementX, movementY) {
75
+ var overlay = overlayRef.current;
76
+ var _overlay$getBoundingC = overlay.getBoundingClientRect(),
77
+ x = _overlay$getBoundingC.x,
78
+ y = _overlay$getBoundingC.y;
79
+ overlay.style.transform = 'none';
80
+ overlay.style.position = 'fixed';
81
+ overlay.style.left = "".concat(x + movementX, "px");
82
+ overlay.style.top = "".concat(y + movementY, "px");
83
+ overlay.style.bottom = 'auto';
84
+ }
85
+ return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
86
+ className: cx(blockClass, "".concat(blockClass, "--").concat(kind), "".concat(blockClass, "__").concat(theme), (isBeacon || isDraggable) && "".concat(blockClass, "--").concat(coachmark.align), fixedIsVisible && "".concat(blockClass, "--is-visible"), className),
87
+ ref: overlayRef,
88
+ style: styledTune
89
+ }, getDevtoolsProps(componentName)), isDraggable ? /*#__PURE__*/React.createElement(CoachmarkDragbar, {
90
+ onDrag: handleDrag,
91
+ onClose: onClose
92
+ }) : /*#__PURE__*/React.createElement(CoachmarkHeader, {
93
+ onClose: onClose
94
+ }), /*#__PURE__*/React.createElement("div", {
95
+ className: "".concat(blockClass, "__body"),
96
+ ref: ref
97
+ }, children), isBeacon && /*#__PURE__*/React.createElement("span", {
98
+ className: "".concat(blockClass, "__caret")
99
+ }));
100
+ });
101
+
102
+ // Return a placeholder if not released and not enabled by feature flag
103
+ CoachmarkOverlay = 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.node.isRequired,
118
+ /**
119
+ * Optional class name for this component.
120
+ */
121
+ className: PropTypes.string,
122
+ /**
123
+ * The visibility of CoachmarkOverlay is
124
+ * managed in the parent Coachmark component.
125
+ */
126
+ fixedIsVisible: PropTypes.bool.isRequired,
127
+ /**
128
+ * What kind or style of Coachmark to render.
129
+ */
130
+ kind: PropTypes.oneOf(Object.values(COACHMARK_OVERLAY_KIND)),
131
+ /**
132
+ * Function to call when the Coachmark closes.
133
+ */
134
+ onClose: PropTypes.func.isRequired,
135
+ /**
136
+ * Determines the theme of the component.
137
+ */
138
+ theme: PropTypes.oneOf(['light', 'dark'])
139
+ };