@carbon/ibm-products 1.61.0 → 1.62.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. package/css/index-full-carbon.css +154 -79
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +3 -3
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon-released-only.css +1753 -0
  6. package/css/index-without-carbon-released-only.css.map +1 -1
  7. package/css/index-without-carbon-released-only.min.css +3 -1
  8. package/css/index-without-carbon-released-only.min.css.map +1 -1
  9. package/css/index-without-carbon.css +154 -79
  10. package/css/index-without-carbon.css.map +1 -1
  11. package/css/index-without-carbon.min.css +3 -3
  12. package/css/index-without-carbon.min.css.map +1 -1
  13. package/css/index.css +154 -79
  14. package/css/index.css.map +1 -1
  15. package/css/index.min.css +3 -3
  16. package/css/index.min.css.map +1 -1
  17. package/es/components/Coachmark/Coachmark.js +17 -5
  18. package/es/components/Coachmark/CoachmarkDragbar.js +12 -5
  19. package/es/components/Coachmark/CoachmarkHeader.js +2 -1
  20. package/es/components/Coachmark/CoachmarkOverlay.js +105 -9
  21. package/es/components/CoachmarkBeacon/CoachmarkBeacon.js +5 -2
  22. package/es/components/CoachmarkFixed/CoachmarkFixed.js +26 -6
  23. package/es/components/CoachmarkOverlayElements/CoachmarkOverlayElements.js +28 -3
  24. package/es/components/CoachmarkStack/CoachmarkStack.js +19 -4
  25. package/es/components/CoachmarkStack/CoachmarkStackHome.js +45 -11
  26. package/es/components/Datagrid/Datagrid/DatagridContent.js +12 -9
  27. package/es/components/Datagrid/Datagrid/DatagridExpandedRow.js +4 -4
  28. package/es/components/Datagrid/Datagrid/DatagridHeaderRow.js +45 -73
  29. package/es/components/Datagrid/Datagrid/DatagridRefBody.js +4 -1
  30. package/es/components/Datagrid/Datagrid/DatagridRow.js +5 -2
  31. package/es/components/Datagrid/Datagrid/DatagridSelectAll.js +12 -11
  32. package/es/components/Datagrid/Datagrid/DatagridSimpleBody.js +4 -1
  33. package/es/components/Datagrid/Datagrid/DatagridToolbar.js +29 -23
  34. package/es/components/Datagrid/Datagrid/DatagridVirtualBody.js +18 -18
  35. package/es/components/Datagrid/Datagrid/addons/stateReducer.js +73 -24
  36. package/es/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +1 -1
  37. package/es/components/Datagrid/useActionsColumn.js +9 -9
  38. package/es/components/Datagrid/useColumnCenterAlign.js +6 -6
  39. package/es/components/Datagrid/useColumnRightAlign.js +6 -6
  40. package/es/components/Datagrid/useDatagrid.js +13 -1
  41. package/es/components/Datagrid/useFlexResize.js +19 -9
  42. package/es/components/Datagrid/useInfiniteScroll.js +10 -9
  43. package/es/components/Datagrid/useNestedRowExpander.js +10 -1
  44. package/es/components/Datagrid/useOnRowClick.js +6 -7
  45. package/es/components/Datagrid/useParentDimensions.js +6 -6
  46. package/es/components/Datagrid/useResizeTable.js +7 -7
  47. package/es/components/Datagrid/useRowExpander.js +11 -1
  48. package/es/components/Datagrid/useSelectAllToggle.js +2 -2
  49. package/es/components/Datagrid/useSelectRows.js +31 -21
  50. package/es/components/Datagrid/useSkeletonRows.js +6 -6
  51. package/es/components/Datagrid/useSortableColumns.js +5 -6
  52. package/es/components/Datagrid/useStickyColumn.js +13 -6
  53. package/es/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +1 -0
  54. package/es/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +1 -0
  55. package/es/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +1 -0
  56. package/es/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +1 -0
  57. package/es/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +1 -0
  58. package/es/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +1 -0
  59. package/es/components/EmptyStates/assets/ErrorIllustration.js +6 -4
  60. package/es/components/EmptyStates/assets/NoDataIllustration.js +6 -4
  61. package/es/components/EmptyStates/assets/NoTagsIllustration.js +6 -4
  62. package/es/components/EmptyStates/assets/NotFoundIllustration.js +6 -4
  63. package/es/components/EmptyStates/assets/NotificationsIllustration.js +6 -4
  64. package/es/components/EmptyStates/assets/UnauthorizedIllustration.js +6 -4
  65. package/es/components/Guidebanner/Guidebanner.js +3 -3
  66. package/es/components/Guidebanner/GuidebannerElement.js +9 -3
  67. package/es/components/Guidebanner/GuidebannerElementButton.js +9 -4
  68. package/es/components/Guidebanner/GuidebannerElementLink.js +9 -3
  69. package/es/components/InlineTip/InlineTipButton.js +7 -0
  70. package/es/components/InlineTip/InlineTipLink.js +7 -0
  71. package/es/components/index.js +2 -2
  72. package/es/global/js/hooks/index.js +3 -2
  73. package/es/global/js/hooks/usePrefix.js +11 -0
  74. package/es/global/js/package-settings.js +6 -2
  75. package/lib/components/Coachmark/Coachmark.js +16 -4
  76. package/lib/components/Coachmark/CoachmarkDragbar.js +12 -5
  77. package/lib/components/Coachmark/CoachmarkHeader.js +2 -1
  78. package/lib/components/Coachmark/CoachmarkOverlay.js +105 -8
  79. package/lib/components/CoachmarkBeacon/CoachmarkBeacon.js +5 -2
  80. package/lib/components/CoachmarkFixed/CoachmarkFixed.js +25 -5
  81. package/lib/components/CoachmarkOverlayElements/CoachmarkOverlayElements.js +28 -3
  82. package/lib/components/CoachmarkStack/CoachmarkStack.js +18 -3
  83. package/lib/components/CoachmarkStack/CoachmarkStackHome.js +44 -10
  84. package/lib/components/Datagrid/Datagrid/DatagridContent.js +12 -9
  85. package/lib/components/Datagrid/Datagrid/DatagridExpandedRow.js +4 -4
  86. package/lib/components/Datagrid/Datagrid/DatagridHeaderRow.js +44 -80
  87. package/lib/components/Datagrid/Datagrid/DatagridRefBody.js +4 -1
  88. package/lib/components/Datagrid/Datagrid/DatagridRow.js +5 -2
  89. package/lib/components/Datagrid/Datagrid/DatagridSelectAll.js +6 -4
  90. package/lib/components/Datagrid/Datagrid/DatagridSimpleBody.js +4 -1
  91. package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +29 -23
  92. package/lib/components/Datagrid/Datagrid/DatagridVirtualBody.js +12 -12
  93. package/lib/components/Datagrid/Datagrid/addons/stateReducer.js +75 -33
  94. package/lib/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +1 -1
  95. package/lib/components/Datagrid/useActionsColumn.js +9 -12
  96. package/lib/components/Datagrid/useDatagrid.js +13 -1
  97. package/lib/components/Datagrid/useFlexResize.js +19 -9
  98. package/lib/components/Datagrid/useInfiniteScroll.js +9 -9
  99. package/lib/components/Datagrid/useNestedRowExpander.js +10 -9
  100. package/lib/components/Datagrid/useOnRowClick.js +6 -7
  101. package/lib/components/Datagrid/useParentDimensions.js +5 -6
  102. package/lib/components/Datagrid/useResizeTable.js +6 -7
  103. package/lib/components/Datagrid/useRowExpander.js +11 -9
  104. package/lib/components/Datagrid/useSelectAllToggle.js +2 -2
  105. package/lib/components/Datagrid/useSelectRows.js +31 -21
  106. package/lib/components/Datagrid/useSkeletonRows.js +6 -6
  107. package/lib/components/Datagrid/useSortableColumns.js +5 -6
  108. package/lib/components/Datagrid/useStickyColumn.js +8 -0
  109. package/lib/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +1 -0
  110. package/lib/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +1 -0
  111. package/lib/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +1 -0
  112. package/lib/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +1 -0
  113. package/lib/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +1 -0
  114. package/lib/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +1 -0
  115. package/lib/components/EmptyStates/assets/ErrorIllustration.js +6 -4
  116. package/lib/components/EmptyStates/assets/NoDataIllustration.js +6 -4
  117. package/lib/components/EmptyStates/assets/NoTagsIllustration.js +6 -4
  118. package/lib/components/EmptyStates/assets/NotFoundIllustration.js +6 -4
  119. package/lib/components/EmptyStates/assets/NotificationsIllustration.js +6 -4
  120. package/lib/components/EmptyStates/assets/UnauthorizedIllustration.js +6 -4
  121. package/lib/components/Guidebanner/Guidebanner.js +3 -3
  122. package/lib/components/Guidebanner/GuidebannerElement.js +8 -1
  123. package/lib/components/Guidebanner/GuidebannerElementButton.js +8 -1
  124. package/lib/components/Guidebanner/GuidebannerElementLink.js +8 -1
  125. package/lib/components/InlineTip/InlineTipButton.js +8 -1
  126. package/lib/components/InlineTip/InlineTipLink.js +8 -1
  127. package/lib/components/index.js +30 -0
  128. package/lib/global/js/hooks/index.js +8 -1
  129. package/lib/global/js/hooks/usePrefix.js +19 -0
  130. package/lib/global/js/package-settings.js +6 -2
  131. package/package.json +2 -2
  132. package/scss/components/Checklist/_checklist.scss +13 -25
  133. package/scss/components/Coachmark/styles/_coachmark-dragbar.scss +1 -45
  134. package/scss/components/Coachmark/styles/_coachmark-header.scss +0 -33
  135. package/scss/components/Coachmark/styles/_coachmark-overlay.scss +113 -5
  136. package/scss/components/Coachmark/styles/_coachmark-tagline.scss +18 -0
  137. package/scss/components/CoachmarkBeacon/_coachmark-beacon.scss +16 -13
  138. package/scss/components/CoachmarkOverlayElement/_coachmark-overlay-element.scss +2 -0
  139. package/scss/components/CoachmarkOverlayElements/_coachmark-overlay-elements.scss +1 -0
  140. package/scss/components/CoachmarkStack/_coachmark-stack.scss +3 -0
  141. package/scss/components/Datagrid/_storybook-styles.scss +15 -0
  142. package/scss/components/Datagrid/styles/_datagrid.scss +31 -5
  143. package/scss/components/Datagrid/styles/_useNestedRows.scss +1 -1
  144. package/scss/components/_index-released-only.scss +1 -0
@@ -9,7 +9,7 @@ var _excluded = ["align", "children", "className", "onClose", "overlayClassName"
9
9
  * LICENSE file in the root directory of this source tree.
10
10
  */
11
11
 
12
- import React, { forwardRef, useEffect, useRef, useState } from 'react';
12
+ import React, { forwardRef, useEffect, useRef, useState, useCallback } from 'react';
13
13
  import cx from 'classnames';
14
14
  import PropTypes, { Component } from 'prop-types';
15
15
  import { createPortal } from 'react-dom';
@@ -22,6 +22,7 @@ import { pkg /*, carbon */ } from '../../settings';
22
22
  import { throttle } from 'lodash';
23
23
  // The block part of our conventional BEM class names (blockClass__E--M).
24
24
  var blockClass = "".concat(pkg.prefix, "--coachmark");
25
+ var overlayBlockClass = "".concat(blockClass, "-overlay");
25
26
  var componentName = 'Coachmark';
26
27
  var defaults = {
27
28
  align: 'bottom',
@@ -83,7 +84,18 @@ export var Coachmark = /*#__PURE__*/forwardRef(function (_ref, ref) {
83
84
  var closeOverlay = function closeOverlay() {
84
85
  setIsOpen(false);
85
86
  };
86
- var handleClose = function handleClose() {
87
+ var escFunction = useCallback(function (event) {
88
+ if (event.key === 'Escape') {
89
+ handleClose();
90
+ }
91
+ }, [handleClose]);
92
+ useEffect(function () {
93
+ document.addEventListener('keydown', escFunction, false);
94
+ return function () {
95
+ document.removeEventListener('keydown', escFunction, false);
96
+ };
97
+ }, [escFunction]);
98
+ var handleClose = useCallback(function () {
87
99
  if (isStacked) {
88
100
  // If stacked, do not unmount,
89
101
  // only call its ("parent") onClose method.
@@ -92,7 +104,7 @@ export var Coachmark = /*#__PURE__*/forwardRef(function (_ref, ref) {
92
104
  setIsOpen(false);
93
105
  onClose();
94
106
  }
95
- };
107
+ }, [isStacked, onClose]);
96
108
  var handleTargetClick = function handleTargetClick(e) {
97
109
  setTargetRect(e.target.getBoundingClientRect());
98
110
  setTargetOffset({
@@ -113,6 +125,7 @@ export var Coachmark = /*#__PURE__*/forwardRef(function (_ref, ref) {
113
125
  var contextValue = {
114
126
  buttonProps: {
115
127
  'aria-expanded': isOpen,
128
+ tabIndex: 0,
116
129
  onClick: handleTargetClick,
117
130
  // Compensate for accidental open/close on double-click.
118
131
  // Only open on double-click.
@@ -164,7 +177,7 @@ export var Coachmark = /*#__PURE__*/forwardRef(function (_ref, ref) {
164
177
  kind: overlayKind,
165
178
  onClose: handleClose,
166
179
  theme: theme,
167
- className: overlayClassName
180
+ className: cx(overlayClassName, "".concat(overlayBlockClass, "--is-visible"))
168
181
  }, children), portalNode)));
169
182
  });
170
183
 
@@ -185,7 +198,6 @@ Coachmark.propTypes = {
185
198
  * @see COACHMARK_ALIGNMENT
186
199
  */
187
200
  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
201
  /**
190
202
  * Coachmark should use a single CoachmarkOverlayElements component as a child.
191
203
  * @see CoachmarkOverlayElements
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
- var _excluded = ["closeIconDescription", "onClose", "onDrag", "showCloseButton", "theme"];
4
+ var _excluded = ["a11yKeyboardHandler", "closeIconDescription", "onClose", "onDrag", "showCloseButton", "theme"];
5
5
  /**
6
6
  * Copyright IBM Corp. 2023, 2023
7
7
  *
@@ -25,6 +25,7 @@ import { pkg /*, carbon */ } from '../../settings';
25
25
 
26
26
  // The block part of our conventional BEM class names (blockClass__E--M).
27
27
  var blockClass = "".concat(pkg.prefix, "--coachmark-dragbar");
28
+ var overlayBlockClass = "".concat(pkg.prefix, "--coachmark-overlay");
28
29
  var componentName = 'CoachmarkDragbar';
29
30
  var defaults = {
30
31
  closeIconDescription: 'Close',
@@ -39,7 +40,8 @@ var defaults = {
39
40
  * of other Novice to Pro components.
40
41
  */
41
42
  export var CoachmarkDragbar = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
42
- var _ref$closeIconDescrip = _ref.closeIconDescription,
43
+ var a11yKeyboardHandler = _ref.a11yKeyboardHandler,
44
+ _ref$closeIconDescrip = _ref.closeIconDescription,
43
45
  closeIconDescription = _ref$closeIconDescrip === void 0 ? defaults.closeIconDescription : _ref$closeIconDescrip,
44
46
  _ref$onClose = _ref.onClose,
45
47
  onClose = _ref$onClose === void 0 ? defaults.onClose : _ref$onClose,
@@ -89,15 +91,16 @@ export var CoachmarkDragbar = /*#__PURE__*/React.forwardRef(function (_ref, ref)
89
91
  // role="main"
90
92
  }, getDevtoolsProps(componentName)), /*#__PURE__*/React.createElement("button", {
91
93
  type: "button",
92
- className: "".concat(blockClass, "__handle"),
93
- onMouseDown: handleDragStart
94
+ className: "".concat(overlayBlockClass, "__handle"),
95
+ onMouseDown: handleDragStart,
96
+ onKeyDown: a11yKeyboardHandler
94
97
  }, /*#__PURE__*/React.createElement(Draggable16, null)), showCloseButton && /*#__PURE__*/React.createElement(Button, {
95
98
  kind: "ghost",
96
99
  size: "sm",
97
100
  renderIcon: Close16,
98
101
  iconDescription: closeIconDescription,
99
102
  hasIconOnly: true,
100
- className: "".concat(blockClass, "--close-btn"),
103
+ className: "".concat(overlayBlockClass, "--close-btn"),
101
104
  onClick: onClose
102
105
  }));
103
106
  });
@@ -113,6 +116,10 @@ CoachmarkDragbar.displayName = componentName;
113
116
  // in alphabetical order (for consistency).
114
117
  // See https://www.npmjs.com/package/prop-types#usage.
115
118
  CoachmarkDragbar.propTypes = {
119
+ /**
120
+ * Handler to manage keyboard interactions with the dragbar.
121
+ */
122
+ a11yKeyboardHandler: PropTypes.func.isRequired,
116
123
  /**
117
124
  * Tooltip text and aria label for the Close button icon.
118
125
  */
@@ -21,6 +21,7 @@ import { pkg /*, carbon */ } from '../../settings';
21
21
 
22
22
  // The block part of our conventional BEM class names (blockClass__E--M).
23
23
  var blockClass = "".concat(pkg.prefix, "--coachmark-header");
24
+ var overlayBlockClass = "".concat(pkg.prefix, "--coachmark-overlay");
24
25
  var componentName = 'CoachmarkHeader';
25
26
  var defaults = {
26
27
  closeIconDescription: 'Close',
@@ -53,7 +54,7 @@ export var CoachmarkHeader = /*#__PURE__*/React.forwardRef(function (_ref, ref)
53
54
  renderIcon: Close16,
54
55
  iconDescription: closeIconDescription,
55
56
  hasIconOnly: true,
56
- className: "".concat(blockClass, "--close-btn"),
57
+ className: "".concat(overlayBlockClass, "--close-btn"),
57
58
  onClick: onClose
58
59
  }));
59
60
  });
@@ -1,4 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
4
  var _excluded = ["children", "onClose", "fixedIsVisible", "className", "kind", "theme"];
4
5
  /**
@@ -9,8 +10,8 @@ var _excluded = ["children", "onClose", "fixedIsVisible", "className", "kind", "
9
10
  */
10
11
 
11
12
  // Import portions of React that are needed.
12
- import React, { forwardRef, useRef } from 'react';
13
-
13
+ import React, { forwardRef, useRef, useState, useEffect } from 'react';
14
+ import uuidv4 from '../../global/js/utils/uuidv4';
14
15
  // Other standard imports.
15
16
  import PropTypes from 'prop-types';
16
17
  import cx from 'classnames';
@@ -47,12 +48,46 @@ export var CoachmarkOverlay = /*#__PURE__*/forwardRef(function (_ref, ref) {
47
48
  _ref$theme = _ref.theme,
48
49
  theme = _ref$theme === void 0 ? defaults.theme : _ref$theme,
49
50
  rest = _objectWithoutProperties(_ref, _excluded);
51
+ var _useWindowDimensions = useWindowDimensions(),
52
+ winHeight = _useWindowDimensions.winHeight,
53
+ winWidth = _useWindowDimensions.winWidth;
54
+ var _useState = useState(false),
55
+ _useState2 = _slicedToArray(_useState, 2),
56
+ a11yDragMode = _useState2[0],
57
+ setA11yDragMode = _useState2[1];
50
58
  var overlayRef = useRef();
51
59
  var coachmark = useCoachmark();
52
60
  var isBeacon = kind === COACHMARK_OVERLAY_KIND.TOOLTIP;
53
61
  var isDraggable = kind === COACHMARK_OVERLAY_KIND.FLOATING;
62
+ var isVisible = className && className.includes('is-visible');
63
+ var handleKeyPress = function handleKeyPress(event) {
64
+ var shiftKey = event.shiftKey,
65
+ key = event.key;
66
+ if (key === 'Enter' || key === ' ') {
67
+ setA11yDragMode(function (prevVal) {
68
+ return !prevVal;
69
+ });
70
+ } else if (a11yDragMode) {
71
+ var distanceToMove = shiftKey ? 128 : 32;
72
+ switch (key) {
73
+ case 'ArrowLeft':
74
+ handleDrag(distanceToMove * -1, 0);
75
+ break;
76
+ case 'ArrowRight':
77
+ handleDrag(distanceToMove, 0);
78
+ break;
79
+ case 'ArrowUp':
80
+ handleDrag(0, distanceToMove * -1);
81
+ break;
82
+ case 'ArrowDown':
83
+ handleDrag(0, distanceToMove);
84
+ break;
85
+ default:
86
+ break;
87
+ }
88
+ }
89
+ };
54
90
  var styledTune = {};
55
- // TODO: check this... this feels like it should be in a hook with no dep array.
56
91
  if (isBeacon || isDraggable) {
57
92
  if (coachmark.targetRect) {
58
93
  styledTune = {
@@ -71,33 +106,94 @@ export var CoachmarkOverlay = /*#__PURE__*/forwardRef(function (_ref, ref) {
71
106
  styledTune.top += offsetTune.top;
72
107
  }
73
108
  }
109
+ function handleDragBounds(x, y) {
110
+ var xRes = x;
111
+ var yRes = y;
112
+ var xMax = winWidth - 288;
113
+ var yMax = winHeight - 150;
114
+ if (xRes < 0) {
115
+ xRes = 0;
116
+ } else if (xRes > xMax) {
117
+ xRes = xMax;
118
+ }
119
+ if (yRes < 0) {
120
+ yRes = 0;
121
+ } else if (yRes > yMax) {
122
+ yRes = yMax;
123
+ }
124
+ return {
125
+ targetX: xRes,
126
+ targetY: yRes
127
+ };
128
+ }
74
129
  function handleDrag(movementX, movementY) {
75
130
  var overlay = overlayRef.current;
76
131
  var _overlay$getBoundingC = overlay.getBoundingClientRect(),
77
132
  x = _overlay$getBoundingC.x,
78
133
  y = _overlay$getBoundingC.y;
134
+ var _handleDragBounds = handleDragBounds(x + movementX, y + movementY),
135
+ targetX = _handleDragBounds.targetX,
136
+ targetY = _handleDragBounds.targetY;
79
137
  overlay.style.transform = 'none';
80
138
  overlay.style.position = 'fixed';
81
- overlay.style.left = "".concat(x + movementX, "px");
82
- overlay.style.top = "".concat(y + movementY, "px");
139
+ overlay.style.left = "".concat(targetX, "px");
140
+ overlay.style.top = "".concat(targetY, "px");
83
141
  overlay.style.bottom = 'auto';
84
142
  }
143
+ var contentId = uuidv4();
85
144
  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),
145
+ className: cx(blockClass, "".concat(blockClass, "--").concat(kind), "".concat(blockClass, "__").concat(theme), (isBeacon || isDraggable) && "".concat(blockClass, "--").concat(coachmark.align), fixedIsVisible && "".concat(blockClass, "--is-visible"), a11yDragMode && "".concat(blockClass, "--is-dragmode"), className),
87
146
  ref: overlayRef,
88
- style: styledTune
147
+ style: styledTune,
148
+ "aria-labelledby": contentId,
149
+ tabIndex: -1
89
150
  }, getDevtoolsProps(componentName)), isDraggable ? /*#__PURE__*/React.createElement(CoachmarkDragbar, {
151
+ a11yKeyboardHandler: handleKeyPress,
152
+ onBlur: function onBlur() {
153
+ return setA11yDragMode(false);
154
+ },
90
155
  onDrag: handleDrag,
156
+ theme: theme,
91
157
  onClose: onClose
92
158
  }) : /*#__PURE__*/React.createElement(CoachmarkHeader, {
93
159
  onClose: onClose
94
160
  }), /*#__PURE__*/React.createElement("div", {
95
161
  className: "".concat(blockClass, "__body"),
96
- ref: ref
97
- }, children), isBeacon && /*#__PURE__*/React.createElement("span", {
162
+ ref: ref,
163
+ id: contentId
164
+ }, React.Children.map(children, function (child) {
165
+ return /*#__PURE__*/React.cloneElement(child, {
166
+ isVisible: isVisible
167
+ });
168
+ })), isBeacon && /*#__PURE__*/React.createElement("span", {
98
169
  className: "".concat(blockClass, "__caret")
99
170
  }));
100
171
  });
172
+ function getWindowDimensions() {
173
+ var _window = window,
174
+ winWidth = _window.innerWidth,
175
+ winHeight = _window.innerHeight;
176
+ return {
177
+ winWidth: winWidth,
178
+ winHeight: winHeight
179
+ };
180
+ }
181
+ var useWindowDimensions = function useWindowDimensions() {
182
+ var _useState3 = useState(getWindowDimensions()),
183
+ _useState4 = _slicedToArray(_useState3, 2),
184
+ windowDimensions = _useState4[0],
185
+ setWindowDimensions = _useState4[1];
186
+ useEffect(function () {
187
+ function handleResize() {
188
+ setWindowDimensions(getWindowDimensions());
189
+ }
190
+ window.addEventListener('resize', handleResize);
191
+ return function () {
192
+ return window.removeEventListener('resize', handleResize);
193
+ };
194
+ }, []);
195
+ return windowDimensions;
196
+ };
101
197
 
102
198
  // Return a placeholder if not released and not enabled by feature flag
103
199
  CoachmarkOverlay = pkg.checkComponentEnabled(CoachmarkOverlay, componentName);
@@ -47,14 +47,17 @@ export var CoachmarkBeacon = /*#__PURE__*/React.forwardRef(function (_ref, ref)
47
47
  className: cx(blockClass, "".concat(blockClass, "-").concat(kind), className),
48
48
  ref: ref,
49
49
  style: overlayPositionStyle
50
- }, getDevtoolsProps(componentName)), /*#__PURE__*/React.createElement("button", _extends({
50
+ }, getDevtoolsProps(componentName), {
51
+ role: "tooltip"
52
+ }), /*#__PURE__*/React.createElement("button", _extends({
51
53
  tabIndex: 0,
52
54
  type: "button"
53
55
  }, coachmark.buttonProps, {
54
56
  "aria-label": label,
55
57
  className: "".concat(blockClass, "__target")
56
58
  }), /*#__PURE__*/React.createElement("svg", {
57
- className: "".concat(blockClass, "__center")
59
+ className: "".concat(blockClass, "__center"),
60
+ alt: ""
58
61
  }, /*#__PURE__*/React.createElement("circle", {
59
62
  r: 1,
60
63
  cx: 38,
@@ -10,7 +10,7 @@ var _excluded = ["children", "className", "onClose", "portalTarget", "tagline",
10
10
  */
11
11
 
12
12
  // Import portions of React that are needed.
13
- import React, { useEffect, useRef, useState } from 'react';
13
+ import React, { useEffect, useRef, useState, useCallback } from 'react';
14
14
 
15
15
  // Other standard imports.
16
16
  import PropTypes from 'prop-types';
@@ -24,7 +24,9 @@ import { getDevtoolsProps } from '../../global/js/utils/devtools';
24
24
  import { pkg /*, carbon */ } from '../../settings';
25
25
 
26
26
  // The block part of our conventional BEM class names (blockClass__E--M).
27
- var blockClass = "".concat(pkg.prefix, "--coachmark-fixed");
27
+ var coachmarkClass = "".concat(pkg.prefix, "--coachmark");
28
+ var blockClass = "".concat(coachmarkClass, "-fixed");
29
+ var overlayBlockClass = "".concat(coachmarkClass, "-overlay");
28
30
  var componentName = 'CoachmarkFixed';
29
31
  var defaults = {
30
32
  onClose: function onClose() {},
@@ -75,9 +77,14 @@ export var CoachmarkFixed = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
75
77
  _useState10 = _slicedToArray(_useState9, 2),
76
78
  fixedIsVisible = _useState10[0],
77
79
  setFixedIsVisible = _useState10[1];
78
- var handleClose = function handleClose() {
79
- setFixedIsVisible(false);
80
- };
80
+ var prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
81
+ var handleClose = useCallback(function () {
82
+ if (prefersReducedMotion.matches) {
83
+ setIsOpen(false);
84
+ } else {
85
+ setFixedIsVisible(false);
86
+ }
87
+ }, [prefersReducedMotion.matches]);
81
88
  var handleTransitionEnd = function handleTransitionEnd(e) {
82
89
  if (e.propertyName === 'transform' && !fixedIsVisible) {
83
90
  setIsOpen(false);
@@ -94,9 +101,21 @@ export var CoachmarkFixed = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
94
101
  setIsOpen(false);
95
102
  setShouldResetPosition(true);
96
103
  };
104
+ var escFunction = useCallback(function (event) {
105
+ if (event.key === 'Escape') {
106
+ handleClose();
107
+ }
108
+ }, [handleClose]);
109
+ useEffect(function () {
110
+ document.addEventListener('keydown', escFunction, false);
111
+ return function () {
112
+ document.removeEventListener('keydown', escFunction, false);
113
+ };
114
+ }, [escFunction]);
97
115
  var contextValue = {
98
116
  buttonProps: {
99
117
  'aria-expanded': isOpen,
118
+ tabIndex: 0,
100
119
  onClick: handleTargetClick,
101
120
  // Compensate for accidental open/close on double-click.
102
121
  // Only open on double-click.
@@ -151,7 +170,8 @@ export var CoachmarkFixed = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
151
170
  kind: COACHMARK_OVERLAY_KIND.FIXED,
152
171
  onClose: handleClose,
153
172
  onTransitionEnd: handleTransitionEnd,
154
- theme: theme
173
+ theme: theme,
174
+ className: cx(fixedIsVisible && "".concat(overlayBlockClass, "--is-visible"), overlayBlockClass)
155
175
  }, children), portalNode)));
156
176
  });
157
177
 
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
- var _excluded = ["className", "children", "media", "nextButtonText", "previousButtonLabel", "closeButtonLabel"];
4
+ var _excluded = ["className", "children", "isVisible", "media", "nextButtonText", "previousButtonLabel", "closeButtonLabel"];
5
5
  /**
6
6
  * Copyright IBM Corp. 2023, 2023
7
7
  *
@@ -27,6 +27,7 @@ import { pkg /*, carbon */ } from '../../settings';
27
27
  var blockClass = "".concat(pkg.prefix, "--coachmark-overlay-elements");
28
28
  var componentName = 'CoachmarkOverlayElements';
29
29
  var defaults = {
30
+ isVisible: false,
30
31
  nextButtonText: 'Next',
31
32
  previousButtonLabel: 'Back',
32
33
  closeButtonLabel: 'Got it'
@@ -39,6 +40,8 @@ var defaults = {
39
40
  export var CoachmarkOverlayElements = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
40
41
  var className = _ref.className,
41
42
  children = _ref.children,
43
+ _ref$isVisible = _ref.isVisible,
44
+ isVisible = _ref$isVisible === void 0 ? defaults.isVisible : _ref$isVisible,
42
45
  media = _ref.media,
43
46
  _ref$nextButtonText = _ref.nextButtonText,
44
47
  nextButtonText = _ref$nextButtonText === void 0 ? defaults.nextButtonText : _ref$nextButtonText,
@@ -56,8 +59,16 @@ export var CoachmarkOverlayElements = /*#__PURE__*/React.forwardRef(function (_r
56
59
  var _useState3 = useState(0),
57
60
  _useState4 = _slicedToArray(_useState3, 2),
58
61
  currentProgStep = _useState4[0],
59
- setCurrentProgStep = _useState4[1];
62
+ _setCurrentProgStep = _useState4[1];
60
63
  var coachmark = useCoachmark();
64
+ var setCurrentProgStep = function setCurrentProgStep(value) {
65
+ if (currentProgStep > 0 && value === 0 && buttonFocusRef.current) {
66
+ setTimeout(function () {
67
+ buttonFocusRef.current.focus();
68
+ }, 1000);
69
+ }
70
+ _setCurrentProgStep(value);
71
+ };
61
72
  var numProgSteps = Children.count(children);
62
73
  var progStepFloor = 0;
63
74
  var progStepCeil = numProgSteps - 1;
@@ -68,6 +79,13 @@ export var CoachmarkOverlayElements = /*#__PURE__*/React.forwardRef(function (_r
68
79
  buttonFocusRef.current.focus();
69
80
  }
70
81
  }, []);
82
+ useEffect(function () {
83
+ setTimeout(function () {
84
+ if (buttonFocusRef.current && isVisible) {
85
+ buttonFocusRef.current.focus();
86
+ }
87
+ }, 100);
88
+ }, [isVisible]);
71
89
  if (!coachmark) {
72
90
  return pconsole.warn("The ".concat(componentName, " is a composable container element which should be used only within the scope of a Coachmark or a CoachmarkFixed component."));
73
91
  }
@@ -91,7 +109,9 @@ export var CoachmarkOverlayElements = /*#__PURE__*/React.forwardRef(function (_r
91
109
  className: cx("".concat(blockClass, "__footer"), 'coachmark-carousel-controls')
92
110
  }, /*#__PURE__*/React.createElement(Button, _extends({
93
111
  size: "sm"
94
- }, coachmark.closeButtonProps), closeButtonLabel))) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Carousel, {
112
+ }, coachmark.closeButtonProps, {
113
+ ref: buttonFocusRef
114
+ }), closeButtonLabel))) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Carousel, {
95
115
  disableArrowScroll: true,
96
116
  ref: scrollRef
97
117
  }, children), /*#__PURE__*/React.createElement("div", {
@@ -154,6 +174,11 @@ CoachmarkOverlayElements.propTypes = {
154
174
  * The label for the Close button.
155
175
  */
156
176
  closeButtonLabel: PropTypes.string,
177
+ /**
178
+ * The visibility of CoachmarkOverlayElements is
179
+ * managed in the parent component.
180
+ */
181
+ isVisible: PropTypes.bool,
157
182
  /**
158
183
  * The object describing an image in one of two shapes.
159
184
  * If a single media element is required, use `{render}`.
@@ -9,7 +9,7 @@ var _excluded = ["children", "className", "onClose", "description", "media", "na
9
9
  * LICENSE file in the root directory of this source tree.
10
10
  */
11
11
 
12
- import React, { Children, useEffect, useRef, useState } from 'react';
12
+ import React, { Children, useEffect, useRef, useState, useCallback } from 'react';
13
13
  import { createPortal } from 'react-dom';
14
14
  import PropTypes from 'prop-types';
15
15
  import cx from 'classnames';
@@ -88,7 +88,18 @@ export var CoachmarkStack = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
88
88
  var handleClickNavItem = function handleClickNavItem(itemNumber) {
89
89
  setSelectedItemNumber(itemNumber);
90
90
  };
91
- var handleClose = function handleClose(isParentCloseButton) {
91
+ var escFunction = useCallback(function (event) {
92
+ if (event.key === 'Escape') {
93
+ selectedItemNumber === 0 ? handleClose(true) : handleClose(false);
94
+ }
95
+ }, [handleClose, selectedItemNumber]);
96
+ useEffect(function () {
97
+ document.addEventListener('keydown', escFunction, false);
98
+ return function () {
99
+ document.removeEventListener('keydown', escFunction, false);
100
+ };
101
+ }, [escFunction]);
102
+ var handleClose = useCallback(function (isParentCloseButton) {
92
103
  if (isParentCloseButton) {
93
104
  // Trigger slide-out animation
94
105
  setSelectedItemNumber(-1);
@@ -105,9 +116,10 @@ export var CoachmarkStack = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
105
116
  // Unstack child
106
117
  setSelectedItemNumber(0);
107
118
  }
108
- };
119
+ }, [onClose]);
109
120
  var contextValue = {
110
121
  buttonProps: {
122
+ tabIndex: 0,
111
123
  'aria-expanded': isOpen,
112
124
  onClick: function onClick() {
113
125
  setIsOpen(true);
@@ -134,7 +146,7 @@ export var CoachmarkStack = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
134
146
  useEffect(function () {
135
147
  setTimeout(function () {
136
148
  if (stackHomeRef.current) {
137
- setParentHeight(stackHomeRef.current.clientHeight);
149
+ setParentHeight(stackHomeRef.current.clientHeight + 16);
138
150
  }
139
151
  }, 0);
140
152
  }, [stackHomeRef]);
@@ -145,10 +157,12 @@ export var CoachmarkStack = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
145
157
  }
146
158
  stackHomeRef.current.style.height = "".concat(parentHeight, "px");
147
159
  if (!isOpen || targetSelectedItem < 0) {
160
+ stackHomeRef.current.focus();
148
161
  return;
149
162
  }
150
163
  var targetHomeHeight = stackedCoachmarkRefs.current[targetSelectedItem].clientHeight;
151
164
  stackHomeRef.current.style.height = "".concat(targetHomeHeight, "px");
165
+ stackedCoachmarkRefs.current[targetSelectedItem].focus();
152
166
  }, [selectedItemNumber, isOpen, parentHeight]);
153
167
  var wrappedChildren = Children.map(childArray, function (child, idx) {
154
168
  var mountedClass = mountedRef.current ? "".concat(elementBlockClass, "--is-mounted") : '';
@@ -177,6 +191,7 @@ export var CoachmarkStack = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
177
191
  }), /*#__PURE__*/React.createElement(CoachmarkStackHome, {
178
192
  ref: stackHomeRef,
179
193
  className: cx("".concat(pkg.prefix, "--coachmark-overlay"), "".concat(pkg.prefix, "--coachmark-overlay__").concat(theme), elementBlockClass, selectedItemNumber > 0 && "".concat(elementBlockClass, "--is-stacked"), selectedItemNumber > 0 && "".concat(elementBlockClass, "--is-stacked__").concat(theme), isOpen && "".concat(elementBlockClass, "--is-visible"), mountedRef.current && "".concat(elementBlockClass, "--is-mounted")),
194
+ isOpen: isOpen && selectedItemNumber < 1,
180
195
  description: description,
181
196
  media: media,
182
197
  navLinkLabels: navLinkLabels,
@@ -1,6 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- var _excluded = ["className", "description", "media", "navLinkLabels", "onClickNavItem", "onClose", "portalTarget", "closeButtonLabel", "title"];
4
+ var _excluded = ["className", "description", "isOpen", "media", "navLinkLabels", "onClickNavItem", "onClose", "portalTarget", "closeButtonLabel", "title"];
4
5
  /**
5
6
  * Copyright IBM Corp. 2023, 2023
6
7
  *
@@ -8,7 +9,7 @@ var _excluded = ["className", "description", "media", "navLinkLabels", "onClickN
8
9
  * LICENSE file in the root directory of this source tree.
9
10
  */
10
11
 
11
- import React, { forwardRef } from 'react';
12
+ import React, { forwardRef, useRef, useEffect, useState } from 'react';
12
13
  import pconsole from '../../global/js/utils/pconsole';
13
14
  import PropTypes from 'prop-types';
14
15
  import cx from 'classnames';
@@ -36,14 +37,27 @@ export var CoachmarkStackHome = /*#__PURE__*/forwardRef(function (_ref, ref) {
36
37
  var _document$querySelect;
37
38
  var className = _ref.className,
38
39
  description = _ref.description,
40
+ isOpen = _ref.isOpen,
39
41
  media = _ref.media,
40
42
  navLinkLabels = _ref.navLinkLabels,
41
43
  onClickNavItem = _ref.onClickNavItem,
42
- onClose = _ref.onClose,
44
+ _onClose = _ref.onClose,
43
45
  portalTarget = _ref.portalTarget,
44
46
  closeButtonLabel = _ref.closeButtonLabel,
45
47
  title = _ref.title,
46
48
  rest = _objectWithoutProperties(_ref, _excluded);
49
+ var buttonFocusRef = useRef();
50
+ var _useState = useState(0),
51
+ _useState2 = _slicedToArray(_useState, 2),
52
+ linkFocusIndex = _useState2[0],
53
+ setLinkFocusIndex = _useState2[1];
54
+ useEffect(function () {
55
+ setTimeout(function () {
56
+ if (isOpen && buttonFocusRef.current) {
57
+ buttonFocusRef.current.focus();
58
+ }
59
+ }, 100);
60
+ }, [isOpen]);
47
61
  if (!navLinkLabels) {
48
62
  return pconsole.warn("".concat(componentName, " is a Novice to Pro internal component and is not intended for general use."));
49
63
  }
@@ -53,7 +67,10 @@ export var CoachmarkStackHome = /*#__PURE__*/forwardRef(function (_ref, ref) {
53
67
  ref: ref,
54
68
  role: "main"
55
69
  }, getDevtoolsProps(componentName)), /*#__PURE__*/React.createElement(CoachmarkHeader, {
56
- onClose: onClose
70
+ onClose: function onClose() {
71
+ setLinkFocusIndex(0);
72
+ _onClose();
73
+ }
57
74
  }), /*#__PURE__*/React.createElement("div", {
58
75
  className: "".concat(overlayClass, "__body")
59
76
  }, /*#__PURE__*/React.createElement("div", {
@@ -73,21 +90,34 @@ export var CoachmarkStackHome = /*#__PURE__*/forwardRef(function (_ref, ref) {
73
90
  }, description)), /*#__PURE__*/React.createElement("ul", {
74
91
  className: "".concat(blockClass, "__nav-links")
75
92
  }, navLinkLabels.map(function (label, index) {
93
+ if (index === linkFocusIndex) {
94
+ return renderNavLink(index, label, buttonFocusRef);
95
+ } else {
96
+ return renderNavLink(index, label);
97
+ }
98
+ })), closeButtonLabel && /*#__PURE__*/React.createElement("div", {
99
+ className: "".concat(overlayClass, "__footer")
100
+ }, /*#__PURE__*/React.createElement(Button, {
101
+ size: "sm",
102
+ onClick: function onClick() {
103
+ setLinkFocusIndex(0);
104
+ _onClose();
105
+ }
106
+ }, closeButtonLabel))))), portalNode);
107
+ function renderNavLink(index, label) {
108
+ var ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
76
109
  return /*#__PURE__*/React.createElement("li", {
77
110
  key: index
78
111
  }, /*#__PURE__*/React.createElement(Button, {
79
112
  kind: "ghost",
80
113
  size: "sm",
81
114
  onClick: function onClick() {
115
+ setLinkFocusIndex(index);
82
116
  onClickNavItem(index + 1);
83
- }
117
+ },
118
+ ref: ref
84
119
  }, label));
85
- })), closeButtonLabel && /*#__PURE__*/React.createElement("div", {
86
- className: "".concat(overlayClass, "__footer")
87
- }, /*#__PURE__*/React.createElement(Button, {
88
- size: "sm",
89
- onClick: onClose
90
- }, closeButtonLabel))))), portalNode);
120
+ }
91
121
  });
92
122
 
93
123
  // Return a placeholder if not released and not enabled by feature flag
@@ -113,6 +143,10 @@ CoachmarkStackHome.propTypes = {
113
143
  * The description of the Coachmark.
114
144
  */
115
145
  description: PropTypes.node.isRequired,
146
+ /**
147
+ * If the stack home is open.
148
+ */
149
+ isOpen: PropTypes.bool.isRequired,
116
150
  /**
117
151
  * The object describing an image in one of two shapes.
118
152
  *