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