@carbon/react 1.7.0 → 1.8.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/es/components/ComposedModal/ComposedModal.js +1 -1
  2. package/es/components/ComposedModal/index.js +4 -4
  3. package/es/components/DataTable/DataTable.js +1 -1
  4. package/es/components/DataTable/Table.js +10 -2
  5. package/es/components/DataTable/TableContainer.js +20 -5
  6. package/es/components/DataTable/TableContext.js +15 -0
  7. package/es/components/DataTable/TableSelectRow.js +1 -1
  8. package/es/components/FileUploader/FileUploader.js +8 -1
  9. package/es/components/FileUploader/FileUploaderButton.js +3 -1
  10. package/es/components/FileUploader/FileUploaderDropContainer.js +3 -1
  11. package/es/components/FileUploader/FileUploaderItem.js +3 -1
  12. package/es/components/InlineLoading/InlineLoading.js +9 -5
  13. package/es/components/Loading/Loading.js +7 -18
  14. package/es/components/MultiSelect/FilterableMultiSelect.js +345 -386
  15. package/es/components/MultiSelect/index.js +4 -8
  16. package/es/components/Notification/Notification.js +322 -189
  17. package/es/components/RadioButton/RadioButton.js +58 -99
  18. package/es/components/RadioButton/index.js +2 -8
  19. package/es/components/RadioButtonGroup/RadioButtonGroup.js +72 -121
  20. package/es/components/RadioButtonGroup/index.js +2 -8
  21. package/es/components/Slider/Slider.js +2 -1
  22. package/es/components/Switch/Switch.js +0 -1
  23. package/es/components/TreeView/TreeView.js +19 -11
  24. package/es/components/UIShell/HeaderMenu.js +1 -1
  25. package/es/components/UIShell/HeaderMenuButton.js +4 -0
  26. package/es/components/UIShell/SideNavLink.js +6 -9
  27. package/es/index.js +7 -6
  28. package/es/internal/createClassWrapper.js +2 -5
  29. package/lib/components/ComposedModal/index.js +7 -7
  30. package/lib/components/DataTable/DataTable.js +5 -5
  31. package/lib/components/DataTable/Table.js +9 -1
  32. package/lib/components/DataTable/TableContainer.js +19 -4
  33. package/lib/components/DataTable/TableContext.js +19 -0
  34. package/lib/components/DataTable/TableSelectRow.js +2 -2
  35. package/lib/components/FileUploader/FileUploader.js +8 -1
  36. package/lib/components/FileUploader/FileUploaderButton.js +3 -1
  37. package/lib/components/FileUploader/FileUploaderDropContainer.js +3 -1
  38. package/lib/components/FileUploader/FileUploaderItem.js +3 -1
  39. package/lib/components/InlineLoading/InlineLoading.js +9 -5
  40. package/lib/components/Loading/Loading.js +6 -17
  41. package/lib/components/MultiSelect/FilterableMultiSelect.js +341 -382
  42. package/lib/components/MultiSelect/index.js +5 -28
  43. package/lib/components/Notification/Notification.js +321 -188
  44. package/lib/components/RadioButton/RadioButton.js +57 -99
  45. package/lib/components/RadioButton/index.js +2 -25
  46. package/lib/components/RadioButtonGroup/RadioButtonGroup.js +68 -117
  47. package/lib/components/RadioButtonGroup/index.js +2 -25
  48. package/lib/components/Slider/Slider.js +2 -1
  49. package/lib/components/Switch/Switch.js +0 -1
  50. package/lib/components/TreeView/TreeView.js +18 -10
  51. package/lib/components/UIShell/HeaderMenu.js +1 -0
  52. package/lib/components/UIShell/HeaderMenuButton.js +4 -0
  53. package/lib/components/UIShell/SideNavLink.js +6 -9
  54. package/lib/index.js +83 -83
  55. package/lib/internal/createClassWrapper.js +2 -5
  56. package/package.json +7 -7
  57. package/es/components/MultiSelect/next/FilterableMultiSelect.js +0 -544
  58. package/es/components/Notification/index.js +0 -42
  59. package/es/components/Notification/next/Notification.js +0 -663
  60. package/es/components/RadioButton/next/RadioButton.js +0 -130
  61. package/es/components/RadioButtonGroup/next/RadioButtonGroup.js +0 -141
  62. package/lib/components/MultiSelect/next/FilterableMultiSelect.js +0 -556
  63. package/lib/components/Notification/index.js +0 -51
  64. package/lib/components/Notification/next/Notification.js +0 -677
  65. package/lib/components/RadioButton/next/RadioButton.js +0 -140
  66. package/lib/components/RadioButtonGroup/next/RadioButtonGroup.js +0 -151
@@ -15,7 +15,11 @@ var React = require('react');
15
15
  var cx = require('classnames');
16
16
  var iconsReact = require('@carbon/icons-react');
17
17
  var Button = require('../Button/Button.js');
18
+ var useIsomorphicEffect = require('../../internal/useIsomorphicEffect.js');
19
+ var useNoInteractiveChildren = require('../../internal/useNoInteractiveChildren.js');
18
20
  var usePrefix = require('../../internal/usePrefix.js');
21
+ var match = require('../../internal/keyboard/match.js');
22
+ var keys = require('../../internal/keyboard/keys.js');
19
23
 
20
24
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
21
25
 
@@ -25,24 +29,52 @@ var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
25
29
 
26
30
  var _iconTypes;
27
31
 
28
- var _excluded = ["children", "className", "onClick"],
29
- _excluded2 = ["ariaLabel", "className", "iconDescription", "type", "renderIcon", "name", "notificationType"],
30
- _excluded3 = ["title", "subtitle", "caption", "notificationType", "children"],
31
- _excluded4 = ["role", "notificationType", "onClose", "onCloseButtonClick", "iconDescription", "statusIconDescription", "className", "caption", "subtitle", "title", "kind", "lowContrast", "hideCloseButton", "children", "timeout"],
32
- _excluded5 = ["actions", "role", "notificationType", "onClose", "onCloseButtonClick", "iconDescription", "statusIconDescription", "className", "subtitle", "title", "kind", "lowContrast", "hideCloseButton", "children"];
32
+ var _excluded = ["children", "className", "onClick", "inline"],
33
+ _excluded2 = ["ariaLabel", "className", "type", "renderIcon", "name", "notificationType"],
34
+ _excluded3 = ["role", "onClose", "onCloseButtonClick", "statusIconDescription", "className", "children", "kind", "lowContrast", "hideCloseButton", "timeout", "title", "caption", "subtitle"],
35
+ _excluded4 = ["children", "title", "subtitle", "role", "onClose", "onCloseButtonClick", "statusIconDescription", "className", "kind", "lowContrast", "hideCloseButton"],
36
+ _excluded5 = ["actionButtonLabel", "ariaLabel", "children", "role", "onActionButtonClick", "onClose", "onCloseButtonClick", "statusIconDescription", "className", "inline", "kind", "lowContrast", "hideCloseButton", "hasFocus", "closeOnEscape", "title", "subtitle"];
37
+ /**
38
+ * Conditionally call a callback when the escape key is pressed
39
+ * @param {node} ref - ref of the container element to scope the functionality to
40
+ * @param {func} callback - function to be called
41
+ * @param {bool} override - escape hatch to conditionally call the callback
42
+ */
43
+
44
+ function useEscapeToClose(ref, callback) {
45
+ var override = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
46
+
47
+ var handleKeyDown = function handleKeyDown(event) {
48
+ // The callback should only be called when focus is on or within the container
49
+ var elementContainsFocus = ref.current && document.activeElement === ref.current || ref.current.contains(document.activeElement);
50
+
51
+ if (match.matches(event, [keys.Escape]) && override && elementContainsFocus) {
52
+ callback(event);
53
+ }
54
+ };
55
+
56
+ useIsomorphicEffect["default"](function () {
57
+ document.addEventListener('keydown', handleKeyDown, false);
58
+ return function () {
59
+ return document.removeEventListener('keydown', handleKeyDown, false);
60
+ };
61
+ });
62
+ }
63
+
33
64
  function NotificationActionButton(_ref) {
34
65
  var children = _ref.children,
35
66
  customClassName = _ref.className,
36
67
  onClick = _ref.onClick,
68
+ inline = _ref.inline,
37
69
  rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
38
70
 
39
71
  var prefix = usePrefix.usePrefix();
40
- var className = cx__default["default"](customClassName, "".concat(prefix, "--inline-notification__action-button"));
72
+ var className = cx__default["default"](customClassName, _rollupPluginBabelHelpers.defineProperty({}, "".concat(prefix, "--actionable-notification__action-button"), true));
41
73
  return /*#__PURE__*/React__default["default"].createElement(Button["default"], _rollupPluginBabelHelpers["extends"]({
42
74
  className: className,
43
- kind: "ghost",
75
+ kind: inline ? 'ghost' : 'tertiary',
44
76
  onClick: onClick,
45
- size: "small"
77
+ size: "sm"
46
78
  }, rest), children);
47
79
  }
48
80
  NotificationActionButton.propTypes = {
@@ -56,6 +88,11 @@ NotificationActionButton.propTypes = {
56
88
  */
57
89
  className: PropTypes__default["default"].string,
58
90
 
91
+ /**
92
+ * Specify if the visual treatment of the button should be for an inline notification
93
+ */
94
+ inline: PropTypes__default["default"].bool,
95
+
59
96
  /**
60
97
  * Optionally specify a click handler for the notification action button.
61
98
  */
@@ -64,7 +101,6 @@ NotificationActionButton.propTypes = {
64
101
  function NotificationButton(_ref2) {
65
102
  var ariaLabel = _ref2.ariaLabel,
66
103
  className = _ref2.className,
67
- iconDescription = _ref2.iconDescription,
68
104
  type = _ref2.type,
69
105
  IconTag = _ref2.renderIcon,
70
106
  name = _ref2.name,
@@ -77,11 +113,10 @@ function NotificationButton(_ref2) {
77
113
  return /*#__PURE__*/React__default["default"].createElement("button", _rollupPluginBabelHelpers["extends"]({}, rest, {
78
114
  // eslint-disable-next-line react/button-has-type
79
115
  type: type,
80
- "aria-label": iconDescription,
81
- title: iconDescription,
116
+ "aria-label": ariaLabel,
117
+ title: ariaLabel,
82
118
  className: buttonClassName
83
119
  }), IconTag && /*#__PURE__*/React__default["default"].createElement(IconTag, {
84
- "aria-label": ariaLabel,
85
120
  className: iconClassName,
86
121
  name: name
87
122
  }));
@@ -97,11 +132,6 @@ NotificationButton.propTypes = {
97
132
  */
98
133
  className: PropTypes__default["default"].string,
99
134
 
100
- /**
101
- * Provide a description for "close" icon that can be read by screen readers
102
- */
103
- iconDescription: PropTypes__default["default"].string,
104
-
105
135
  /**
106
136
  * Specify an optional icon for the Button through a string,
107
137
  * if something but regular "close" icon is desirable
@@ -111,7 +141,7 @@ NotificationButton.propTypes = {
111
141
  /**
112
142
  * Specify the notification type
113
143
  */
114
- notificationType: PropTypes__default["default"].oneOf(['toast', 'inline']),
144
+ notificationType: PropTypes__default["default"].oneOf(['toast', 'inline', 'actionable']),
115
145
 
116
146
  /**
117
147
  * Optional prop to allow overriding the icon rendering.
@@ -126,84 +156,20 @@ NotificationButton.propTypes = {
126
156
  };
127
157
  NotificationButton.defaultProps = {
128
158
  ariaLabel: 'close notification',
129
- // TODO: deprecate this prop
130
159
  notificationType: 'toast',
131
160
  type: 'button',
132
- iconDescription: 'close icon',
133
161
  renderIcon: iconsReact.Close
134
162
  };
135
- function NotificationTextDetails(_ref3) {
136
- var title = _ref3.title,
137
- subtitle = _ref3.subtitle,
138
- caption = _ref3.caption,
139
- notificationType = _ref3.notificationType,
140
- children = _ref3.children,
141
- rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref3, _excluded3);
142
-
143
- var prefix = usePrefix.usePrefix();
144
-
145
- if (notificationType === 'toast') {
146
- return /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({}, rest, {
147
- className: "".concat(prefix, "--toast-notification__details")
148
- }), /*#__PURE__*/React__default["default"].createElement("h3", {
149
- className: "".concat(prefix, "--toast-notification__title")
150
- }, title), /*#__PURE__*/React__default["default"].createElement("div", {
151
- className: "".concat(prefix, "--toast-notification__subtitle")
152
- }, subtitle), caption && /*#__PURE__*/React__default["default"].createElement("div", {
153
- className: "".concat(prefix, "--toast-notification__caption")
154
- }, caption), children);
155
- }
156
-
157
- if (notificationType === 'inline') {
158
- return /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({}, rest, {
159
- className: "".concat(prefix, "--inline-notification__text-wrapper")
160
- }), /*#__PURE__*/React__default["default"].createElement("p", {
161
- className: "".concat(prefix, "--inline-notification__title")
162
- }, title), /*#__PURE__*/React__default["default"].createElement("div", {
163
- className: "".concat(prefix, "--inline-notification__subtitle")
164
- }, subtitle), children);
165
- }
166
- }
167
- NotificationTextDetails.propTypes = {
168
- /**
169
- * Specify the caption
170
- */
171
- caption: PropTypes__default["default"].node,
172
-
173
- /**
174
- * Pass in the children that will be rendered in NotificationTextDetails
175
- */
176
- children: PropTypes__default["default"].node,
177
-
178
- /**
179
- * Specify the notification type
180
- */
181
- notificationType: PropTypes__default["default"].oneOf(['toast', 'inline']),
182
-
183
- /**
184
- * Specify the sub-title
185
- */
186
- subtitle: PropTypes__default["default"].node,
187
-
188
- /**
189
- * Specify the title
190
- */
191
- title: PropTypes__default["default"].string
192
- };
193
- NotificationTextDetails.defaultProps = {
194
- title: 'title',
195
- notificationType: 'toast'
196
- };
197
163
  var iconTypes = (_iconTypes = {
198
164
  error: iconsReact.ErrorFilled,
199
165
  success: iconsReact.CheckmarkFilled,
200
166
  warning: iconsReact.WarningFilled
201
167
  }, _rollupPluginBabelHelpers.defineProperty(_iconTypes, 'warning-alt', iconsReact.WarningAltFilled), _rollupPluginBabelHelpers.defineProperty(_iconTypes, "info", iconsReact.InformationFilled), _rollupPluginBabelHelpers.defineProperty(_iconTypes, 'info-square', iconsReact.InformationSquareFilled), _iconTypes);
202
168
 
203
- function NotificationIcon(_ref4) {
204
- var iconDescription = _ref4.iconDescription,
205
- kind = _ref4.kind,
206
- notificationType = _ref4.notificationType;
169
+ function NotificationIcon(_ref3) {
170
+ var iconDescription = _ref3.iconDescription,
171
+ kind = _ref3.kind,
172
+ notificationType = _ref3.notificationType;
207
173
  var prefix = usePrefix.usePrefix();
208
174
  var IconForKind = iconTypes[kind];
209
175
 
@@ -221,34 +187,33 @@ NotificationIcon.propTypes = {
221
187
  kind: PropTypes__default["default"].oneOf(['error', 'success', 'warning', 'warning-alt', 'info', 'info-square']).isRequired,
222
188
  notificationType: PropTypes__default["default"].oneOf(['inline', 'toast']).isRequired
223
189
  };
224
- function ToastNotification(_ref5) {
225
- var _cx3;
226
-
227
- var role = _ref5.role,
228
- notificationType = _ref5.notificationType,
229
- onClose = _ref5.onClose,
230
- onCloseButtonClick = _ref5.onCloseButtonClick,
231
- iconDescription = _ref5.iconDescription,
232
- statusIconDescription = _ref5.statusIconDescription,
233
- className = _ref5.className,
234
- caption = _ref5.caption,
235
- subtitle = _ref5.subtitle,
236
- title = _ref5.title,
237
- kind = _ref5.kind,
238
- lowContrast = _ref5.lowContrast,
239
- hideCloseButton = _ref5.hideCloseButton,
240
- children = _ref5.children,
241
- timeout = _ref5.timeout,
242
- rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref5, _excluded4);
190
+ function ToastNotification(_ref4) {
191
+ var _cx4;
243
192
 
244
- var prefix = usePrefix.usePrefix();
193
+ var role = _ref4.role,
194
+ onClose = _ref4.onClose,
195
+ onCloseButtonClick = _ref4.onCloseButtonClick,
196
+ statusIconDescription = _ref4.statusIconDescription,
197
+ className = _ref4.className,
198
+ children = _ref4.children,
199
+ kind = _ref4.kind,
200
+ lowContrast = _ref4.lowContrast,
201
+ hideCloseButton = _ref4.hideCloseButton,
202
+ timeout = _ref4.timeout,
203
+ title = _ref4.title,
204
+ caption = _ref4.caption,
205
+ subtitle = _ref4.subtitle,
206
+ rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref4, _excluded3);
245
207
 
246
208
  var _useState = React.useState(true),
247
209
  _useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
248
210
  isOpen = _useState2[0],
249
211
  setIsOpen = _useState2[1];
250
212
 
251
- var containerClassName = cx__default["default"](className, (_cx3 = {}, _rollupPluginBabelHelpers.defineProperty(_cx3, "".concat(prefix, "--toast-notification"), true), _rollupPluginBabelHelpers.defineProperty(_cx3, "".concat(prefix, "--toast-notification--low-contrast"), lowContrast), _rollupPluginBabelHelpers.defineProperty(_cx3, "".concat(prefix, "--toast-notification--").concat(kind), kind), _cx3));
213
+ var prefix = usePrefix.usePrefix();
214
+ var containerClassName = cx__default["default"](className, (_cx4 = {}, _rollupPluginBabelHelpers.defineProperty(_cx4, "".concat(prefix, "--toast-notification"), true), _rollupPluginBabelHelpers.defineProperty(_cx4, "".concat(prefix, "--toast-notification--low-contrast"), lowContrast), _rollupPluginBabelHelpers.defineProperty(_cx4, "".concat(prefix, "--toast-notification--").concat(kind), kind), _cx4));
215
+ var contentRef = React.useRef(null);
216
+ useNoInteractiveChildren.useNoInteractiveChildren(contentRef);
252
217
 
253
218
  var handleClose = function handleClose(evt) {
254
219
  if (!onClose || onClose(evt) !== false) {
@@ -256,6 +221,8 @@ function ToastNotification(_ref5) {
256
221
  }
257
222
  };
258
223
 
224
+ var ref = React.useRef(null);
225
+
259
226
  function handleCloseButtonClick(event) {
260
227
  onCloseButtonClick(event);
261
228
  handleClose(event);
@@ -286,33 +253,44 @@ function ToastNotification(_ref5) {
286
253
  return null;
287
254
  }
288
255
 
289
- return /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({}, rest, {
256
+ return /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({
257
+ ref: ref
258
+ }, rest, {
290
259
  role: role,
291
- kind: kind,
292
260
  className: containerClassName
293
261
  }), /*#__PURE__*/React__default["default"].createElement(NotificationIcon, {
294
- notificationType: notificationType,
262
+ notificationType: "toast",
295
263
  kind: kind,
296
264
  iconDescription: statusIconDescription || "".concat(kind, " icon")
297
- }), /*#__PURE__*/React__default["default"].createElement(NotificationTextDetails, {
298
- title: title,
299
- subtitle: subtitle,
300
- caption: caption,
301
- notificationType: notificationType
302
- }, children), !hideCloseButton && /*#__PURE__*/React__default["default"].createElement(NotificationButton, {
303
- iconDescription: iconDescription,
304
- notificationType: notificationType,
305
- onClick: handleCloseButtonClick
265
+ }), /*#__PURE__*/React__default["default"].createElement("div", {
266
+ ref: contentRef,
267
+ className: "".concat(prefix, "--toast-notification__details")
268
+ }, title && /*#__PURE__*/React__default["default"].createElement("div", {
269
+ className: "".concat(prefix, "--toast-notification__title")
270
+ }, title), subtitle && /*#__PURE__*/React__default["default"].createElement("div", {
271
+ className: "".concat(prefix, "--toast-notification__subtitle")
272
+ }, subtitle), caption && /*#__PURE__*/React__default["default"].createElement("div", {
273
+ className: "".concat(prefix, "--toast-notification__caption")
274
+ }, caption), children), !hideCloseButton && /*#__PURE__*/React__default["default"].createElement(NotificationButton, {
275
+ notificationType: "toast",
276
+ onClick: handleCloseButtonClick,
277
+ "aria-hidden": "true",
278
+ tabIndex: "-1"
306
279
  }));
307
280
  }
308
281
  ToastNotification.propTypes = {
282
+ /**
283
+ * Provide a description for "close" icon button that can be read by screen readers
284
+ */
285
+ ariaLabel: PropTypes__default["default"].string,
286
+
309
287
  /**
310
288
  * Specify the caption
311
289
  */
312
- caption: PropTypes__default["default"].node,
290
+ caption: PropTypes__default["default"].string,
313
291
 
314
292
  /**
315
- * Pass in the children that will be rendered within the ToastNotification
293
+ * Specify the content
316
294
  */
317
295
  children: PropTypes__default["default"].node,
318
296
 
@@ -326,27 +304,16 @@ ToastNotification.propTypes = {
326
304
  */
327
305
  hideCloseButton: PropTypes__default["default"].bool,
328
306
 
329
- /**
330
- * Provide a description for "close" icon that can be read by screen readers
331
- */
332
- iconDescription: PropTypes__default["default"].string,
333
-
334
307
  /**
335
308
  * Specify what state the notification represents
336
309
  */
337
- kind: PropTypes__default["default"].oneOf(['error', 'info', 'info-square', 'success', 'warning', 'warning-alt']).isRequired,
310
+ kind: PropTypes__default["default"].oneOf(['error', 'info', 'info-square', 'success', 'warning', 'warning-alt']),
338
311
 
339
312
  /**
340
313
  * Specify whether you are using the low contrast variant of the ToastNotification.
341
314
  */
342
315
  lowContrast: PropTypes__default["default"].bool,
343
316
 
344
- /**
345
- * By default, this value is "toast". You can also provide an alternate type
346
- * if it makes sense for the underlying `<NotificationTextDetails>` and `<NotificationButton>`
347
- */
348
- notificationType: PropTypes__default["default"].string,
349
-
350
317
  /**
351
318
  * Provide a function that is called when menu is closed
352
319
  */
@@ -358,10 +325,10 @@ ToastNotification.propTypes = {
358
325
  onCloseButtonClick: PropTypes__default["default"].func,
359
326
 
360
327
  /**
361
- * By default, this value is "alert". You can also provide an alternate
328
+ * By default, this value is "status". You can also provide an alternate
362
329
  * role if it makes sense from the accessibility-side
363
330
  */
364
- role: PropTypes__default["default"].string.isRequired,
331
+ role: PropTypes__default["default"].oneOf(['alert', 'log', 'status']),
365
332
 
366
333
  /**
367
334
  * Provide a description for "status" icon that can be read by screen readers
@@ -371,7 +338,7 @@ ToastNotification.propTypes = {
371
338
  /**
372
339
  * Specify the sub-title
373
340
  */
374
- subtitle: PropTypes__default["default"].node,
341
+ subtitle: PropTypes__default["default"].string,
375
342
 
376
343
  /**
377
344
  * Specify an optional duration the notification should be closed in
@@ -381,45 +348,181 @@ ToastNotification.propTypes = {
381
348
  /**
382
349
  * Specify the title
383
350
  */
384
- title: PropTypes__default["default"].string.isRequired
351
+ title: PropTypes__default["default"].string
385
352
  };
386
353
  ToastNotification.defaultProps = {
387
354
  kind: 'error',
388
- title: 'provide a title',
389
- role: 'alert',
390
- notificationType: 'toast',
391
- iconDescription: 'closes notification',
355
+ role: 'status',
392
356
  onCloseButtonClick: function onCloseButtonClick() {},
393
357
  hideCloseButton: false,
394
358
  timeout: 0
395
359
  };
396
- function InlineNotification(_ref6) {
397
- var _cx4;
360
+ function InlineNotification(_ref5) {
361
+ var _cx5;
362
+
363
+ var children = _ref5.children,
364
+ title = _ref5.title,
365
+ subtitle = _ref5.subtitle,
366
+ role = _ref5.role,
367
+ onClose = _ref5.onClose,
368
+ onCloseButtonClick = _ref5.onCloseButtonClick,
369
+ statusIconDescription = _ref5.statusIconDescription,
370
+ className = _ref5.className,
371
+ kind = _ref5.kind,
372
+ lowContrast = _ref5.lowContrast,
373
+ hideCloseButton = _ref5.hideCloseButton,
374
+ rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref5, _excluded4);
375
+
376
+ var _useState3 = React.useState(true),
377
+ _useState4 = _rollupPluginBabelHelpers.slicedToArray(_useState3, 2),
378
+ isOpen = _useState4[0],
379
+ setIsOpen = _useState4[1];
380
+
381
+ var prefix = usePrefix.usePrefix();
382
+ var containerClassName = cx__default["default"](className, (_cx5 = {}, _rollupPluginBabelHelpers.defineProperty(_cx5, "".concat(prefix, "--inline-notification"), true), _rollupPluginBabelHelpers.defineProperty(_cx5, "".concat(prefix, "--inline-notification--low-contrast"), lowContrast), _rollupPluginBabelHelpers.defineProperty(_cx5, "".concat(prefix, "--inline-notification--").concat(kind), kind), _rollupPluginBabelHelpers.defineProperty(_cx5, "".concat(prefix, "--inline-notification--hide-close-button"), hideCloseButton), _cx5));
383
+ var contentRef = React.useRef(null);
384
+ useNoInteractiveChildren.useNoInteractiveChildren(contentRef);
385
+
386
+ var handleClose = function handleClose(evt) {
387
+ if (!onClose || onClose(evt) !== false) {
388
+ setIsOpen(false);
389
+ }
390
+ };
391
+
392
+ var ref = React.useRef(null);
393
+
394
+ function handleCloseButtonClick(event) {
395
+ onCloseButtonClick(event);
396
+ handleClose(event);
397
+ }
398
398
 
399
- var actions = _ref6.actions,
399
+ if (!isOpen) {
400
+ return null;
401
+ }
402
+
403
+ return /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({
404
+ ref: ref
405
+ }, rest, {
406
+ role: role,
407
+ className: containerClassName
408
+ }), /*#__PURE__*/React__default["default"].createElement("div", {
409
+ className: "".concat(prefix, "--inline-notification__details")
410
+ }, /*#__PURE__*/React__default["default"].createElement(NotificationIcon, {
411
+ notificationType: "inline",
412
+ kind: kind,
413
+ iconDescription: statusIconDescription || "".concat(kind, " icon")
414
+ }), /*#__PURE__*/React__default["default"].createElement("div", {
415
+ ref: contentRef,
416
+ className: "".concat(prefix, "--inline-notification__text-wrapper")
417
+ }, title && /*#__PURE__*/React__default["default"].createElement("div", {
418
+ className: "".concat(prefix, "--inline-notification__title")
419
+ }, title), subtitle && /*#__PURE__*/React__default["default"].createElement("div", {
420
+ className: "".concat(prefix, "--inline-notification__subtitle")
421
+ }, subtitle), children)), !hideCloseButton && /*#__PURE__*/React__default["default"].createElement(NotificationButton, {
422
+ notificationType: "inline",
423
+ onClick: handleCloseButtonClick,
424
+ "aria-hidden": "true",
425
+ tabIndex: "-1"
426
+ }));
427
+ }
428
+ InlineNotification.propTypes = {
429
+ /**
430
+ * Specify the content
431
+ */
432
+ children: PropTypes__default["default"].node,
433
+
434
+ /**
435
+ * Specify an optional className to be applied to the notification box
436
+ */
437
+ className: PropTypes__default["default"].string,
438
+
439
+ /**
440
+ * Specify the close button should be disabled, or not
441
+ */
442
+ hideCloseButton: PropTypes__default["default"].bool,
443
+
444
+ /**
445
+ * Specify what state the notification represents
446
+ */
447
+ kind: PropTypes__default["default"].oneOf(['error', 'info', 'info-square', 'success', 'warning', 'warning-alt']),
448
+
449
+ /**
450
+ * Specify whether you are using the low contrast variant of the InlineNotification.
451
+ */
452
+ lowContrast: PropTypes__default["default"].bool,
453
+
454
+ /**
455
+ * Provide a function that is called when menu is closed
456
+ */
457
+ onClose: PropTypes__default["default"].func,
458
+
459
+ /**
460
+ * Provide a function that is called when the close button is clicked
461
+ */
462
+ onCloseButtonClick: PropTypes__default["default"].func,
463
+
464
+ /**
465
+ * By default, this value is "status". You can also provide an alternate
466
+ * role if it makes sense from the accessibility-side.
467
+ */
468
+ role: PropTypes__default["default"].oneOf(['alert', 'log', 'status']),
469
+
470
+ /**
471
+ * Provide a description for "status" icon that can be read by screen readers
472
+ */
473
+ statusIconDescription: PropTypes__default["default"].string,
474
+
475
+ /**
476
+ * Specify the sub-title
477
+ */
478
+ subtitle: PropTypes__default["default"].string,
479
+
480
+ /**
481
+ * Specify the title
482
+ */
483
+ title: PropTypes__default["default"].string
484
+ };
485
+ InlineNotification.defaultProps = {
486
+ kind: 'error',
487
+ role: 'status',
488
+ onCloseButtonClick: function onCloseButtonClick() {},
489
+ hideCloseButton: false
490
+ };
491
+ function ActionableNotification(_ref6) {
492
+ var _cx6;
493
+
494
+ var actionButtonLabel = _ref6.actionButtonLabel,
495
+ ariaLabel = _ref6.ariaLabel,
496
+ children = _ref6.children,
400
497
  role = _ref6.role,
401
- notificationType = _ref6.notificationType,
498
+ onActionButtonClick = _ref6.onActionButtonClick,
402
499
  onClose = _ref6.onClose,
403
500
  onCloseButtonClick = _ref6.onCloseButtonClick,
404
- iconDescription = _ref6.iconDescription,
405
501
  statusIconDescription = _ref6.statusIconDescription,
406
502
  className = _ref6.className,
407
- subtitle = _ref6.subtitle,
408
- title = _ref6.title,
503
+ inline = _ref6.inline,
409
504
  kind = _ref6.kind,
410
505
  lowContrast = _ref6.lowContrast,
411
506
  hideCloseButton = _ref6.hideCloseButton,
412
- children = _ref6.children,
507
+ hasFocus = _ref6.hasFocus,
508
+ closeOnEscape = _ref6.closeOnEscape,
509
+ title = _ref6.title,
510
+ subtitle = _ref6.subtitle,
413
511
  rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref6, _excluded5);
414
512
 
415
- var prefix = usePrefix.usePrefix();
416
-
417
- var _useState3 = React.useState(true),
418
- _useState4 = _rollupPluginBabelHelpers.slicedToArray(_useState3, 2),
419
- isOpen = _useState4[0],
420
- setIsOpen = _useState4[1];
513
+ var _useState5 = React.useState(true),
514
+ _useState6 = _rollupPluginBabelHelpers.slicedToArray(_useState5, 2),
515
+ isOpen = _useState6[0],
516
+ setIsOpen = _useState6[1];
421
517
 
422
- var containerClassName = cx__default["default"](className, (_cx4 = {}, _rollupPluginBabelHelpers.defineProperty(_cx4, "".concat(prefix, "--inline-notification"), true), _rollupPluginBabelHelpers.defineProperty(_cx4, "".concat(prefix, "--inline-notification--low-contrast"), lowContrast), _rollupPluginBabelHelpers.defineProperty(_cx4, "".concat(prefix, "--inline-notification--").concat(kind), kind), _rollupPluginBabelHelpers.defineProperty(_cx4, "".concat(prefix, "--inline-notification--hide-close-button"), hideCloseButton), _cx4));
518
+ var prefix = usePrefix.usePrefix();
519
+ var containerClassName = cx__default["default"](className, (_cx6 = {}, _rollupPluginBabelHelpers.defineProperty(_cx6, "".concat(prefix, "--actionable-notification"), true), _rollupPluginBabelHelpers.defineProperty(_cx6, "".concat(prefix, "--actionable-notification--toast"), !inline), _rollupPluginBabelHelpers.defineProperty(_cx6, "".concat(prefix, "--actionable-notification--low-contrast"), lowContrast), _rollupPluginBabelHelpers.defineProperty(_cx6, "".concat(prefix, "--actionable-notification--").concat(kind), kind), _rollupPluginBabelHelpers.defineProperty(_cx6, "".concat(prefix, "--actionable-notification--hide-close-button"), hideCloseButton), _cx6));
520
+ var ref = React.useRef(null);
521
+ useIsomorphicEffect["default"](function () {
522
+ if (ref.current && hasFocus) {
523
+ ref.current.focus();
524
+ }
525
+ });
423
526
 
424
527
  var handleClose = function handleClose(evt) {
425
528
  if (!onClose || onClose(evt) !== false) {
@@ -427,6 +530,8 @@ function InlineNotification(_ref6) {
427
530
  }
428
531
  };
429
532
 
533
+ useEscapeToClose(ref, handleCloseButtonClick, closeOnEscape);
534
+
430
535
  function handleCloseButtonClick(event) {
431
536
  onCloseButtonClick(event);
432
537
  handleClose(event);
@@ -437,33 +542,50 @@ function InlineNotification(_ref6) {
437
542
  }
438
543
 
439
544
  return /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({}, rest, {
545
+ ref: ref,
440
546
  role: role,
441
- kind: kind,
442
547
  className: containerClassName
443
548
  }), /*#__PURE__*/React__default["default"].createElement("div", {
444
- className: "".concat(prefix, "--inline-notification__details")
549
+ className: "".concat(prefix, "--actionable-notification__details")
445
550
  }, /*#__PURE__*/React__default["default"].createElement(NotificationIcon, {
446
- notificationType: notificationType,
551
+ notificationType: inline ? 'inline' : 'toast',
447
552
  kind: kind,
448
553
  iconDescription: statusIconDescription || "".concat(kind, " icon")
449
- }), /*#__PURE__*/React__default["default"].createElement(NotificationTextDetails, {
450
- title: title,
451
- subtitle: subtitle,
452
- notificationType: notificationType
453
- }, children)), actions, !hideCloseButton && /*#__PURE__*/React__default["default"].createElement(NotificationButton, {
454
- iconDescription: iconDescription,
455
- notificationType: notificationType,
554
+ }), /*#__PURE__*/React__default["default"].createElement("div", {
555
+ className: "".concat(prefix, "--actionable-notification__text-wrapper")
556
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
557
+ className: "".concat(prefix, "--actionable-notification__content")
558
+ }, title && /*#__PURE__*/React__default["default"].createElement("div", {
559
+ className: "".concat(prefix, "--actionable-notification__title")
560
+ }, title), subtitle && /*#__PURE__*/React__default["default"].createElement("div", {
561
+ className: "".concat(prefix, "--actionable-notification__subtitle")
562
+ }, subtitle), children))), /*#__PURE__*/React__default["default"].createElement(NotificationActionButton, {
563
+ onClick: onActionButtonClick,
564
+ inline: inline
565
+ }, actionButtonLabel), !hideCloseButton && /*#__PURE__*/React__default["default"].createElement(NotificationButton, {
566
+ "aria-label": ariaLabel,
567
+ notificationType: "actionable",
456
568
  onClick: handleCloseButtonClick
457
569
  }));
458
570
  }
459
- InlineNotification.propTypes = {
571
+ ActionableNotification.propTypes = {
572
+ /**
573
+ * Pass in the action button label that will be rendered within the ActionableNotification.
574
+ */
575
+ actionButtonLabel: PropTypes__default["default"].string.isRequired,
576
+
460
577
  /**
461
- * Pass in the action nodes that will be rendered within the InlineNotification
578
+ * Provide a description for "close" icon button that can be read by screen readers
579
+ */
580
+ ariaLabel: PropTypes__default["default"].string,
581
+
582
+ /**
583
+ * Specify the caption
462
584
  */
463
- actions: PropTypes__default["default"].node,
585
+ caption: PropTypes__default["default"].string,
464
586
 
465
587
  /**
466
- * Pass in the children that will be rendered within the InlineNotification
588
+ * Specify the content
467
589
  */
468
590
  children: PropTypes__default["default"].node,
469
591
 
@@ -472,15 +594,25 @@ InlineNotification.propTypes = {
472
594
  */
473
595
  className: PropTypes__default["default"].string,
474
596
 
597
+ /**
598
+ * Specify if pressing the escape key should close notifications
599
+ */
600
+ closeOnEscape: PropTypes__default["default"].bool,
601
+
602
+ /**
603
+ * Specify if focus should be moved to the component when the notification contains actions
604
+ */
605
+ hasFocus: PropTypes__default["default"].bool,
606
+
475
607
  /**
476
608
  * Specify the close button should be disabled, or not
477
609
  */
478
610
  hideCloseButton: PropTypes__default["default"].bool,
479
611
 
480
- /**
481
- * Provide a description for "close" icon that can be read by screen readers
612
+ /*
613
+ * Specify if the notification should have inline styling applied instead of toast
482
614
  */
483
- iconDescription: PropTypes__default["default"].string,
615
+ inline: PropTypes__default["default"].bool,
484
616
 
485
617
  /**
486
618
  * Specify what state the notification represents
@@ -488,15 +620,14 @@ InlineNotification.propTypes = {
488
620
  kind: PropTypes__default["default"].oneOf(['error', 'info', 'info-square', 'success', 'warning', 'warning-alt']).isRequired,
489
621
 
490
622
  /**
491
- * Specify whether you are using the low contrast variant of the InlineNotification.
623
+ * Specify whether you are using the low contrast variant of the ActionableNotification.
492
624
  */
493
625
  lowContrast: PropTypes__default["default"].bool,
494
626
 
495
627
  /**
496
- * By default, this value is "inline". You can also provide an alternate type
497
- * if it makes sense for the underlying `<NotificationTextDetails>` and `<NotificationButton>`
628
+ * Provide a function that is called when the action is clicked
498
629
  */
499
- notificationType: PropTypes__default["default"].string,
630
+ onActionButtonClick: PropTypes__default["default"].func,
500
631
 
501
632
  /**
502
633
  * Provide a function that is called when menu is closed
@@ -509,10 +640,10 @@ InlineNotification.propTypes = {
509
640
  onCloseButtonClick: PropTypes__default["default"].func,
510
641
 
511
642
  /**
512
- * By default, this value is "alert". You can also provide an alternate
513
- * role if it makes sense from the accessibility-side
643
+ * By default, this value is "alertdialog". You can also provide an alternate
644
+ * role if it makes sense from the accessibility-side.
514
645
  */
515
- role: PropTypes__default["default"].string.isRequired,
646
+ role: PropTypes__default["default"].string,
516
647
 
517
648
  /**
518
649
  * Provide a description for "status" icon that can be read by screen readers
@@ -522,23 +653,25 @@ InlineNotification.propTypes = {
522
653
  /**
523
654
  * Specify the sub-title
524
655
  */
525
- subtitle: PropTypes__default["default"].node,
656
+ subtitle: PropTypes__default["default"].string,
526
657
 
527
658
  /**
528
659
  * Specify the title
529
660
  */
530
- title: PropTypes__default["default"].string.isRequired
661
+ title: PropTypes__default["default"].string
531
662
  };
532
- InlineNotification.defaultProps = {
533
- role: 'alert',
534
- notificationType: 'inline',
535
- iconDescription: 'closes notification',
663
+ ActionableNotification.defaultProps = {
664
+ kind: 'error',
665
+ role: 'alertdialog',
536
666
  onCloseButtonClick: function onCloseButtonClick() {},
537
- hideCloseButton: false
667
+ hideCloseButton: false,
668
+ hasFocus: true,
669
+ closeOnEscape: true,
670
+ inline: false
538
671
  };
539
672
 
673
+ exports.ActionableNotification = ActionableNotification;
540
674
  exports.InlineNotification = InlineNotification;
541
675
  exports.NotificationActionButton = NotificationActionButton;
542
676
  exports.NotificationButton = NotificationButton;
543
- exports.NotificationTextDetails = NotificationTextDetails;
544
677
  exports.ToastNotification = ToastNotification;