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