@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,93 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["closeIconDescription", "onClose", "theme", "title"];
4
+ /**
5
+ * Copyright IBM Corp. 2023, 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, Idea16 } from '@carbon/icons-react';
18
+ import { Button } from 'carbon-components-react';
19
+ import { useCoachmark } from './utils/context';
20
+ import { getDevtoolsProps } from '../../global/js/utils/devtools';
21
+ import { pkg /*, carbon */ } from '../../settings';
22
+
23
+ // The block part of our conventional BEM class names (blockClass__E--M).
24
+ var blockClass = "".concat(pkg.prefix, "--coachmark-tagline");
25
+ var componentName = 'CoachmarkTagline';
26
+ var defaults = {
27
+ closeIconDescription: 'Close',
28
+ onClose: function onClose() {},
29
+ theme: 'light'
30
+ };
31
+
32
+ /**
33
+ * DO NOT USE. This component is for the exclusive use
34
+ * of other Novice to Pro components.
35
+ */
36
+ export var CoachmarkTagline = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
37
+ var _ref$closeIconDescrip = _ref.closeIconDescription,
38
+ closeIconDescription = _ref$closeIconDescrip === void 0 ? defaults.closeIconDescription : _ref$closeIconDescrip,
39
+ _ref$onClose = _ref.onClose,
40
+ onClose = _ref$onClose === void 0 ? defaults.onClose : _ref$onClose,
41
+ _ref$theme = _ref.theme,
42
+ theme = _ref$theme === void 0 ? defaults.theme : _ref$theme,
43
+ title = _ref.title,
44
+ rest = _objectWithoutProperties(_ref, _excluded);
45
+ var coachmark = useCoachmark();
46
+ return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
47
+ className: cx(blockClass, "".concat(blockClass, "__").concat(theme), coachmark.isOpen && "".concat(blockClass, "--is-open")),
48
+ ref: ref
49
+ }, getDevtoolsProps(componentName)), /*#__PURE__*/React.createElement("button", _extends({
50
+ // {...rest}
51
+ className: "".concat(blockClass, "__cta"),
52
+ type: "button"
53
+ }, coachmark.buttonProps), /*#__PURE__*/React.createElement("div", {
54
+ className: "".concat(blockClass, "__idea")
55
+ }, /*#__PURE__*/React.createElement(Idea16, null)), /*#__PURE__*/React.createElement("div", null, title)), /*#__PURE__*/React.createElement(Button, {
56
+ kind: "ghost",
57
+ size: "sm",
58
+ renderIcon: Close16,
59
+ iconDescription: closeIconDescription,
60
+ hasIconOnly: true,
61
+ className: "".concat(blockClass, "--close-btn"),
62
+ onClick: onClose
63
+ }));
64
+ });
65
+
66
+ // Return a placeholder if not released and not enabled by feature flag
67
+ CoachmarkTagline = pkg.checkComponentEnabled(CoachmarkTagline, componentName);
68
+
69
+ // The display name of the component, used by React. Note that displayName
70
+ // is used in preference to relying on function.name.
71
+ CoachmarkTagline.displayName = componentName;
72
+
73
+ // The types and DocGen commentary for the component props,
74
+ // in alphabetical order (for consistency).
75
+ // See https://www.npmjs.com/package/prop-types#usage.
76
+ CoachmarkTagline.propTypes = {
77
+ /**
78
+ * Tooltip text and aria label for the Close button icon.
79
+ */
80
+ closeIconDescription: PropTypes.string,
81
+ /**
82
+ * Function to call when the close button is clicked.
83
+ */
84
+ onClose: PropTypes.func,
85
+ /**
86
+ * Determines the theme of the component.
87
+ */
88
+ theme: PropTypes.oneOf(['light', 'dark']),
89
+ /**
90
+ * The title of the tagline.
91
+ */
92
+ title: PropTypes.string.isRequired
93
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright IBM Corp. 2023, 2023
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ export { Coachmark } from './Coachmark';
9
+ export { BEACON_KIND, COACHMARK_OVERLAY_KIND, COACHMARK_ALIGNMENT } from './utils/enums';
10
+ export { useCoachmark } from './utils/context';
@@ -0,0 +1,76 @@
1
+ import { COACHMARK_ALIGNMENT, COACHMARK_OVERLAY_KIND } from './enums';
2
+
3
+ /**
4
+ * If the coachmark's target is a link, button, etc. (i.e. not a beacon),
5
+ * this adjusts the coachmark's position based on the position and size of the target.
6
+ * @param {object} coachmark target reference
7
+ * @param {string} kind type of coachmark
8
+ * @returns {object} {top:number, left:number}
9
+ */
10
+
11
+ export var getOffsetTune = function getOffsetTune(coachmark, kind) {
12
+ // for future reference
13
+ // const coachmarkTarget = {
14
+ // x: coachmark.targetOffset.x,
15
+ // y: coachmark.targetOffset.y,
16
+ // width: coachmark.targetRect.width,
17
+ // height: coachmark.targetRect.height,
18
+ // };
19
+
20
+ var _coachmark$targetRect = coachmark.targetRect,
21
+ width = _coachmark$targetRect.width,
22
+ height = _coachmark$targetRect.height;
23
+ var distanceOffset = 24; // see also _coachmark-overlay.scss > $distance-offset
24
+ var top = 0;
25
+ var left = 0;
26
+ if (kind !== COACHMARK_OVERLAY_KIND.TOOLTIP) {
27
+ switch (coachmark.align) {
28
+ case COACHMARK_ALIGNMENT.TOP:
29
+ left = width / 2;
30
+ break;
31
+ case COACHMARK_ALIGNMENT.TOP_LEFT:
32
+ left = distanceOffset;
33
+ break;
34
+ case COACHMARK_ALIGNMENT.TOP_RIGHT:
35
+ left = width - distanceOffset;
36
+ break;
37
+ case COACHMARK_ALIGNMENT.BOTTOM:
38
+ top = height;
39
+ left = width / 2;
40
+ break;
41
+ case COACHMARK_ALIGNMENT.BOTTOM_LEFT:
42
+ top = height;
43
+ left = distanceOffset;
44
+ break;
45
+ case COACHMARK_ALIGNMENT.BOTTOM_RIGHT:
46
+ top = height;
47
+ left = width - distanceOffset;
48
+ break;
49
+ case COACHMARK_ALIGNMENT.LEFT:
50
+ top = height / 2;
51
+ break;
52
+ case COACHMARK_ALIGNMENT.LEFT_TOP:
53
+ top = distanceOffset;
54
+ break;
55
+ case COACHMARK_ALIGNMENT.LEFT_BOTTOM:
56
+ top = height - distanceOffset;
57
+ break;
58
+ case COACHMARK_ALIGNMENT.RIGHT:
59
+ top = height / 2;
60
+ left = width;
61
+ break;
62
+ case COACHMARK_ALIGNMENT.RIGHT_TOP:
63
+ top = distanceOffset;
64
+ left = width;
65
+ break;
66
+ case COACHMARK_ALIGNMENT.RIGHT_BOTTOM:
67
+ top = height - distanceOffset;
68
+ left = width;
69
+ break;
70
+ }
71
+ }
72
+ return {
73
+ top: top,
74
+ left: left
75
+ };
76
+ };
@@ -0,0 +1,5 @@
1
+ import { createContext, useContext } from 'react';
2
+ export var CoachmarkContext = /*#__PURE__*/createContext();
3
+ export var useCoachmark = function useCoachmark() {
4
+ return useContext(CoachmarkContext);
5
+ };
@@ -0,0 +1,40 @@
1
+ /* eslint-disable max-len */
2
+
3
+ /**
4
+ * Reserved for future expansion, i.e. "RING".
5
+ */
6
+ export var BEACON_KIND = {
7
+ DEFAULT: 'default'
8
+ };
9
+
10
+ /**
11
+ * Describes the style and behavior of a Coachmark.
12
+ * @param TOOLTIP includes a caret pointing to the animated beacon.
13
+ * @param FLOATING includes a drag handle across the top.
14
+ * @param FIXED is fixed to the bottom-right of the viewport.
15
+ * @param STACKED is fixed to the bottom-right of the viewport, includes links to show more, stackable Coachmarks if included.
16
+ */
17
+ export var COACHMARK_OVERLAY_KIND = {
18
+ TOOLTIP: 'tooltip',
19
+ FLOATING: 'floating',
20
+ FIXED: 'fixed',
21
+ STACKED: 'stacked'
22
+ };
23
+ /**
24
+ * Where to render the Coachmark relative to its target.
25
+ * Applies only to Floating and Tooltip Coachmarks.
26
+ */
27
+ export var COACHMARK_ALIGNMENT = {
28
+ BOTTOM: 'bottom',
29
+ BOTTOM_LEFT: 'bottom-left',
30
+ BOTTOM_RIGHT: 'bottom-right',
31
+ LEFT: 'left',
32
+ LEFT_TOP: 'left-top',
33
+ LEFT_BOTTOM: 'left-bottom',
34
+ RIGHT: 'right',
35
+ RIGHT_TOP: 'right-top',
36
+ RIGHT_BOTTOM: 'right-bottom',
37
+ TOP: 'top',
38
+ TOP_LEFT: 'top-left',
39
+ TOP_RIGHT: 'top-right'
40
+ };
@@ -0,0 +1,11 @@
1
+ /* eslint-disable max-len */
2
+
3
+ /**
4
+ * Clamp the given value between the upper bound `max` and the lower bound `min`
5
+ * @param {number} max
6
+ * @param {number} min
7
+ * @param {number} value
8
+ */
9
+ export function clamp(max, min, value) {
10
+ return Math.min(max, Math.max(min, value));
11
+ }
@@ -0,0 +1,54 @@
1
+ import { useEffect, useRef, useLayoutEffect } from 'react';
2
+ import { COACHMARK_OVERLAY_KIND } from './enums';
3
+
4
+ /**
5
+ * Detects when a user clicks outside of the element
6
+ * @param {object} coachmarkRef - The ref to the React element for the Coachmark to detect when the user clicks outside of its bounds.
7
+ * @param {object} overlayRef - The ref to the React element for the CoachmarkOverlay to detect when the user clicks outside of its bounds.
8
+ * @param {string} overlayKind - The overlayKind prop from the Coachmark. @see COACHMARK_OVERLAY_KIND
9
+ * @param {Function} callback The callback to call when the user mouses down.
10
+ */
11
+
12
+ function useClickOutsideElement(coachmarkRef, overlayRef, overlayKind, callback) {
13
+ var cb = useRef();
14
+ var isTooltip = overlayKind === COACHMARK_OVERLAY_KIND.TOOLTIP;
15
+ useLayoutEffect(function () {
16
+ cb.current = callback;
17
+ }, [callback]);
18
+ useEffect(function () {
19
+ function handleClickOutside(event) {
20
+ var isOverlayOutside = overlayRef.current && !overlayRef.current.contains(event.target);
21
+ var isOutsideCoachmark = coachmarkRef.current && !coachmarkRef.current.contains(event.target);
22
+ if (isOverlayOutside && isOutsideCoachmark) {
23
+ callCallback();
24
+ }
25
+ }
26
+ function callCallback() {
27
+ if (isTooltip) {
28
+ cb.current();
29
+ }
30
+ }
31
+ document.addEventListener('mousedown', handleClickOutside);
32
+ return function () {
33
+ document.removeEventListener('mousedown', handleClickOutside);
34
+ };
35
+ }, [coachmarkRef, overlayRef, isTooltip]);
36
+ }
37
+ var useWindowEvent = function useWindowEvent(eventName, callback) {
38
+ var savedCallback = useRef(null);
39
+ useEffect(function () {
40
+ savedCallback.current = callback;
41
+ });
42
+ useEffect(function () {
43
+ function handler(event) {
44
+ if (savedCallback.current) {
45
+ savedCallback.current(event);
46
+ }
47
+ }
48
+ window.addEventListener(eventName, handler);
49
+ return function () {
50
+ window.removeEventListener(eventName, handler);
51
+ };
52
+ }, [eventName]);
53
+ };
54
+ export { useClickOutsideElement, useWindowEvent };
@@ -0,0 +1,90 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["label", "className", "kind"];
4
+ /**
5
+ * Copyright IBM Corp. 2023, 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 { useCoachmark } from '../Coachmark';
18
+ import { getDevtoolsProps } from '../../global/js/utils/devtools';
19
+ import { pkg /*, carbon */ } from '../../settings';
20
+
21
+ // The block part of our conventional BEM class names (blockClass__E--M).
22
+ var blockClass = "".concat(pkg.prefix, "--coachmark-beacon");
23
+ var componentName = 'CoachmarkBeacon';
24
+ var defaults = {
25
+ kind: 'default'
26
+ };
27
+
28
+ /**
29
+ * Use beacon for the target prop of a Coachmark component.
30
+ */
31
+ export var CoachmarkBeacon = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
32
+ var _coachmark$positionTu, _coachmark$positionTu2, _coachmark$positionTu3, _coachmark$positionTu4;
33
+ var label = _ref.label,
34
+ className = _ref.className,
35
+ _ref$kind = _ref.kind,
36
+ kind = _ref$kind === void 0 ? defaults.kind : _ref$kind,
37
+ rest = _objectWithoutProperties(_ref, _excluded);
38
+ var coachmark = useCoachmark();
39
+ if (!coachmark) {
40
+ return /*#__PURE__*/React.createElement("div", null, "CoachmarkBeacon is to be use exclusively within the target prop of Coachmark");
41
+ }
42
+ var overlayPositionStyle = {
43
+ top: (_coachmark$positionTu = (_coachmark$positionTu2 = coachmark.positionTune) === null || _coachmark$positionTu2 === void 0 ? void 0 : _coachmark$positionTu2.y) !== null && _coachmark$positionTu !== void 0 ? _coachmark$positionTu : 0,
44
+ left: (_coachmark$positionTu3 = (_coachmark$positionTu4 = coachmark.positionTune) === null || _coachmark$positionTu4 === void 0 ? void 0 : _coachmark$positionTu4.x) !== null && _coachmark$positionTu3 !== void 0 ? _coachmark$positionTu3 : 0
45
+ };
46
+ return /*#__PURE__*/React.createElement("span", _extends({}, rest, {
47
+ className: cx(blockClass, "".concat(blockClass, "-").concat(kind), className),
48
+ ref: ref,
49
+ style: overlayPositionStyle
50
+ }, getDevtoolsProps(componentName)), /*#__PURE__*/React.createElement("button", _extends({
51
+ tabIndex: 0,
52
+ type: "button"
53
+ }, coachmark.buttonProps, {
54
+ "aria-label": label,
55
+ className: "".concat(blockClass, "__target")
56
+ }), /*#__PURE__*/React.createElement("svg", {
57
+ className: "".concat(blockClass, "__center")
58
+ }, /*#__PURE__*/React.createElement("circle", {
59
+ r: 1,
60
+ cx: 38,
61
+ cy: 38
62
+ }))));
63
+ });
64
+
65
+ // Return a placeholder if not released and not enabled by feature flag
66
+ CoachmarkBeacon = pkg.checkComponentEnabled(CoachmarkBeacon, componentName);
67
+
68
+ // The display name of the component, used by React. Note that displayName
69
+ // is used in preference to relying on function.name.
70
+ CoachmarkBeacon.displayName = componentName;
71
+
72
+ // The types and DocGen commentary for the component props,
73
+ // in alphabetical order (for consistency).
74
+ // See https://www.npmjs.com/package/prop-types#usage.
75
+ CoachmarkBeacon.propTypes = {
76
+ /**
77
+ * Optional class name for this component.
78
+ */
79
+ className: PropTypes.string,
80
+ /**
81
+ * What style of beacon.
82
+ * BEACON_KIND is an exported enum from the Coachmark and can be used for this value.
83
+ * @see {@link BEACON_KIND}
84
+ */
85
+ kind: PropTypes.oneOf(['default']),
86
+ /**
87
+ * The aria label.
88
+ */
89
+ label: PropTypes.string.isRequired
90
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright IBM Corp. 2023, 2023
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ export { CoachmarkBeacon } from './CoachmarkBeacon';
@@ -0,0 +1,72 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["className", "label"];
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 { Button } from 'carbon-components-react';
18
+ import { useCoachmark } from '../Coachmark';
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-button");
24
+ var componentName = 'CoachmarkButton';
25
+
26
+ /**
27
+ * Use CoachmarkButton for the target prop of a Coachmark component.
28
+ */
29
+ export var CoachmarkButton = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
30
+ var className = _ref.className,
31
+ label = _ref.label,
32
+ rest = _objectWithoutProperties(_ref, _excluded);
33
+ var coachmark = useCoachmark();
34
+ if (!coachmark) {
35
+ return /*#__PURE__*/React.createElement("div", null, "CoachmarkButton is to be use exclusively within the target prop of Coachmark");
36
+ }
37
+ return /*#__PURE__*/React.createElement(Button, _extends({}, rest, {
38
+ className: cx(blockClass,
39
+ // Apply the block class to the main HTML element
40
+ className,
41
+ // Apply any supplied class names to the main HTML element.
42
+ // example: `${blockClass}__template-string-class-${kind}-n-${size}`,
43
+ {
44
+ // switched classes dependant on props or state
45
+ // example: [`${blockClass}__here-if-small`]: size === 'sm',
46
+ }),
47
+ ref: ref,
48
+ role: "button",
49
+ "aria-label": label
50
+ }, getDevtoolsProps(componentName), coachmark.buttonProps), label);
51
+ });
52
+
53
+ // Return a placeholder if not released and not enabled by feature flag
54
+ CoachmarkButton = pkg.checkComponentEnabled(CoachmarkButton, componentName);
55
+
56
+ // The display name of the component, used by React. Note that displayName
57
+ // is used in preference to relying on function.name.
58
+ CoachmarkButton.displayName = componentName;
59
+
60
+ // The types and DocGen commentary for the component props,
61
+ // in alphabetical order (for consistency).
62
+ // See https://www.npmjs.com/package/prop-types#usage.
63
+ CoachmarkButton.propTypes = {
64
+ /**
65
+ * Provide an optional class to be applied to the containing node.
66
+ */
67
+ className: PropTypes.string,
68
+ /**
69
+ * The aria label.
70
+ */
71
+ label: PropTypes.string.isRequired
72
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright IBM Corp. 2023, 2023
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ export { CoachmarkButton } from './CoachmarkButton';
@@ -0,0 +1,201 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
+ var _excluded = ["children", "className", "onClose", "portalTarget", "tagline", "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, useRef, useState } from 'react';
14
+
15
+ // Other standard imports.
16
+ import PropTypes from 'prop-types';
17
+ import cx from 'classnames';
18
+ import { createPortal } from 'react-dom';
19
+ import { CoachmarkOverlay } from '../Coachmark/CoachmarkOverlay';
20
+ import { CoachmarkTagline } from '../Coachmark/CoachmarkTagline';
21
+ import { CoachmarkContext } from '../Coachmark/utils/context';
22
+ import { COACHMARK_OVERLAY_KIND } from '../Coachmark/utils/enums';
23
+ import { getDevtoolsProps } from '../../global/js/utils/devtools';
24
+ import { pkg /*, carbon */ } from '../../settings';
25
+
26
+ // The block part of our conventional BEM class names (blockClass__E--M).
27
+ var blockClass = "".concat(pkg.prefix, "--coachmark-fixed");
28
+ var componentName = 'CoachmarkFixed';
29
+ var defaults = {
30
+ onClose: function onClose() {},
31
+ theme: 'light',
32
+ tagline: ''
33
+ };
34
+
35
+ /**
36
+ * Fixed coachmarks are used to call out specific functionality or concepts
37
+ * within the UI that may not be intuitive but are important for the
38
+ * user to gain understanding of the product's main value and discover new use cases.
39
+ * This variant allows the a coachmark overlay to be displayed by interacting with the tagline.
40
+ */
41
+ export var CoachmarkFixed = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
42
+ var _document$querySelect;
43
+ var children = _ref.children,
44
+ className = _ref.className,
45
+ _ref$onClose = _ref.onClose,
46
+ onClose = _ref$onClose === void 0 ? defaults.onClose : _ref$onClose,
47
+ portalTarget = _ref.portalTarget,
48
+ _ref$tagline = _ref.tagline,
49
+ tagline = _ref$tagline === void 0 ? defaults.tagline : _ref$tagline,
50
+ _ref$theme = _ref.theme,
51
+ theme = _ref$theme === void 0 ? defaults.theme : _ref$theme,
52
+ rest = _objectWithoutProperties(_ref, _excluded);
53
+ var overlayRef = useRef();
54
+ var portalNode = portalTarget ? (_document$querySelect = document.querySelector(portalTarget)) !== null && _document$querySelect !== void 0 ? _document$querySelect : document.querySelector('body') : document.querySelector('body');
55
+ var _useState = useState(false),
56
+ _useState2 = _slicedToArray(_useState, 2),
57
+ isOpen = _useState2[0],
58
+ setIsOpen = _useState2[1];
59
+ var _useState3 = useState(false),
60
+ _useState4 = _slicedToArray(_useState3, 2),
61
+ shouldResetPosition = _useState4[0],
62
+ setShouldResetPosition = _useState4[1];
63
+ var _useState5 = useState(),
64
+ _useState6 = _slicedToArray(_useState5, 2),
65
+ targetRect = _useState6[0],
66
+ setTargetRect = _useState6[1];
67
+ var _useState7 = useState({
68
+ x: 0,
69
+ y: 0
70
+ }),
71
+ _useState8 = _slicedToArray(_useState7, 2),
72
+ targetOffset = _useState8[0],
73
+ setTargetOffset = _useState8[1];
74
+ var _useState9 = useState(false),
75
+ _useState10 = _slicedToArray(_useState9, 2),
76
+ fixedIsVisible = _useState10[0],
77
+ setFixedIsVisible = _useState10[1];
78
+ var handleClose = function handleClose() {
79
+ setFixedIsVisible(false);
80
+ };
81
+ var handleTransitionEnd = function handleTransitionEnd(e) {
82
+ if (e.propertyName === 'transform' && !fixedIsVisible) {
83
+ setIsOpen(false);
84
+ onClose();
85
+ }
86
+ };
87
+ var handleTargetClick = function handleTargetClick(e) {
88
+ setTargetRect(e.target.getBoundingClientRect());
89
+ setTargetOffset({
90
+ x: e.target.offsetLeft,
91
+ y: e.target.offsetTop
92
+ });
93
+ // reset position for all other kinds
94
+ setIsOpen(false);
95
+ setShouldResetPosition(true);
96
+ };
97
+ var contextValue = {
98
+ buttonProps: {
99
+ 'aria-expanded': isOpen,
100
+ onClick: handleTargetClick,
101
+ // Compensate for accidental open/close on double-click.
102
+ // Only open on double-click.
103
+ onDoubleClick: handleTargetClick
104
+ },
105
+ closeButtonProps: {
106
+ onClick: handleClose
107
+ },
108
+ targetRect: targetRect,
109
+ targetOffset: targetOffset,
110
+ isOpen: isOpen
111
+ };
112
+
113
+ // instead of toggling on/off,
114
+ // keep open and reset to original position
115
+ useEffect(function () {
116
+ if (shouldResetPosition) {
117
+ setShouldResetPosition(false);
118
+ setIsOpen(true);
119
+ }
120
+ }, [shouldResetPosition]);
121
+ useEffect(function () {
122
+ setFixedIsVisible(isOpen);
123
+ }, [isOpen]);
124
+
125
+ // On unmount:
126
+ // - DO NOT "Close()" the coachmark.
127
+ // - This triggers a "signal" to close it forever.
128
+ // - "Closing" should only ever be a user-triggered event.
129
+ // - DO "hide" the coachmark.
130
+ // - The app is doing the action for the user.
131
+ // - The user will have the opportunity to open it again.
132
+ useEffect(function () {
133
+ return function () {
134
+ return setIsOpen(false);
135
+ };
136
+ }, []);
137
+ return /*#__PURE__*/React.createElement(CoachmarkContext.Provider, {
138
+ value: contextValue
139
+ }, /*#__PURE__*/React.createElement("div", _extends({}, rest, {
140
+ className: cx(blockClass, // Apply the block class to the main HTML element
141
+ "".concat(blockClass, "__").concat(theme), className // Apply any supplied class names to the main HTML element.
142
+ ),
143
+
144
+ ref: ref
145
+ }, getDevtoolsProps(componentName)), /*#__PURE__*/React.createElement(CoachmarkTagline, {
146
+ title: tagline,
147
+ onClose: onClose
148
+ }), isOpen && /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement(CoachmarkOverlay, {
149
+ ref: overlayRef,
150
+ fixedIsVisible: fixedIsVisible,
151
+ kind: COACHMARK_OVERLAY_KIND.FIXED,
152
+ onClose: handleClose,
153
+ onTransitionEnd: handleTransitionEnd,
154
+ theme: theme
155
+ }, children), portalNode)));
156
+ });
157
+
158
+ // Return a placeholder if not released and not enabled by feature flag
159
+ CoachmarkFixed = pkg.checkComponentEnabled(CoachmarkFixed, componentName);
160
+
161
+ // The display name of the component, used by React. Note that displayName
162
+ // is used in preference to relying on function.name.
163
+ CoachmarkFixed.displayName = componentName;
164
+
165
+ // The types and DocGen commentary for the component props,
166
+ // in alphabetical order (for consistency).
167
+ // See https://www.npmjs.com/package/prop-types#usage.
168
+ CoachmarkFixed.propTypes = {
169
+ // TODO: Add this to MDX as will be done with Coachmark
170
+ /**
171
+ * CoachmarkFixed should use a single CoachmarkOverlayElements component as a child.
172
+ */
173
+ children: PropTypes.node.isRequired,
174
+ /**
175
+ * Optional class name for this component.
176
+ */
177
+ className: PropTypes.string,
178
+ /**
179
+ * Function to call when the Coachmark closes.
180
+ */
181
+ onClose: PropTypes.func,
182
+ /**
183
+ * By default, the Coachmark will be appended to the end of `document.body`.
184
+ * The Coachmark will remain persistent as the user navigates the app until
185
+ * the user closes the Coachmark.
186
+ *
187
+ * Alternatively, the app developer can tightly couple the Coachmark to a DOM
188
+ * element or other component by specifying a CSS selector. The Coachmark will
189
+ * remain visible as long as that element remains visible or mounted. When the
190
+ * element is hidden or component is unmounted, the Coachmark will disappear.
191
+ */
192
+ portalTarget: PropTypes.string,
193
+ /**
194
+ * The tagline title which will be fixed to the bottom right of the window and will serve as the display trigger.
195
+ */
196
+ tagline: PropTypes.string.isRequired,
197
+ /**
198
+ * Determines the theme of the component.
199
+ */
200
+ theme: PropTypes.oneOf(['light', 'dark'])
201
+ };