@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
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright IBM Corp. 2020, 2021
2
+ * Copyright IBM Corp. 2020, 2023
3
3
  *
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -15,4 +15,5 @@ export { usePreviousValue } from './usePreviousValue';
15
15
  export { useResetCreateComponent } from './useResetCreateComponent';
16
16
  export { useRetrieveStepData } from './useRetrieveStepData';
17
17
  export { useValidCreateStepCount } from './useValidCreateStepCount';
18
- export { useControllableState } from './useControllableState';
18
+ export { useControllableState } from './useControllableState';
19
+ export { usePrefix } from './usePrefix';
@@ -0,0 +1,11 @@
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
+ import pkg from '../package-settings';
9
+ export var usePrefix = function usePrefix() {
10
+ return pkg.prefix;
11
+ };
@@ -25,6 +25,7 @@ var defaults = {
25
25
  CreateTearsheet: true,
26
26
  CreateTearsheetStep: true,
27
27
  CreateTearsheetDivider: true,
28
+ Datagrid: true,
28
29
  EditInPlace: true,
29
30
  EmptyState: true,
30
31
  ErrorEmptyState: true,
@@ -65,7 +66,6 @@ var defaults = {
65
66
  EditSidePanel: false,
66
67
  CancelableTextEdit: false,
67
68
  DataSpreadsheet: false,
68
- Datagrid: false,
69
69
  EditTearsheet: false,
70
70
  EditTearsheetNarrow: false,
71
71
  EditFullPage: false,
@@ -73,7 +73,12 @@ var defaults = {
73
73
  ButtonMenu: false,
74
74
  // Novice to pro components not yet reviewed and released:
75
75
  InlineTip: false,
76
+ InlineTipButton: false,
77
+ InlineTipLink: false,
76
78
  Guidebanner: false,
79
+ GuidebannerElement: false,
80
+ GuidebannerElementButton: false,
81
+ GuidebannerElementLink: false,
77
82
  NonLinearReading: false,
78
83
  Checklist: false,
79
84
  Coachmark: false,
@@ -93,7 +98,6 @@ var defaults = {
93
98
  'Datagrid.useExpandedRow': false,
94
99
  'Datagrid.useNestedRows': false,
95
100
  'Datagrid.useInlineEdit': false,
96
- 'Datagrid.useActionsColumn': false,
97
101
  'Datagrid.useFiltering': false,
98
102
  'Datagrid.useCustomizeColumns': false,
99
103
  'ExampleComponent.secondaryIcon': false,
@@ -25,6 +25,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
25
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
26
  // The block part of our conventional BEM class names (blockClass__E--M).
27
27
  var blockClass = "".concat(_settings.pkg.prefix, "--coachmark");
28
+ var overlayBlockClass = "".concat(blockClass, "-overlay");
28
29
  var componentName = 'Coachmark';
29
30
  var defaults = {
30
31
  align: 'bottom',
@@ -86,7 +87,18 @@ var Coachmark = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
86
87
  var closeOverlay = function closeOverlay() {
87
88
  setIsOpen(false);
88
89
  };
89
- var handleClose = function handleClose() {
90
+ var escFunction = (0, _react.useCallback)(function (event) {
91
+ if (event.key === 'Escape') {
92
+ handleClose();
93
+ }
94
+ }, [handleClose]);
95
+ (0, _react.useEffect)(function () {
96
+ document.addEventListener('keydown', escFunction, false);
97
+ return function () {
98
+ document.removeEventListener('keydown', escFunction, false);
99
+ };
100
+ }, [escFunction]);
101
+ var handleClose = (0, _react.useCallback)(function () {
90
102
  if (isStacked) {
91
103
  // If stacked, do not unmount,
92
104
  // only call its ("parent") onClose method.
@@ -95,7 +107,7 @@ var Coachmark = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
95
107
  setIsOpen(false);
96
108
  onClose();
97
109
  }
98
- };
110
+ }, [isStacked, onClose]);
99
111
  var handleTargetClick = function handleTargetClick(e) {
100
112
  setTargetRect(e.target.getBoundingClientRect());
101
113
  setTargetOffset({
@@ -116,6 +128,7 @@ var Coachmark = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
116
128
  var contextValue = {
117
129
  buttonProps: {
118
130
  'aria-expanded': isOpen,
131
+ tabIndex: 0,
119
132
  onClick: handleTargetClick,
120
133
  // Compensate for accidental open/close on double-click.
121
134
  // Only open on double-click.
@@ -167,7 +180,7 @@ var Coachmark = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
167
180
  kind: overlayKind,
168
181
  onClose: handleClose,
169
182
  theme: theme,
170
- className: overlayClassName
183
+ className: (0, _classnames.default)(overlayClassName, "".concat(overlayBlockClass, "--is-visible"))
171
184
  }, children), portalNode)));
172
185
  });
173
186
 
@@ -189,7 +202,6 @@ Coachmark.propTypes = {
189
202
  * @see COACHMARK_ALIGNMENT
190
203
  */
191
204
  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
205
  /**
194
206
  * Coachmark should use a single CoachmarkOverlayElements component as a child.
195
207
  * @see CoachmarkOverlayElements
@@ -16,7 +16,7 @@ var _iconsReact = require("@carbon/icons-react");
16
16
  var _carbonComponentsReact = require("carbon-components-react");
17
17
  var _devtools = require("../../global/js/utils/devtools");
18
18
  var _settings = require("../../settings");
19
- var _excluded = ["closeIconDescription", "onClose", "onDrag", "showCloseButton", "theme"];
19
+ var _excluded = ["a11yKeyboardHandler", "closeIconDescription", "onClose", "onDrag", "showCloseButton", "theme"];
20
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
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
22
  // Carbon and package components we use.
@@ -24,6 +24,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
24
24
 
25
25
  // The block part of our conventional BEM class names (blockClass__E--M).
26
26
  var blockClass = "".concat(_settings.pkg.prefix, "--coachmark-dragbar");
27
+ var overlayBlockClass = "".concat(_settings.pkg.prefix, "--coachmark-overlay");
27
28
  var componentName = 'CoachmarkDragbar';
28
29
  var defaults = {
29
30
  closeIconDescription: 'Close',
@@ -38,7 +39,8 @@ var defaults = {
38
39
  * of other Novice to Pro components.
39
40
  */
40
41
  var CoachmarkDragbar = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
41
- var _ref$closeIconDescrip = _ref.closeIconDescription,
42
+ var a11yKeyboardHandler = _ref.a11yKeyboardHandler,
43
+ _ref$closeIconDescrip = _ref.closeIconDescription,
42
44
  closeIconDescription = _ref$closeIconDescrip === void 0 ? defaults.closeIconDescription : _ref$closeIconDescrip,
43
45
  _ref$onClose = _ref.onClose,
44
46
  onClose = _ref$onClose === void 0 ? defaults.onClose : _ref$onClose,
@@ -88,15 +90,16 @@ var CoachmarkDragbar = /*#__PURE__*/_react.default.forwardRef(function (_ref, re
88
90
  // role="main"
89
91
  }, (0, _devtools.getDevtoolsProps)(componentName)), /*#__PURE__*/_react.default.createElement("button", {
90
92
  type: "button",
91
- className: "".concat(blockClass, "__handle"),
92
- onMouseDown: handleDragStart
93
+ className: "".concat(overlayBlockClass, "__handle"),
94
+ onMouseDown: handleDragStart,
95
+ onKeyDown: a11yKeyboardHandler
93
96
  }, /*#__PURE__*/_react.default.createElement(_iconsReact.Draggable16, null)), showCloseButton && /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.Button, {
94
97
  kind: "ghost",
95
98
  size: "sm",
96
99
  renderIcon: _iconsReact.Close16,
97
100
  iconDescription: closeIconDescription,
98
101
  hasIconOnly: true,
99
- className: "".concat(blockClass, "--close-btn"),
102
+ className: "".concat(overlayBlockClass, "--close-btn"),
100
103
  onClick: onClose
101
104
  }));
102
105
  });
@@ -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.default.func.isRequired,
116
123
  /**
117
124
  * Tooltip text and aria label for the Close button icon.
118
125
  */
@@ -17,6 +17,7 @@ var _settings = require("../../settings");
17
17
  var _excluded = ["closeIconDescription", "onClose", "showCloseButton", "theme"];
18
18
  // The block part of our conventional BEM class names (blockClass__E--M).
19
19
  var blockClass = "".concat(_settings.pkg.prefix, "--coachmark-header");
20
+ var overlayBlockClass = "".concat(_settings.pkg.prefix, "--coachmark-overlay");
20
21
  var componentName = 'CoachmarkHeader';
21
22
  var defaults = {
22
23
  closeIconDescription: 'Close',
@@ -49,7 +50,7 @@ var CoachmarkHeader = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
49
50
  renderIcon: _iconsReact.Close16,
50
51
  iconDescription: closeIconDescription,
51
52
  hasIconOnly: true,
52
- className: "".concat(blockClass, "--close-btn"),
53
+ className: "".concat(overlayBlockClass, "--close-btn"),
53
54
  onClick: onClose
54
55
  }));
55
56
  });
@@ -7,8 +7,10 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.CoachmarkOverlay = void 0;
9
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
11
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
12
  var _react = _interopRequireWildcard(require("react"));
13
+ var _uuidv = _interopRequireDefault(require("../../global/js/utils/uuidv4"));
12
14
  var _propTypes = _interopRequireDefault(require("prop-types"));
13
15
  var _classnames = _interopRequireDefault(require("classnames"));
14
16
  var _devtools = require("../../global/js/utils/devtools");
@@ -46,12 +48,46 @@ var CoachmarkOverlay = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref)
46
48
  _ref$theme = _ref.theme,
47
49
  theme = _ref$theme === void 0 ? defaults.theme : _ref$theme,
48
50
  rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
51
+ var _useWindowDimensions = useWindowDimensions(),
52
+ winHeight = _useWindowDimensions.winHeight,
53
+ winWidth = _useWindowDimensions.winWidth;
54
+ var _useState = (0, _react.useState)(false),
55
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
56
+ a11yDragMode = _useState2[0],
57
+ setA11yDragMode = _useState2[1];
49
58
  var overlayRef = (0, _react.useRef)();
50
59
  var coachmark = (0, _context.useCoachmark)();
51
60
  var isBeacon = kind === _enums.COACHMARK_OVERLAY_KIND.TOOLTIP;
52
61
  var isDraggable = kind === _enums.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
+ };
53
90
  var styledTune = {};
54
- // TODO: check this... this feels like it should be in a hook with no dep array.
55
91
  if (isBeacon || isDraggable) {
56
92
  if (coachmark.targetRect) {
57
93
  styledTune = {
@@ -70,36 +106,97 @@ var CoachmarkOverlay = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref)
70
106
  styledTune.top += offsetTune.top;
71
107
  }
72
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
+ }
73
129
  function handleDrag(movementX, movementY) {
74
130
  var overlay = overlayRef.current;
75
131
  var _overlay$getBoundingC = overlay.getBoundingClientRect(),
76
132
  x = _overlay$getBoundingC.x,
77
133
  y = _overlay$getBoundingC.y;
134
+ var _handleDragBounds = handleDragBounds(x + movementX, y + movementY),
135
+ targetX = _handleDragBounds.targetX,
136
+ targetY = _handleDragBounds.targetY;
78
137
  overlay.style.transform = 'none';
79
138
  overlay.style.position = 'fixed';
80
- overlay.style.left = "".concat(x + movementX, "px");
81
- overlay.style.top = "".concat(y + movementY, "px");
139
+ overlay.style.left = "".concat(targetX, "px");
140
+ overlay.style.top = "".concat(targetY, "px");
82
141
  overlay.style.bottom = 'auto';
83
142
  }
143
+ var contentId = (0, _uuidv.default)();
84
144
  return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, rest, {
85
- className: (0, _classnames.default)(blockClass, "".concat(blockClass, "--").concat(kind), "".concat(blockClass, "__").concat(theme), (isBeacon || isDraggable) && "".concat(blockClass, "--").concat(coachmark.align), fixedIsVisible && "".concat(blockClass, "--is-visible"), className),
145
+ className: (0, _classnames.default)(blockClass, "".concat(blockClass, "--").concat(kind), "".concat(blockClass, "__").concat(theme), (isBeacon || isDraggable) && "".concat(blockClass, "--").concat(coachmark.align), fixedIsVisible && "".concat(blockClass, "--is-visible"), a11yDragMode && "".concat(blockClass, "--is-dragmode"), className),
86
146
  ref: overlayRef,
87
- style: styledTune
147
+ style: styledTune,
148
+ "aria-labelledby": contentId,
149
+ tabIndex: -1
88
150
  }, (0, _devtools.getDevtoolsProps)(componentName)), isDraggable ? /*#__PURE__*/_react.default.createElement(_CoachmarkDragbar.CoachmarkDragbar, {
151
+ a11yKeyboardHandler: handleKeyPress,
152
+ onBlur: function onBlur() {
153
+ return setA11yDragMode(false);
154
+ },
89
155
  onDrag: handleDrag,
156
+ theme: theme,
90
157
  onClose: onClose
91
158
  }) : /*#__PURE__*/_react.default.createElement(_CoachmarkHeader.CoachmarkHeader, {
92
159
  onClose: onClose
93
160
  }), /*#__PURE__*/_react.default.createElement("div", {
94
161
  className: "".concat(blockClass, "__body"),
95
- ref: ref
96
- }, children), isBeacon && /*#__PURE__*/_react.default.createElement("span", {
162
+ ref: ref,
163
+ id: contentId
164
+ }, _react.default.Children.map(children, function (child) {
165
+ return /*#__PURE__*/_react.default.cloneElement(child, {
166
+ isVisible: isVisible
167
+ });
168
+ })), isBeacon && /*#__PURE__*/_react.default.createElement("span", {
97
169
  className: "".concat(blockClass, "__caret")
98
170
  }));
99
171
  });
172
+ exports.CoachmarkOverlay = CoachmarkOverlay;
173
+ function getWindowDimensions() {
174
+ var _window = window,
175
+ winWidth = _window.innerWidth,
176
+ winHeight = _window.innerHeight;
177
+ return {
178
+ winWidth: winWidth,
179
+ winHeight: winHeight
180
+ };
181
+ }
182
+ var useWindowDimensions = function useWindowDimensions() {
183
+ var _useState3 = (0, _react.useState)(getWindowDimensions()),
184
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
185
+ windowDimensions = _useState4[0],
186
+ setWindowDimensions = _useState4[1];
187
+ (0, _react.useEffect)(function () {
188
+ function handleResize() {
189
+ setWindowDimensions(getWindowDimensions());
190
+ }
191
+ window.addEventListener('resize', handleResize);
192
+ return function () {
193
+ return window.removeEventListener('resize', handleResize);
194
+ };
195
+ }, []);
196
+ return windowDimensions;
197
+ };
100
198
 
101
199
  // Return a placeholder if not released and not enabled by feature flag
102
- exports.CoachmarkOverlay = CoachmarkOverlay;
103
200
  exports.CoachmarkOverlay = CoachmarkOverlay = _settings.pkg.checkComponentEnabled(CoachmarkOverlay, componentName);
104
201
 
105
202
  // The display name of the component, used by React. Note that displayName
@@ -43,14 +43,17 @@ var CoachmarkBeacon = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
43
43
  className: (0, _classnames.default)(blockClass, "".concat(blockClass, "-").concat(kind), className),
44
44
  ref: ref,
45
45
  style: overlayPositionStyle
46
- }, (0, _devtools.getDevtoolsProps)(componentName)), /*#__PURE__*/_react.default.createElement("button", (0, _extends2.default)({
46
+ }, (0, _devtools.getDevtoolsProps)(componentName), {
47
+ role: "tooltip"
48
+ }), /*#__PURE__*/_react.default.createElement("button", (0, _extends2.default)({
47
49
  tabIndex: 0,
48
50
  type: "button"
49
51
  }, coachmark.buttonProps, {
50
52
  "aria-label": label,
51
53
  className: "".concat(blockClass, "__target")
52
54
  }), /*#__PURE__*/_react.default.createElement("svg", {
53
- className: "".concat(blockClass, "__center")
55
+ className: "".concat(blockClass, "__center"),
56
+ alt: ""
54
57
  }, /*#__PURE__*/_react.default.createElement("circle", {
55
58
  r: 1,
56
59
  cx: 38,
@@ -23,7 +23,9 @@ var _excluded = ["children", "className", "onClose", "portalTarget", "tagline",
23
23
  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); }
24
24
  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; }
25
25
  // The block part of our conventional BEM class names (blockClass__E--M).
26
- var blockClass = "".concat(_settings.pkg.prefix, "--coachmark-fixed");
26
+ var coachmarkClass = "".concat(_settings.pkg.prefix, "--coachmark");
27
+ var blockClass = "".concat(coachmarkClass, "-fixed");
28
+ var overlayBlockClass = "".concat(coachmarkClass, "-overlay");
27
29
  var componentName = 'CoachmarkFixed';
28
30
  var defaults = {
29
31
  onClose: function onClose() {},
@@ -74,9 +76,14 @@ var CoachmarkFixed = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref)
74
76
  _useState10 = (0, _slicedToArray2.default)(_useState9, 2),
75
77
  fixedIsVisible = _useState10[0],
76
78
  setFixedIsVisible = _useState10[1];
77
- var handleClose = function handleClose() {
78
- setFixedIsVisible(false);
79
- };
79
+ var prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
80
+ var handleClose = (0, _react.useCallback)(function () {
81
+ if (prefersReducedMotion.matches) {
82
+ setIsOpen(false);
83
+ } else {
84
+ setFixedIsVisible(false);
85
+ }
86
+ }, [prefersReducedMotion.matches]);
80
87
  var handleTransitionEnd = function handleTransitionEnd(e) {
81
88
  if (e.propertyName === 'transform' && !fixedIsVisible) {
82
89
  setIsOpen(false);
@@ -93,9 +100,21 @@ var CoachmarkFixed = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref)
93
100
  setIsOpen(false);
94
101
  setShouldResetPosition(true);
95
102
  };
103
+ var escFunction = (0, _react.useCallback)(function (event) {
104
+ if (event.key === 'Escape') {
105
+ handleClose();
106
+ }
107
+ }, [handleClose]);
108
+ (0, _react.useEffect)(function () {
109
+ document.addEventListener('keydown', escFunction, false);
110
+ return function () {
111
+ document.removeEventListener('keydown', escFunction, false);
112
+ };
113
+ }, [escFunction]);
96
114
  var contextValue = {
97
115
  buttonProps: {
98
116
  'aria-expanded': isOpen,
117
+ tabIndex: 0,
99
118
  onClick: handleTargetClick,
100
119
  // Compensate for accidental open/close on double-click.
101
120
  // Only open on double-click.
@@ -150,7 +169,8 @@ var CoachmarkFixed = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref)
150
169
  kind: _enums.COACHMARK_OVERLAY_KIND.FIXED,
151
170
  onClose: handleClose,
152
171
  onTransitionEnd: handleTransitionEnd,
153
- theme: theme
172
+ theme: theme,
173
+ className: (0, _classnames.default)(fixedIsVisible && "".concat(overlayBlockClass, "--is-visible"), overlayBlockClass)
154
174
  }, children), portalNode)));
155
175
  });
156
176
 
@@ -20,13 +20,14 @@ var _Carousel = require("../Carousel");
20
20
  var _SteppedAnimatedMedia = require("../SteppedAnimatedMedia");
21
21
  var _devtools = require("../../global/js/utils/devtools");
22
22
  var _settings = require("../../settings");
23
- var _excluded = ["className", "children", "media", "nextButtonText", "previousButtonLabel", "closeButtonLabel"];
23
+ var _excluded = ["className", "children", "isVisible", "media", "nextButtonText", "previousButtonLabel", "closeButtonLabel"];
24
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
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
26
  // The block part of our conventional BEM class names (blockClass__E--M).
27
27
  var blockClass = "".concat(_settings.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
  var CoachmarkOverlayElements = /*#__PURE__*/_react.default.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 @@ var CoachmarkOverlayElements = /*#__PURE__*/_react.default.forwardRef(function (
56
59
  var _useState3 = (0, _react.useState)(0),
57
60
  _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
58
61
  currentProgStep = _useState4[0],
59
- setCurrentProgStep = _useState4[1];
62
+ _setCurrentProgStep = _useState4[1];
60
63
  var coachmark = (0, _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 = _react.Children.count(children);
62
73
  var progStepFloor = 0;
63
74
  var progStepCeil = numProgSteps - 1;
@@ -68,6 +79,13 @@ var CoachmarkOverlayElements = /*#__PURE__*/_react.default.forwardRef(function (
68
79
  buttonFocusRef.current.focus();
69
80
  }
70
81
  }, []);
82
+ (0, _react.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.default.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 @@ var CoachmarkOverlayElements = /*#__PURE__*/_react.default.forwardRef(function (
91
109
  className: (0, _classnames.default)("".concat(blockClass, "__footer"), 'coachmark-carousel-controls')
92
110
  }, /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.Button, (0, _extends2.default)({
93
111
  size: "sm"
94
- }, coachmark.closeButtonProps), closeButtonLabel))) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Carousel.Carousel, {
112
+ }, coachmark.closeButtonProps, {
113
+ ref: buttonFocusRef
114
+ }), closeButtonLabel))) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Carousel.Carousel, {
95
115
  disableArrowScroll: true,
96
116
  ref: scrollRef
97
117
  }, children), /*#__PURE__*/_react.default.createElement("div", {
@@ -155,6 +175,11 @@ CoachmarkOverlayElements.propTypes = {
155
175
  * The label for the Close button.
156
176
  */
157
177
  closeButtonLabel: _propTypes.default.string,
178
+ /**
179
+ * The visibility of CoachmarkOverlayElements is
180
+ * managed in the parent component.
181
+ */
182
+ isVisible: _propTypes.default.bool,
158
183
  /**
159
184
  * The object describing an image in one of two shapes.
160
185
  * If a single media element is required, use `{render}`.
@@ -91,7 +91,18 @@ var CoachmarkStack = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref)
91
91
  var handleClickNavItem = function handleClickNavItem(itemNumber) {
92
92
  setSelectedItemNumber(itemNumber);
93
93
  };
94
- var handleClose = function handleClose(isParentCloseButton) {
94
+ var escFunction = (0, _react.useCallback)(function (event) {
95
+ if (event.key === 'Escape') {
96
+ selectedItemNumber === 0 ? handleClose(true) : handleClose(false);
97
+ }
98
+ }, [handleClose, selectedItemNumber]);
99
+ (0, _react.useEffect)(function () {
100
+ document.addEventListener('keydown', escFunction, false);
101
+ return function () {
102
+ document.removeEventListener('keydown', escFunction, false);
103
+ };
104
+ }, [escFunction]);
105
+ var handleClose = (0, _react.useCallback)(function (isParentCloseButton) {
95
106
  if (isParentCloseButton) {
96
107
  // Trigger slide-out animation
97
108
  setSelectedItemNumber(-1);
@@ -108,9 +119,10 @@ var CoachmarkStack = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref)
108
119
  // Unstack child
109
120
  setSelectedItemNumber(0);
110
121
  }
111
- };
122
+ }, [onClose]);
112
123
  var contextValue = {
113
124
  buttonProps: {
125
+ tabIndex: 0,
114
126
  'aria-expanded': isOpen,
115
127
  onClick: function onClick() {
116
128
  setIsOpen(true);
@@ -137,7 +149,7 @@ var CoachmarkStack = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref)
137
149
  (0, _react.useEffect)(function () {
138
150
  setTimeout(function () {
139
151
  if (stackHomeRef.current) {
140
- setParentHeight(stackHomeRef.current.clientHeight);
152
+ setParentHeight(stackHomeRef.current.clientHeight + 16);
141
153
  }
142
154
  }, 0);
143
155
  }, [stackHomeRef]);
@@ -148,10 +160,12 @@ var CoachmarkStack = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref)
148
160
  }
149
161
  stackHomeRef.current.style.height = "".concat(parentHeight, "px");
150
162
  if (!isOpen || targetSelectedItem < 0) {
163
+ stackHomeRef.current.focus();
151
164
  return;
152
165
  }
153
166
  var targetHomeHeight = stackedCoachmarkRefs.current[targetSelectedItem].clientHeight;
154
167
  stackHomeRef.current.style.height = "".concat(targetHomeHeight, "px");
168
+ stackedCoachmarkRefs.current[targetSelectedItem].focus();
155
169
  }, [selectedItemNumber, isOpen, parentHeight]);
156
170
  var wrappedChildren = _react.Children.map(childArray, function (child, idx) {
157
171
  var mountedClass = mountedRef.current ? "".concat(elementBlockClass, "--is-mounted") : '';
@@ -180,6 +194,7 @@ var CoachmarkStack = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref)
180
194
  }), /*#__PURE__*/_react.default.createElement(_CoachmarkStackHome.CoachmarkStackHome, {
181
195
  ref: stackHomeRef,
182
196
  className: (0, _classnames.default)("".concat(_settings.pkg.prefix, "--coachmark-overlay"), "".concat(_settings.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")),
197
+ isOpen: isOpen && selectedItemNumber < 1,
183
198
  description: description,
184
199
  media: media,
185
200
  navLinkLabels: navLinkLabels,