@carbon/ibm-products 1.55.2 → 1.57.0

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