@zendeskgarden/react-notifications 9.0.0-next.2 → 9.0.0-next.20

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 (68) hide show
  1. package/README.md +6 -4
  2. package/dist/esm/elements/Alert.js +56 -0
  3. package/dist/esm/elements/Notification.js +55 -0
  4. package/dist/esm/elements/Well.js +47 -0
  5. package/dist/esm/elements/content/Close.js +40 -0
  6. package/dist/esm/elements/content/Paragraph.js +28 -0
  7. package/dist/esm/elements/content/Title.js +35 -0
  8. package/dist/esm/elements/global-alert/GlobalAlert.js +78 -0
  9. package/dist/esm/elements/global-alert/GlobalAlertButton.js +47 -0
  10. package/dist/esm/elements/global-alert/GlobalAlertClose.js +43 -0
  11. package/dist/esm/elements/global-alert/GlobalAlertContent.js +30 -0
  12. package/dist/esm/elements/global-alert/GlobalAlertTitle.js +44 -0
  13. package/dist/esm/elements/toaster/Toast.js +62 -0
  14. package/dist/esm/elements/toaster/ToastContext.js +11 -0
  15. package/dist/esm/elements/toaster/ToastProvider.js +51 -0
  16. package/dist/esm/elements/toaster/ToastSlot.js +82 -0
  17. package/dist/esm/elements/toaster/reducer.js +66 -0
  18. package/dist/esm/elements/toaster/styled.js +71 -0
  19. package/dist/esm/elements/toaster/useToast.js +70 -0
  20. package/dist/esm/index.js +15 -0
  21. package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/alert-error-stroke.svg.js +37 -0
  22. package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/alert-warning-stroke.svg.js +32 -0
  23. package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/check-circle-stroke.svg.js +33 -0
  24. package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/info-stroke.svg.js +37 -0
  25. package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/x-stroke.svg.js +26 -0
  26. package/dist/esm/styled/StyledAlert.js +51 -0
  27. package/dist/esm/styled/StyledBase.js +92 -0
  28. package/dist/esm/styled/StyledIcon.js +61 -0
  29. package/dist/esm/styled/StyledNotification.js +56 -0
  30. package/dist/esm/styled/StyledWell.js +47 -0
  31. package/dist/esm/styled/content/StyledClose.js +70 -0
  32. package/dist/esm/styled/content/StyledParagraph.js +22 -0
  33. package/dist/esm/styled/content/StyledTitle.js +25 -0
  34. package/dist/esm/styled/global-alert/StyledGlobalAlert.js +160 -0
  35. package/dist/esm/styled/global-alert/StyledGlobalAlertButton.js +118 -0
  36. package/dist/esm/styled/global-alert/StyledGlobalAlertClose.js +103 -0
  37. package/dist/esm/styled/global-alert/StyledGlobalAlertContent.js +22 -0
  38. package/dist/esm/styled/global-alert/StyledGlobalAlertIcon.js +65 -0
  39. package/dist/esm/styled/global-alert/StyledGlobalAlertTitle.js +49 -0
  40. package/dist/esm/types/index.js +9 -0
  41. package/dist/esm/utils/icons.js +25 -0
  42. package/dist/esm/utils/useGlobalAlertContext.js +14 -0
  43. package/dist/esm/utils/useNotificationsContext.js +14 -0
  44. package/dist/index.cjs.js +811 -440
  45. package/dist/typings/elements/Alert.d.ts +9 -1
  46. package/dist/typings/elements/Notification.d.ts +9 -1
  47. package/dist/typings/elements/Well.d.ts +7 -1
  48. package/dist/typings/elements/content/Close.d.ts +2 -0
  49. package/dist/typings/elements/content/Paragraph.d.ts +2 -0
  50. package/dist/typings/elements/content/Title.d.ts +2 -0
  51. package/dist/typings/index.d.ts +2 -6
  52. package/dist/typings/styled/StyledAlert.d.ts +8 -3
  53. package/dist/typings/styled/StyledBase.d.ts +8 -6
  54. package/dist/typings/styled/StyledIcon.d.ts +11 -2
  55. package/dist/typings/styled/StyledNotification.d.ts +11 -3
  56. package/dist/typings/styled/StyledWell.d.ts +7 -2
  57. package/dist/typings/styled/content/StyledClose.d.ts +5 -3
  58. package/dist/typings/styled/content/StyledTitle.d.ts +1 -1
  59. package/dist/typings/styled/global-alert/StyledGlobalAlert.d.ts +1 -1
  60. package/dist/typings/styled/global-alert/StyledGlobalAlertButton.d.ts +4 -11
  61. package/dist/typings/styled/global-alert/StyledGlobalAlertClose.d.ts +2 -3
  62. package/dist/typings/styled/global-alert/StyledGlobalAlertIcon.d.ts +2 -2
  63. package/dist/typings/styled/global-alert/StyledGlobalAlertTitle.d.ts +2 -2
  64. package/dist/typings/utils/icons.d.ts +1 -1
  65. package/dist/typings/{elements/global-alert/utility.d.ts → utils/useGlobalAlertContext.d.ts} +1 -1
  66. package/dist/typings/utils/useNotificationsContext.d.ts +2 -3
  67. package/package.json +9 -9
  68. package/dist/index.esm.js +0 -1124
package/dist/index.esm.js DELETED
@@ -1,1124 +0,0 @@
1
- /**
2
- * Copyright Zendesk, Inc.
3
- *
4
- * Use of this source code is governed under the Apache License, Version 2.0
5
- * found at http://www.apache.org/licenses/LICENSE-2.0.
6
- */
7
-
8
- import * as React from 'react';
9
- import React__default, { Children, createContext, useContext, forwardRef, useCallback, useState, useRef, useEffect, useReducer, useMemo } from 'react';
10
- import PropTypes from 'prop-types';
11
- import styled, { css, ThemeContext } from 'styled-components';
12
- import { getColor, focusStyles, retrieveComponentStyles, DEFAULT_THEME, getLineHeight, useText, useDocument } from '@zendeskgarden/react-theming';
13
- import { IconButton, Button } from '@zendeskgarden/react-buttons';
14
- import { math, hideVisually } from 'polished';
15
- import { TransitionGroup, CSSTransition } from 'react-transition-group';
16
- import { uid } from 'react-uid';
17
-
18
- function _extends$6() {
19
- _extends$6 = Object.assign ? Object.assign.bind() : function (target) {
20
- for (var i = 1; i < arguments.length; i++) {
21
- var source = arguments[i];
22
- for (var key in source) {
23
- if (Object.prototype.hasOwnProperty.call(source, key)) {
24
- target[key] = source[key];
25
- }
26
- }
27
- }
28
- return target;
29
- };
30
- return _extends$6.apply(this, arguments);
31
- }
32
-
33
- const TYPE = ['success', 'warning', 'error', 'info'];
34
-
35
- const COMPONENT_ID$b = 'notifications.close';
36
- const StyledClose = styled.button.attrs({
37
- 'data-garden-id': COMPONENT_ID$b,
38
- 'data-garden-version': '9.0.0-next.2'
39
- }).withConfig({
40
- displayName: "StyledClose",
41
- componentId: "sc-1mr9nx1-0"
42
- })(["display:block;position:absolute;top:", "px;", ":", ";transition:background-color 0.1s ease-in-out,color 0.25s ease-in-out,box-shadow 0.1s ease-in-out;border:none;border-radius:50%;background-color:transparent;cursor:pointer;padding:0;width:", "px;height:", "px;overflow:hidden;color:", ";font-size:0;user-select:none;&::-moz-focus-inner{border:0;}&:hover{color:", ";}", " ", ";"], props => props.theme.space.base, props => props.theme.rtl ? 'left' : 'right', props => `${props.theme.space.base}px`, props => props.theme.space.base * 7, props => props.theme.space.base * 7, props => props.hue ? getColor(props.hue, props.hue === 'warningHue' ? 700 : 600, props.theme) : getColor('neutralHue', 600, props.theme), props => props.hue ? getColor(props.hue, 800, props.theme) : getColor('neutralHue', 800, props.theme), props => focusStyles({
43
- theme: props.theme,
44
- inset: true
45
- }), props => retrieveComponentStyles(COMPONENT_ID$b, props));
46
- StyledClose.defaultProps = {
47
- theme: DEFAULT_THEME
48
- };
49
-
50
- const COMPONENT_ID$a = 'notifications.paragraph';
51
- const StyledParagraph = styled.p.attrs({
52
- 'data-garden-id': COMPONENT_ID$a,
53
- 'data-garden-version': '9.0.0-next.2'
54
- }).withConfig({
55
- displayName: "StyledParagraph",
56
- componentId: "sc-12tmd6p-0"
57
- })(["margin:", "px 0 0;", ";"], props => props.theme.space.base * 2, props => retrieveComponentStyles(COMPONENT_ID$a, props));
58
- StyledParagraph.defaultProps = {
59
- theme: DEFAULT_THEME
60
- };
61
-
62
- const COMPONENT_ID$9 = 'notifications.title';
63
- const StyledTitle = styled.div.attrs({
64
- 'data-garden-id': COMPONENT_ID$9,
65
- 'data-garden-version': '9.0.0-next.2'
66
- }).withConfig({
67
- displayName: "StyledTitle",
68
- componentId: "sc-xx4jsv-0"
69
- })(["margin:0;color:", ";font-weight:", ";", ";"], props => props.theme.colors.foreground, props => props.isRegular ? props.theme.fontWeights.regular : props.theme.fontWeights.semibold, props => retrieveComponentStyles(COMPONENT_ID$9, props));
70
- StyledTitle.defaultProps = {
71
- theme: DEFAULT_THEME
72
- };
73
-
74
- const boxShadow = props => {
75
- const {
76
- theme
77
- } = props;
78
- const {
79
- space,
80
- shadows
81
- } = theme;
82
- const offsetY = `${space.base * 5}px`;
83
- const blurRadius = `${space.base * 7}px`;
84
- const color = getColor('chromeHue', 600, theme, 0.15);
85
- return shadows.lg(offsetY, blurRadius, color);
86
- };
87
- const colorStyles$6 = props => {
88
- let backgroundColor;
89
- let borderColor;
90
- let foregroundColor;
91
- if (props.hue) {
92
- backgroundColor = getColor(props.hue, 100, props.theme);
93
- borderColor = getColor(props.hue, 300, props.theme);
94
- foregroundColor = getColor(props.hue, props.type === 'info' ? 600 : 700, props.theme);
95
- } else {
96
- backgroundColor = props.theme.colors.background;
97
- borderColor = getColor('neutralHue', 300, props.theme);
98
- foregroundColor = getColor('neutralHue', 800, props.theme);
99
- }
100
- return css(["border-color:", ";background-color:", ";color:", ";"], borderColor, backgroundColor, foregroundColor);
101
- };
102
- const padding = props => {
103
- const {
104
- space
105
- } = props.theme;
106
- const paddingVertical = `${space.base * 5}px`;
107
- const paddingHorizontal = `${space.base * 10}px`;
108
- return `${paddingVertical} ${paddingHorizontal}`;
109
- };
110
- const StyledBase = styled.div.withConfig({
111
- displayName: "StyledBase",
112
- componentId: "sc-14syaqw-0"
113
- })(["position:relative;border:", ";border-radius:", ";box-shadow:", ";padding:", ";line-height:", ";font-size:", ";direction:", ";", ";"], props => props.theme.borders.sm, props => props.theme.borderRadii.md, props => props.isFloating && boxShadow, padding, props => getLineHeight(props.theme.space.base * 5, props.theme.fontSizes.md), props => props.theme.fontSizes.md, props => props.theme.rtl && 'rtl', colorStyles$6);
114
- StyledBase.defaultProps = {
115
- theme: DEFAULT_THEME
116
- };
117
-
118
- const COMPONENT_ID$8 = 'notifications.alert';
119
- const colorStyles$5 = props => css(["", "{color:", ";}"], StyledTitle, props.hue && getColor(props.hue, 800, props.theme));
120
- const StyledAlert = styled(StyledBase).attrs({
121
- 'data-garden-id': COMPONENT_ID$8,
122
- 'data-garden-version': '9.0.0-next.2'
123
- }).withConfig({
124
- displayName: "StyledAlert",
125
- componentId: "sc-fyn8jp-0"
126
- })(["", " ", ";"], colorStyles$5, props => retrieveComponentStyles(COMPONENT_ID$8, props));
127
- StyledAlert.defaultProps = {
128
- theme: DEFAULT_THEME
129
- };
130
-
131
- const COMPONENT_ID$7 = 'notifications.notification';
132
- const colorStyles$4 = props => {
133
- const {
134
- type,
135
- theme
136
- } = props;
137
- const {
138
- colors
139
- } = theme;
140
- const {
141
- successHue,
142
- dangerHue,
143
- warningHue,
144
- foreground
145
- } = colors;
146
- let color;
147
- switch (type) {
148
- case 'success':
149
- color = getColor(successHue, 600, theme);
150
- break;
151
- case 'error':
152
- color = getColor(dangerHue, 600, theme);
153
- break;
154
- case 'warning':
155
- color = getColor(warningHue, 700, theme);
156
- break;
157
- case 'info':
158
- color = foreground;
159
- break;
160
- default:
161
- color = 'inherit';
162
- break;
163
- }
164
- return css(["", "{color:", ";}"], StyledTitle, color);
165
- };
166
- const StyledNotification = styled(StyledBase).attrs({
167
- 'data-garden-id': COMPONENT_ID$7,
168
- 'data-garden-version': '9.0.0-next.2'
169
- }).withConfig({
170
- displayName: "StyledNotification",
171
- componentId: "sc-uf6jh-0"
172
- })(["", " ", ";"], colorStyles$4, props => retrieveComponentStyles(COMPONENT_ID$7, props));
173
- StyledNotification.propTypes = {
174
- type: PropTypes.oneOf(TYPE)
175
- };
176
- StyledNotification.defaultProps = {
177
- theme: DEFAULT_THEME
178
- };
179
-
180
- const COMPONENT_ID$6 = 'notifications.well';
181
- const StyledWell = styled(StyledBase).attrs({
182
- 'data-garden-id': COMPONENT_ID$6,
183
- 'data-garden-version': '9.0.0-next.2'
184
- }).withConfig({
185
- displayName: "StyledWell",
186
- componentId: "sc-a5831c-0"
187
- })(["background-color:", ";color:", " ", ";"], props => props.isRecessed && getColor('neutralHue', 100, props.theme), props => getColor('neutralHue', 600, props.theme), props => retrieveComponentStyles(COMPONENT_ID$6, props));
188
- StyledWell.defaultProps = {
189
- theme: DEFAULT_THEME
190
- };
191
-
192
- const StyledIcon = styled(_ref => {
193
- let {
194
- children,
195
- ...props
196
- } = _ref;
197
- return React__default.cloneElement(Children.only(children), props);
198
- }).withConfig({
199
- displayName: "StyledIcon",
200
- componentId: "sc-msklws-0"
201
- })(["position:absolute;right:", ";left:", ";margin-top:", "px;color:", ";"], props => props.theme.rtl && `${props.theme.space.base * 4}px`, props => !props.theme.rtl && `${props.theme.space.base * 4}px`, props => props.theme.space.base / 2, props => props.hue && getColor(props.hue, props.hue === 'warningHue' ? 700 : 600, props.theme));
202
- StyledIcon.defaultProps = {
203
- theme: DEFAULT_THEME
204
- };
205
-
206
- const COMPONENT_ID$5 = 'notifications.global-alert';
207
- const colorStyles$3 = props => {
208
- let borderColor;
209
- let backgroundColor;
210
- let foregroundColor;
211
- let anchorHoverColor;
212
- let anchorActiveColor;
213
- let focusColor;
214
- switch (props.alertType) {
215
- case 'success':
216
- borderColor = getColor('successHue', 700, props.theme);
217
- backgroundColor = getColor('successHue', 600, props.theme);
218
- foregroundColor = getColor('successHue', 100, props.theme);
219
- anchorHoverColor = props.theme.palette.white;
220
- anchorActiveColor = props.theme.palette.white;
221
- focusColor = 'successHue';
222
- break;
223
- case 'error':
224
- borderColor = getColor('dangerHue', 700, props.theme);
225
- backgroundColor = getColor('dangerHue', 600, props.theme);
226
- foregroundColor = getColor('dangerHue', 100, props.theme);
227
- anchorHoverColor = props.theme.palette.white;
228
- anchorActiveColor = props.theme.palette.white;
229
- focusColor = 'dangerHue';
230
- break;
231
- case 'warning':
232
- borderColor = getColor('warningHue', 400, props.theme);
233
- backgroundColor = getColor('warningHue', 300, props.theme);
234
- foregroundColor = getColor('warningHue', 800, props.theme);
235
- anchorHoverColor = getColor('warningHue', 900, props.theme);
236
- anchorActiveColor = getColor('warningHue', 1000, props.theme);
237
- focusColor = 'warningHue';
238
- break;
239
- case 'info':
240
- borderColor = getColor('primaryHue', 300, props.theme);
241
- backgroundColor = getColor('primaryHue', 200, props.theme);
242
- foregroundColor = getColor('primaryHue', 700, props.theme);
243
- anchorHoverColor = getColor('primaryHue', 800, props.theme);
244
- anchorActiveColor = getColor('primaryHue', 900, props.theme);
245
- focusColor = 'primaryHue';
246
- break;
247
- }
248
- const boxShadow = `0 ${props.theme.borderWidths.sm} ${props.theme.borderWidths.sm} ${borderColor}`;
249
- return css(["box-shadow:", ";background-color:", ";color:", ";& a{color:inherit;", " &:hover{color:", ";}&:active{color:", ";}}"], boxShadow, backgroundColor, foregroundColor, focusStyles({
250
- theme: props.theme,
251
- hue: focusColor,
252
- shade: props.alertType === 'info' ? 600 : 800,
253
- styles: {
254
- color: 'inherit'
255
- }
256
- }), anchorHoverColor, anchorActiveColor);
257
- };
258
- const sizeStyles$3 = props => {
259
- const {
260
- fontSizes,
261
- space
262
- } = props.theme;
263
- const minHeight = space.base * 13;
264
- const padding = space.base * 4;
265
- const lineHeight = getLineHeight(space.base * 5, fontSizes.md);
266
- return css(["padding:", "px;min-height:", "px;line-height:", ";font-size:", ";"], padding, minHeight, lineHeight, fontSizes.md);
267
- };
268
- const StyledGlobalAlert = styled.div.attrs({
269
- 'data-garden-id': COMPONENT_ID$5,
270
- 'data-garden-version': '9.0.0-next.2'
271
- }).withConfig({
272
- displayName: "StyledGlobalAlert",
273
- componentId: "sc-k6rimt-0"
274
- })(["display:flex;flex-wrap:nowrap;overflow:auto;overflow-x:hidden;box-sizing:border-box;direction:", ";", " ", " && a{border-radius:", ";text-decoration:underline;}", ";"], props => props.theme.rtl ? 'rtl' : 'ltr', sizeStyles$3, colorStyles$3, props => props.theme.borderRadii.sm, props => retrieveComponentStyles(COMPONENT_ID$5, props));
275
- StyledGlobalAlert.defaultProps = {
276
- theme: DEFAULT_THEME
277
- };
278
-
279
- const COMPONENT_ID$4 = 'notifications.global-alert.close';
280
- const colorStyles$2 = props => {
281
- let hoverBackgroundColor;
282
- let hoverForegroundColor;
283
- let activeBackgroundColor;
284
- let activeForegroundColor;
285
- let focusColor;
286
- switch (props.alertType) {
287
- case 'success':
288
- hoverBackgroundColor = getColor('successHue', 100, props.theme, 0.08);
289
- hoverForegroundColor = props.theme.palette.white;
290
- activeBackgroundColor = getColor('successHue', 100, props.theme, 0.2);
291
- activeForegroundColor = props.theme.palette.white;
292
- focusColor = 'successHue';
293
- break;
294
- case 'error':
295
- hoverBackgroundColor = getColor('dangerHue', 100, props.theme, 0.08);
296
- hoverForegroundColor = props.theme.palette.white;
297
- activeBackgroundColor = getColor('dangerHue', 100, props.theme, 0.2);
298
- activeForegroundColor = props.theme.palette.white;
299
- focusColor = 'dangerHue';
300
- break;
301
- case 'warning':
302
- hoverBackgroundColor = getColor('warningHue', 800, props.theme, 0.08);
303
- hoverForegroundColor = getColor('warningHue', 900, props.theme);
304
- activeBackgroundColor = getColor('warningHue', 800, props.theme, 0.2);
305
- activeForegroundColor = getColor('warningHue', 1000, props.theme);
306
- focusColor = 'warningHue';
307
- break;
308
- case 'info':
309
- hoverBackgroundColor = getColor('primaryHue', 700, props.theme, 0.08);
310
- hoverForegroundColor = getColor('primaryHue', 800, props.theme);
311
- activeBackgroundColor = getColor('primaryHue', 700, props.theme, 0.2);
312
- activeForegroundColor = getColor('primaryHue', 900, props.theme);
313
- focusColor = 'primaryHue';
314
- break;
315
- }
316
- return css(["color:inherit;&:hover{background-color:", ";color:", ";}", " &:active{background-color:", ";color:", ";}"], hoverBackgroundColor, hoverForegroundColor, focusStyles({
317
- theme: props.theme,
318
- hue: focusColor,
319
- shade: props.alertType === 'info' ? 600 : 800
320
- }), activeBackgroundColor, activeForegroundColor);
321
- };
322
- const sizeStyles$2 = props => {
323
- const marginVertical = `-${props.theme.space.base * 1.5}px`;
324
- const marginStart = `${props.theme.space.base * 2}px`;
325
- const marginEnd = `-${props.theme.space.base * 2}px`;
326
- return css(["margin:", " ", " ", " ", ";"], marginVertical, props.theme.rtl ? marginStart : marginEnd, marginVertical, props.theme.rtl ? marginEnd : marginStart);
327
- };
328
- const StyledGlobalAlertClose = styled(IconButton).attrs({
329
- 'data-garden-id': COMPONENT_ID$4,
330
- 'data-garden-version': '9.0.0-next.2',
331
- size: 'small'
332
- }).withConfig({
333
- displayName: "StyledGlobalAlertClose",
334
- componentId: "sc-1g5s93s-0"
335
- })(["", ";", ";", ";"], sizeStyles$2, colorStyles$2, props => retrieveComponentStyles(COMPONENT_ID$4, props));
336
- StyledGlobalAlertClose.defaultProps = {
337
- theme: DEFAULT_THEME
338
- };
339
-
340
- const COMPONENT_ID$3 = 'notifications.global-alert.button';
341
- function colorStyles$1(props) {
342
- if (props.isBasic) {
343
- return colorStyles$2(props);
344
- }
345
- let backgroundColor;
346
- let hoverBackgroundColor;
347
- let activeBackgroundColor;
348
- let focusColor;
349
- switch (props.alertType) {
350
- case 'success':
351
- backgroundColor = getColor('successHue', 800, props.theme);
352
- hoverBackgroundColor = getColor('successHue', 900, props.theme);
353
- activeBackgroundColor = getColor('successHue', 1000, props.theme);
354
- focusColor = 'successHue';
355
- break;
356
- case 'error':
357
- backgroundColor = getColor('dangerHue', 800, props.theme);
358
- hoverBackgroundColor = getColor('dangerHue', 900, props.theme);
359
- activeBackgroundColor = getColor('dangerHue', 1000, props.theme);
360
- focusColor = 'dangerHue';
361
- break;
362
- case 'warning':
363
- backgroundColor = getColor('warningHue', 800, props.theme);
364
- hoverBackgroundColor = getColor('warningHue', 900, props.theme);
365
- activeBackgroundColor = getColor('warningHue', 1000, props.theme);
366
- focusColor = 'warningHue';
367
- break;
368
- case 'info':
369
- focusColor = 'primaryHue';
370
- break;
371
- }
372
- return css(["background-color:", ";&:hover{background-color:", ";}", " &:active{background-color:", ";}"], backgroundColor, hoverBackgroundColor, focusStyles({
373
- theme: props.theme,
374
- hue: focusColor,
375
- shade: props.alertType === 'info' ? 600 : 800
376
- }), activeBackgroundColor);
377
- }
378
- function sizeStyles$1(props) {
379
- const marginVertical = `-${props.theme.space.base * 1.5}px`;
380
- const marginStart = `${props.theme.space.base * 2}px`;
381
- return css(["margin:", " ", " ", " ", ";"], marginVertical, props.theme.rtl ? marginStart : 0, marginVertical, props.theme.rtl ? 0 : marginStart);
382
- }
383
- const StyledGlobalAlertButton = styled(Button).attrs({
384
- 'data-garden-id': COMPONENT_ID$3,
385
- 'data-garden-version': '9.0.0-next.2',
386
- focusInset: false,
387
- isDanger: false,
388
- isLink: false,
389
- isNeutral: false,
390
- isPill: false,
391
- isStretched: false,
392
- size: 'small'
393
- }).withConfig({
394
- displayName: "StyledGlobalAlertButton",
395
- componentId: "sc-1txe91a-0"
396
- })(["flex-shrink:0;", ";", ";", ";"], sizeStyles$1, colorStyles$1, props => retrieveComponentStyles(COMPONENT_ID$3, props));
397
- StyledGlobalAlertButton.defaultProps = {
398
- theme: DEFAULT_THEME
399
- };
400
-
401
- const COMPONENT_ID$2 = 'notifications.global-alert.content';
402
- const StyledGlobalAlertContent = styled.div.attrs({
403
- 'data-garden-id': COMPONENT_ID$2,
404
- 'data-garden-version': '9.0.0-next.2'
405
- }).withConfig({
406
- displayName: "StyledGlobalAlertContent",
407
- componentId: "sc-rept0u-0"
408
- })(["flex-grow:1;", ";"], props => retrieveComponentStyles(COMPONENT_ID$2, props));
409
- StyledGlobalAlertContent.defaultProps = {
410
- theme: DEFAULT_THEME
411
- };
412
-
413
- const COMPONENT_ID$1 = 'notifications.global-alert.icon';
414
- const sizeStyles = props => {
415
- const size = props.theme.iconSizes.md;
416
- const marginTop = math(`(${props.theme.space.base * 5} - ${size}) / 2`);
417
- const marginHorizontal = `${props.theme.space.base * 2}px`;
418
- return css(["margin-top:", ";margin-", ":", ";width:", ";height:", ";"], marginTop, props.theme.rtl ? 'left' : 'right', marginHorizontal, size, size);
419
- };
420
- const StyledGlobalAlertIcon = styled(_ref => {
421
- let {
422
- children,
423
- ...props
424
- } = _ref;
425
- return React__default.cloneElement(Children.only(children), props);
426
- }).attrs({
427
- 'data-garden-id': COMPONENT_ID$1,
428
- 'data-garden-version': '9.0.0-next.2'
429
- }).withConfig({
430
- displayName: "StyledGlobalAlertIcon",
431
- componentId: "sc-84ne9k-0"
432
- })(["flex-shrink:0;", ";", ";"], sizeStyles, props => retrieveComponentStyles(COMPONENT_ID$1, props));
433
- StyledGlobalAlertIcon.defaultProps = {
434
- theme: DEFAULT_THEME
435
- };
436
-
437
- const COMPONENT_ID = 'notifications.global-alert.title';
438
- const colorStyles = props => {
439
- let color;
440
- switch (props.alertType) {
441
- case 'success':
442
- case 'error':
443
- color = props.theme.palette.white;
444
- break;
445
- case 'warning':
446
- color = getColor('warningHue', 900, props.theme);
447
- break;
448
- case 'info':
449
- color = getColor('primaryHue', 800, props.theme);
450
- break;
451
- }
452
- return css(["color:", ";"], color);
453
- };
454
- const StyledGlobalAlertTitle = styled.div.attrs({
455
- 'data-garden-id': COMPONENT_ID,
456
- 'data-garden-version': '9.0.0-next.2'
457
- }).withConfig({
458
- displayName: "StyledGlobalAlertTitle",
459
- componentId: "sc-10clqbo-0"
460
- })(["display:inline;margin-", ":", "px;font-weight:", ";", ";", ";"], props => props.theme.rtl ? 'left' : 'right', props => props.theme.space.base * 2, props => props.isRegular ? props.theme.fontWeights.regular : props.theme.fontWeights.semibold, colorStyles, props => retrieveComponentStyles(COMPONENT_ID, props));
461
- StyledGlobalAlertTitle.defaultProps = {
462
- theme: DEFAULT_THEME
463
- };
464
-
465
- var _g$2, _circle$2;
466
- function _extends$5() { _extends$5 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$5.apply(this, arguments); }
467
- var SvgAlertErrorStroke = function SvgAlertErrorStroke(props) {
468
- return /*#__PURE__*/React.createElement("svg", _extends$5({
469
- xmlns: "http://www.w3.org/2000/svg",
470
- width: 16,
471
- height: 16,
472
- focusable: "false",
473
- viewBox: "0 0 16 16",
474
- "aria-hidden": "true"
475
- }, props), _g$2 || (_g$2 = /*#__PURE__*/React.createElement("g", {
476
- fill: "none",
477
- stroke: "currentColor"
478
- }, /*#__PURE__*/React.createElement("circle", {
479
- cx: 7.5,
480
- cy: 8.5,
481
- r: 7
482
- }), /*#__PURE__*/React.createElement("path", {
483
- strokeLinecap: "round",
484
- d: "M7.5 4.5V9"
485
- }))), _circle$2 || (_circle$2 = /*#__PURE__*/React.createElement("circle", {
486
- cx: 7.5,
487
- cy: 12,
488
- r: 1,
489
- fill: "currentColor"
490
- })));
491
- };
492
-
493
- var _g$1;
494
- function _extends$4() { _extends$4 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$4.apply(this, arguments); }
495
- var SvgCheckCircleStroke = function SvgCheckCircleStroke(props) {
496
- return /*#__PURE__*/React.createElement("svg", _extends$4({
497
- xmlns: "http://www.w3.org/2000/svg",
498
- width: 16,
499
- height: 16,
500
- focusable: "false",
501
- viewBox: "0 0 16 16",
502
- "aria-hidden": "true"
503
- }, props), _g$1 || (_g$1 = /*#__PURE__*/React.createElement("g", {
504
- fill: "none",
505
- stroke: "currentColor"
506
- }, /*#__PURE__*/React.createElement("path", {
507
- strokeLinecap: "round",
508
- strokeLinejoin: "round",
509
- d: "M4 9l2.5 2.5 5-5"
510
- }), /*#__PURE__*/React.createElement("circle", {
511
- cx: 7.5,
512
- cy: 8.5,
513
- r: 7
514
- }))));
515
- };
516
-
517
- var _path$2, _circle$1;
518
- function _extends$3() { _extends$3 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$3.apply(this, arguments); }
519
- var SvgAlertWarningStroke = function SvgAlertWarningStroke(props) {
520
- return /*#__PURE__*/React.createElement("svg", _extends$3({
521
- xmlns: "http://www.w3.org/2000/svg",
522
- width: 16,
523
- height: 16,
524
- focusable: "false",
525
- viewBox: "0 0 16 16",
526
- "aria-hidden": "true"
527
- }, props), _path$2 || (_path$2 = /*#__PURE__*/React.createElement("path", {
528
- fill: "none",
529
- stroke: "currentColor",
530
- strokeLinecap: "round",
531
- d: "M.88 13.77L7.06 1.86c.19-.36.7-.36.89 0l6.18 11.91c.17.33-.07.73-.44.73H1.32c-.37 0-.61-.4-.44-.73zM7.5 6v3.5"
532
- })), _circle$1 || (_circle$1 = /*#__PURE__*/React.createElement("circle", {
533
- cx: 7.5,
534
- cy: 12,
535
- r: 1,
536
- fill: "currentColor"
537
- })));
538
- };
539
-
540
- var _g, _circle;
541
- function _extends$2() { _extends$2 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$2.apply(this, arguments); }
542
- var SvgInfoStroke = function SvgInfoStroke(props) {
543
- return /*#__PURE__*/React.createElement("svg", _extends$2({
544
- xmlns: "http://www.w3.org/2000/svg",
545
- width: 16,
546
- height: 16,
547
- focusable: "false",
548
- viewBox: "0 0 16 16",
549
- "aria-hidden": "true"
550
- }, props), _g || (_g = /*#__PURE__*/React.createElement("g", {
551
- stroke: "currentColor"
552
- }, /*#__PURE__*/React.createElement("circle", {
553
- cx: 7.5,
554
- cy: 8.5,
555
- r: 7,
556
- fill: "none"
557
- }), /*#__PURE__*/React.createElement("path", {
558
- strokeLinecap: "round",
559
- d: "M7.5 12.5V8"
560
- }))), _circle || (_circle = /*#__PURE__*/React.createElement("circle", {
561
- cx: 7.5,
562
- cy: 5,
563
- r: 1,
564
- fill: "currentColor"
565
- })));
566
- };
567
-
568
- const validationIcons = {
569
- success: SvgCheckCircleStroke,
570
- error: SvgAlertErrorStroke,
571
- warning: SvgAlertWarningStroke,
572
- info: SvgInfoStroke
573
- };
574
- const validationHues = {
575
- success: 'successHue',
576
- error: 'dangerHue',
577
- warning: 'warningHue',
578
- info: 'neutralHue'
579
- };
580
-
581
- const NotificationsContext = createContext(undefined);
582
- const useNotificationsContext = () => {
583
- return useContext(NotificationsContext);
584
- };
585
-
586
- const Alert = React__default.forwardRef((_ref, ref) => {
587
- let {
588
- role,
589
- ...props
590
- } = _ref;
591
- const hue = validationHues[props.type];
592
- const Icon = validationIcons[props.type];
593
- return React__default.createElement(NotificationsContext.Provider, {
594
- value: hue
595
- }, React__default.createElement(StyledAlert, _extends$6({
596
- ref: ref,
597
- hue: hue,
598
- role: role === undefined ? 'alert' : role
599
- }, props), React__default.createElement(StyledIcon, {
600
- hue: hue
601
- }, React__default.createElement(Icon, null)), props.children));
602
- });
603
- Alert.displayName = 'Alert';
604
- Alert.propTypes = {
605
- type: PropTypes.oneOf(TYPE).isRequired
606
- };
607
-
608
- const Notification = forwardRef((_ref, ref) => {
609
- let {
610
- role,
611
- ...props
612
- } = _ref;
613
- const Icon = props.type ? validationIcons[props.type] : SvgInfoStroke;
614
- const hue = props.type && validationHues[props.type];
615
- return React__default.createElement(StyledNotification, _extends$6({
616
- ref: ref,
617
- type: props.type,
618
- isFloating: true
619
- }, props, {
620
- role: role === undefined ? 'status' : role
621
- }), props.type && React__default.createElement(StyledIcon, {
622
- hue: hue
623
- }, React__default.createElement(Icon, null)), props.children);
624
- });
625
- Notification.displayName = 'Notification';
626
- Notification.propTypes = {
627
- type: PropTypes.oneOf(TYPE)
628
- };
629
-
630
- const Well = React__default.forwardRef((props, ref) => React__default.createElement(StyledWell, _extends$6({
631
- ref: ref
632
- }, props)));
633
- Well.displayName = 'Well';
634
- Well.propTypes = {
635
- isRecessed: PropTypes.bool,
636
- isFloating: PropTypes.bool
637
- };
638
-
639
- var _path$1;
640
- function _extends$1() { _extends$1 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$1.apply(this, arguments); }
641
- var SvgXStroke$1 = function SvgXStroke(props) {
642
- return /*#__PURE__*/React.createElement("svg", _extends$1({
643
- xmlns: "http://www.w3.org/2000/svg",
644
- width: 12,
645
- height: 12,
646
- focusable: "false",
647
- viewBox: "0 0 12 12",
648
- "aria-hidden": "true"
649
- }, props), _path$1 || (_path$1 = /*#__PURE__*/React.createElement("path", {
650
- stroke: "currentColor",
651
- strokeLinecap: "round",
652
- d: "M3 9l6-6m0 6L3 3"
653
- })));
654
- };
655
-
656
- const Close = React__default.forwardRef((props, ref) => {
657
- const ariaLabel = useText(Close, props, 'aria-label', 'Close');
658
- const hue = useNotificationsContext();
659
- return React__default.createElement(StyledClose, _extends$6({
660
- ref: ref,
661
- hue: hue,
662
- "aria-label": ariaLabel
663
- }, props), React__default.createElement(SvgXStroke$1, null));
664
- });
665
- Close.displayName = 'Close';
666
-
667
- const Paragraph = React__default.forwardRef((props, ref) => React__default.createElement(StyledParagraph, _extends$6({
668
- ref: ref
669
- }, props)));
670
- Paragraph.displayName = 'Paragraph';
671
-
672
- const Title = React__default.forwardRef((props, ref) => React__default.createElement(StyledTitle, _extends$6({
673
- ref: ref
674
- }, props)));
675
- Title.displayName = 'Title';
676
-
677
- const getInitialState = () => {
678
- return {
679
- toasts: []
680
- };
681
- };
682
- const toasterReducer = (state, action) => {
683
- switch (action.type) {
684
- case 'ADD_TOAST':
685
- {
686
- return {
687
- ...state,
688
- toasts: [...state.toasts, action.payload]
689
- };
690
- }
691
- case 'REMOVE_TOAST':
692
- {
693
- const filteredToasts = state.toasts.filter(toast => toast.id !== action.payload);
694
- return {
695
- ...state,
696
- toasts: filteredToasts
697
- };
698
- }
699
- case 'UPDATE_TOAST':
700
- {
701
- const updatedToasts = state.toasts.map(toast => {
702
- if (toast.id !== action.payload.id) {
703
- return toast;
704
- }
705
- const updatedToast = toast;
706
- const {
707
- content,
708
- ...newOptions
709
- } = action.payload.options;
710
- if (content) {
711
- updatedToast.content = content;
712
- }
713
- updatedToast.options = {
714
- ...updatedToast.options,
715
- ...newOptions
716
- };
717
- return updatedToast;
718
- });
719
- return {
720
- ...state,
721
- toasts: updatedToasts
722
- };
723
- }
724
- case 'REMOVE_ALL_TOASTS':
725
- {
726
- return {
727
- ...state,
728
- toasts: []
729
- };
730
- }
731
- default:
732
- throw new Error('Invalid toaster reducer action');
733
- }
734
- };
735
-
736
- const ToastContext = createContext(undefined);
737
-
738
- const DEFAULT_TOAST_OPTIONS = {
739
- autoDismiss: 5000,
740
- placement: 'top-end'
741
- };
742
- const useToast = () => {
743
- const context = useContext(ToastContext);
744
- if (context === undefined) {
745
- throw new Error('useToast() must be used within a "ToastProvider"');
746
- }
747
- const {
748
- dispatch,
749
- state
750
- } = context;
751
- const addToast = useCallback(function (content) {
752
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
753
- const mergedOptions = {
754
- ...DEFAULT_TOAST_OPTIONS,
755
- ...options
756
- };
757
- const newToast = {
758
- id: mergedOptions.id || uid(content),
759
- content,
760
- options: mergedOptions
761
- };
762
- dispatch({
763
- type: 'ADD_TOAST',
764
- payload: newToast
765
- });
766
- return newToast.id;
767
- }, [dispatch]);
768
- const removeToast = useCallback(id => {
769
- dispatch({
770
- type: 'REMOVE_TOAST',
771
- payload: id
772
- });
773
- }, [dispatch]);
774
- const updateToast = useCallback((id, options) => {
775
- dispatch({
776
- type: 'UPDATE_TOAST',
777
- payload: {
778
- id,
779
- options
780
- }
781
- });
782
- }, [dispatch]);
783
- const removeAllToasts = useCallback(() => {
784
- dispatch({
785
- type: 'REMOVE_ALL_TOASTS'
786
- });
787
- }, [dispatch]);
788
- return {
789
- addToast,
790
- removeToast,
791
- updateToast,
792
- removeAllToasts,
793
- toasts: state.toasts
794
- };
795
- };
796
-
797
- const Toast = _ref => {
798
- let {
799
- toast,
800
- pauseTimers
801
- } = _ref;
802
- const {
803
- removeToast
804
- } = useToast();
805
- const {
806
- id
807
- } = toast;
808
- const {
809
- autoDismiss
810
- } = toast.options;
811
- const [remainingTime, setRemainingTime] = useState(NaN);
812
- const startTimeRef = useRef(Date.now());
813
- const previousRemainingTimeRef = useRef(remainingTime);
814
- useEffect(() => {
815
- if (typeof autoDismiss === 'number') {
816
- setRemainingTime(autoDismiss);
817
- } else {
818
- setRemainingTime(NaN);
819
- }
820
- }, [autoDismiss]);
821
- useEffect(() => {
822
- if (pauseTimers && !isNaN(remainingTime)) {
823
- previousRemainingTimeRef.current = remainingTime - (Date.now() - startTimeRef.current);
824
- setRemainingTime(NaN);
825
- } else if (!pauseTimers && isNaN(remainingTime) && !isNaN(previousRemainingTimeRef.current)) {
826
- setRemainingTime(previousRemainingTimeRef.current);
827
- }
828
- }, [pauseTimers, remainingTime]);
829
- useEffect(() => {
830
- let timeout;
831
- if (!isNaN(remainingTime)) {
832
- startTimeRef.current = Date.now();
833
- timeout = setTimeout(() => {
834
- removeToast(id);
835
- }, remainingTime);
836
- }
837
- return () => {
838
- clearTimeout(timeout);
839
- };
840
- }, [id, pauseTimers, remainingTime, removeToast]);
841
- const close = useCallback(() => {
842
- removeToast(toast.id);
843
- }, [removeToast, toast.id]);
844
- return toast.content({
845
- close
846
- });
847
- };
848
-
849
- const TRANSITION_CLASS = 'garden-toast-transition';
850
- const DEFAULT_DURATION = '400ms';
851
- const StyledFadeInTransition = styled.div.withConfig({
852
- displayName: "styled__StyledFadeInTransition",
853
- componentId: "sc-nq0usb-0"
854
- })(["transition:opacity ", " ease-in 300ms;opacity:", ";margin-bottom:", "px;", " &.", "-enter{transform:translateY( ", " );opacity:0;max-height:0;}&.", "-enter-active{transform:translateY(0);transition:opacity ", " ease-in,transform ", " cubic-bezier(0.15,0.85,0.35,1.2),max-height ", ";opacity:1;max-height:500px;}&.", "-exit{opacity:1;max-height:500px;}&.", "-exit-active{transition:opacity 550ms ease-out,max-height ", " linear 150ms;opacity:0;max-height:0;}"], DEFAULT_DURATION, p => p.isHidden ? '0 !important' : 1, p => p.theme.space.base * 2, p => p.isHidden && hideVisually(), TRANSITION_CLASS, props => {
855
- if (props.placement === 'bottom-start' || props.placement === 'bottom' || props.placement === 'bottom-end') {
856
- return '100px';
857
- }
858
- return '-100px';
859
- }, TRANSITION_CLASS, DEFAULT_DURATION, DEFAULT_DURATION, DEFAULT_DURATION, TRANSITION_CLASS, TRANSITION_CLASS, DEFAULT_DURATION);
860
- StyledFadeInTransition.defaultProps = {
861
- theme: DEFAULT_THEME
862
- };
863
- const placementStyles = props => {
864
- const verticalDistance = `${props.theme.space.base * 16}px`;
865
- const horizontalDistance = `${props.theme.space.base * 3}px`;
866
- const topLeftStyles = css(["top:", ";left:", ";"], verticalDistance, horizontalDistance);
867
- const topStyles = css(["top:", ";left:50%;transform:translate(-50%,0);"], verticalDistance);
868
- const topRightStyles = css(["top:", ";right:", ";"], verticalDistance, horizontalDistance);
869
- const bottomLeftStyles = css(["bottom:", ";left:", ";"], verticalDistance, horizontalDistance);
870
- const bottomStyles = css(["bottom:", ";left:50%;transform:translate(-50%,0);"], verticalDistance);
871
- const bottomRightStyles = css(["right:", ";bottom:", ";"], horizontalDistance, verticalDistance);
872
- switch (props.toastPlacement) {
873
- case 'top-start':
874
- if (props.theme.rtl) {
875
- return topRightStyles;
876
- }
877
- return topLeftStyles;
878
- case 'top':
879
- return topStyles;
880
- case 'top-end':
881
- if (props.theme.rtl) {
882
- return topLeftStyles;
883
- }
884
- return topRightStyles;
885
- case 'bottom-start':
886
- if (props.theme.rtl) {
887
- return bottomRightStyles;
888
- }
889
- return bottomLeftStyles;
890
- case 'bottom':
891
- return bottomStyles;
892
- case 'bottom-end':
893
- if (props.theme.rtl) {
894
- return bottomLeftStyles;
895
- }
896
- return bottomRightStyles;
897
- default:
898
- return '';
899
- }
900
- };
901
- const StyledTransitionContainer = styled.div.withConfig({
902
- displayName: "styled__StyledTransitionContainer",
903
- componentId: "sc-nq0usb-1"
904
- })(["position:fixed;z-index:", ";", ";"], props => props.toastZIndex, placementStyles);
905
- StyledTransitionContainer.defaultProps = {
906
- theme: DEFAULT_THEME
907
- };
908
-
909
- const ToastSlot = _ref => {
910
- let {
911
- toasts,
912
- placement,
913
- zIndex,
914
- limit,
915
- ...props
916
- } = _ref;
917
- const [pauseTimers, setPauseTimers] = useState(false);
918
- const theme = useContext(ThemeContext);
919
- const environment = useDocument(theme);
920
- const handleVisibilityChange = useCallback(e => {
921
- if (e.target.visibilityState === 'visible') {
922
- setPauseTimers(false);
923
- } else {
924
- setPauseTimers(true);
925
- }
926
- }, []);
927
- useEffect(() => {
928
- if (environment) {
929
- environment.addEventListener('visibilitychange', handleVisibilityChange);
930
- }
931
- return () => {
932
- if (environment) {
933
- environment.removeEventListener('visibilitychange', handleVisibilityChange);
934
- }
935
- };
936
- }, [environment, handleVisibilityChange]);
937
- const handleMouseEnter = useCallback(() => {
938
- setPauseTimers(true);
939
- }, []);
940
- const handleMouseLeave = useCallback(() => {
941
- setPauseTimers(false);
942
- }, []);
943
- const isHidden = useCallback(index => {
944
- if (placement === 'bottom' || placement === 'bottom-start' || placement === 'bottom-end') {
945
- return index < toasts.length - limit;
946
- }
947
- return index >= limit;
948
- }, [limit, placement, toasts.length]);
949
- return React__default.createElement(StyledTransitionContainer, _extends$6({
950
- key: placement,
951
- toastPlacement: placement,
952
- toastZIndex: zIndex,
953
- onMouseEnter: handleMouseEnter,
954
- onMouseLeave: handleMouseLeave
955
- }, props), React__default.createElement(TransitionGroup, null, toasts.map((toast, index) => {
956
- const transitionRef = React__default.createRef();
957
- return React__default.createElement(CSSTransition, {
958
- key: toast.id,
959
- timeout: {
960
- enter: 400,
961
- exit: 550
962
- },
963
- unmountOnExit: true,
964
- classNames: TRANSITION_CLASS,
965
- nodeRef: transitionRef
966
- }, React__default.createElement(StyledFadeInTransition, {
967
- ref: transitionRef,
968
- placement: placement,
969
- isHidden: isHidden(index)
970
- }, React__default.createElement(Toast, {
971
- toast: toast,
972
- pauseTimers: pauseTimers || isHidden(index)
973
- })));
974
- })));
975
- };
976
-
977
- const ToastProvider = _ref => {
978
- let {
979
- limit,
980
- zIndex,
981
- placementProps = {},
982
- children
983
- } = _ref;
984
- const [state, dispatch] = useReducer(toasterReducer, getInitialState());
985
- const contextValue = useMemo(() => ({
986
- state,
987
- dispatch
988
- }), [state, dispatch]);
989
- const toastsByPlacement = useCallback(placement => {
990
- let matchingToasts = state.toasts.filter(toast => toast.options.placement === placement);
991
- if (placement === 'bottom' || placement === 'bottom-start' || placement === 'bottom-end') {
992
- matchingToasts = matchingToasts.reverse();
993
- }
994
- return React__default.createElement(ToastSlot, _extends$6({
995
- placement: placement,
996
- toasts: matchingToasts,
997
- zIndex: zIndex,
998
- limit: limit
999
- }, placementProps[placement]));
1000
- }, [limit, state.toasts, zIndex, placementProps]);
1001
- return React__default.createElement(ToastContext.Provider, {
1002
- value: contextValue
1003
- }, toastsByPlacement('top-start'), toastsByPlacement('top'), toastsByPlacement('top-end'), children, toastsByPlacement('bottom-start'), toastsByPlacement('bottom'), toastsByPlacement('bottom-end'));
1004
- };
1005
- ToastProvider.displayName = 'ToastProvider';
1006
- ToastProvider.defaultProps = {
1007
- limit: 4
1008
- };
1009
- ToastProvider.propTypes = {
1010
- limit: PropTypes.number,
1011
- zIndex: PropTypes.number,
1012
- placementProps: PropTypes.object
1013
- };
1014
-
1015
- const GlobalAlertContext = createContext({
1016
- type: 'info'
1017
- });
1018
- const useGlobalAlertContext = () => useContext(GlobalAlertContext);
1019
-
1020
- const GlobalAlertButton = forwardRef((_ref, ref) => {
1021
- let {
1022
- isBasic,
1023
- ...props
1024
- } = _ref;
1025
- const {
1026
- type
1027
- } = useGlobalAlertContext();
1028
- return React__default.createElement(StyledGlobalAlertButton, _extends$6({
1029
- ref: ref,
1030
- alertType: type
1031
- }, props, {
1032
- isPrimary: !isBasic,
1033
- isBasic: isBasic
1034
- }));
1035
- });
1036
- GlobalAlertButton.displayName = 'GlobalAlert.Button';
1037
- GlobalAlertButton.propTypes = {
1038
- isBasic: PropTypes.bool
1039
- };
1040
-
1041
- var _path;
1042
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
1043
- var SvgXStroke = function SvgXStroke(props) {
1044
- return /*#__PURE__*/React.createElement("svg", _extends({
1045
- xmlns: "http://www.w3.org/2000/svg",
1046
- width: 16,
1047
- height: 16,
1048
- focusable: "false",
1049
- viewBox: "0 0 16 16",
1050
- "aria-hidden": "true"
1051
- }, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
1052
- stroke: "currentColor",
1053
- strokeLinecap: "round",
1054
- d: "M3 13L13 3m0 10L3 3"
1055
- })));
1056
- };
1057
-
1058
- const GlobalAlertClose = forwardRef((props, ref) => {
1059
- const {
1060
- type
1061
- } = useGlobalAlertContext();
1062
- const label = useText(GlobalAlertClose, props, 'aria-label', 'Close');
1063
- return React__default.createElement(StyledGlobalAlertClose, _extends$6({
1064
- ref: ref,
1065
- alertType: type
1066
- }, props), React__default.createElement(SvgXStroke, {
1067
- role: "img",
1068
- "aria-label": label
1069
- }));
1070
- });
1071
- GlobalAlertClose.displayName = 'GlobalAlert.Close';
1072
-
1073
- const GlobalAlertContent = forwardRef((props, ref) => {
1074
- return React__default.createElement(StyledGlobalAlertContent, _extends$6({
1075
- ref: ref
1076
- }, props));
1077
- });
1078
- GlobalAlertContent.displayName = 'GlobalAlert.Content';
1079
-
1080
- const GlobalAlertTitle = forwardRef((props, ref) => {
1081
- const {
1082
- type
1083
- } = useGlobalAlertContext();
1084
- return React__default.createElement(StyledGlobalAlertTitle, _extends$6({
1085
- alertType: type,
1086
- ref: ref
1087
- }, props));
1088
- });
1089
- GlobalAlertTitle.displayName = 'GlobalAlert.Title';
1090
- GlobalAlertTitle.propTypes = {
1091
- isRegular: PropTypes.bool
1092
- };
1093
-
1094
- const GlobalAlertComponent = forwardRef((_ref, ref) => {
1095
- let {
1096
- type,
1097
- ...props
1098
- } = _ref;
1099
- return React__default.createElement(GlobalAlertContext.Provider, {
1100
- value: useMemo(() => ({
1101
- type
1102
- }), [type])
1103
- }, React__default.createElement(StyledGlobalAlert, _extends$6({
1104
- ref: ref,
1105
- role: "status",
1106
- alertType: type
1107
- }, props), {
1108
- success: React__default.createElement(StyledGlobalAlertIcon, null, React__default.createElement(SvgCheckCircleStroke, null)),
1109
- error: React__default.createElement(StyledGlobalAlertIcon, null, React__default.createElement(SvgAlertErrorStroke, null)),
1110
- warning: React__default.createElement(StyledGlobalAlertIcon, null, React__default.createElement(SvgAlertWarningStroke, null)),
1111
- info: React__default.createElement(StyledGlobalAlertIcon, null, React__default.createElement(SvgInfoStroke, null))
1112
- }[type], props.children));
1113
- });
1114
- GlobalAlertComponent.displayName = 'GlobalAlert';
1115
- const GlobalAlert = GlobalAlertComponent;
1116
- GlobalAlert.Button = GlobalAlertButton;
1117
- GlobalAlert.Close = GlobalAlertClose;
1118
- GlobalAlert.Content = GlobalAlertContent;
1119
- GlobalAlert.Title = GlobalAlertTitle;
1120
- GlobalAlert.propTypes = {
1121
- type: PropTypes.oneOf(TYPE).isRequired
1122
- };
1123
-
1124
- export { Alert, Close, GlobalAlert, Notification, Paragraph, Title, ToastProvider, Well, useToast };