@xsolla/xui-toast 0.158.0 → 0.160.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/README.md +124 -166
- package/native/index.d.mts +48 -19
- package/native/index.d.ts +48 -19
- package/native/index.js +248 -86
- package/native/index.js.map +1 -1
- package/native/index.mjs +260 -87
- package/native/index.mjs.map +1 -1
- package/package.json +5 -4
- package/web/index.d.mts +48 -19
- package/web/index.d.ts +48 -19
- package/web/index.js +248 -86
- package/web/index.js.map +1 -1
- package/web/index.mjs +260 -87
- package/web/index.mjs.map +1 -1
package/native/index.d.ts
CHANGED
|
@@ -1,29 +1,54 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import React__default, { ReactNode } from 'react';
|
|
2
|
+
import React__default, { ReactNode, ReactElement } from 'react';
|
|
3
3
|
import { ThemeOverrideProps } from '@xsolla/xui-core';
|
|
4
4
|
|
|
5
|
-
type
|
|
5
|
+
type ToastType = "alert" | "success" | "neutral" | "warning";
|
|
6
6
|
type ToastPosition = "top" | "bottom";
|
|
7
7
|
type ToastAlign = "left" | "center" | "right";
|
|
8
8
|
interface ToastData {
|
|
9
9
|
id: string;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
type: ToastType;
|
|
11
|
+
title?: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
icon?: boolean | ReactNode;
|
|
14
|
+
action?: ReactElement;
|
|
15
|
+
showCloseButton?: boolean;
|
|
16
|
+
progress?: boolean;
|
|
13
17
|
duration?: number;
|
|
14
18
|
}
|
|
19
|
+
interface ToastColorScheme {
|
|
20
|
+
background: string;
|
|
21
|
+
text: string;
|
|
22
|
+
descriptionText: string;
|
|
23
|
+
divider: string;
|
|
24
|
+
actionText: string;
|
|
25
|
+
shadow?: string;
|
|
26
|
+
backdropFilter?: string;
|
|
27
|
+
}
|
|
15
28
|
interface ToastProps extends ThemeOverrideProps {
|
|
16
29
|
id: string;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
30
|
+
type?: ToastType;
|
|
31
|
+
title?: string;
|
|
32
|
+
description?: string;
|
|
33
|
+
icon?: boolean | ReactNode;
|
|
34
|
+
action?: ReactElement;
|
|
35
|
+
showCloseButton?: boolean;
|
|
36
|
+
progress?: boolean;
|
|
20
37
|
duration?: number;
|
|
21
38
|
onClose?: () => void;
|
|
39
|
+
/** Internal color override for product-specific toast surfaces */
|
|
40
|
+
colorScheme?: ToastColorScheme;
|
|
41
|
+
/** Test ID for testing frameworks */
|
|
42
|
+
testID?: string;
|
|
22
43
|
}
|
|
23
44
|
interface ToastOptions {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
45
|
+
type?: ToastType;
|
|
46
|
+
title?: string;
|
|
47
|
+
description?: string;
|
|
48
|
+
icon?: boolean | ReactNode;
|
|
49
|
+
action?: ReactElement;
|
|
50
|
+
showCloseButton?: boolean;
|
|
51
|
+
progress?: boolean;
|
|
27
52
|
duration?: number;
|
|
28
53
|
}
|
|
29
54
|
interface ToastGroupProps extends ThemeOverrideProps {
|
|
@@ -32,6 +57,8 @@ interface ToastGroupProps extends ThemeOverrideProps {
|
|
|
32
57
|
align?: ToastAlign;
|
|
33
58
|
maxWidth?: number;
|
|
34
59
|
onDismiss: (id: string) => void;
|
|
60
|
+
/** Test ID for testing frameworks */
|
|
61
|
+
testID?: string;
|
|
35
62
|
}
|
|
36
63
|
interface ToastContextType {
|
|
37
64
|
toasts: ToastData[];
|
|
@@ -45,11 +72,13 @@ interface ToastProviderProps {
|
|
|
45
72
|
align?: ToastAlign;
|
|
46
73
|
defaultDuration?: number;
|
|
47
74
|
maxWidth?: number;
|
|
75
|
+
/** Test ID for testing frameworks */
|
|
76
|
+
testID?: string;
|
|
48
77
|
}
|
|
49
78
|
|
|
50
79
|
declare const Toast: React__default.FC<ToastProps>;
|
|
51
80
|
|
|
52
|
-
declare const ToastGroup: React__default.MemoExoticComponent<({ toasts, position, align, maxWidth, onDismiss, themeMode, themeProductContext, }: ToastGroupProps) => React__default.ReactPortal | null>;
|
|
81
|
+
declare const ToastGroup: React__default.MemoExoticComponent<({ toasts, position, align, maxWidth, onDismiss, testID, themeMode, themeProductContext, }: ToastGroupProps) => React__default.ReactPortal | null>;
|
|
53
82
|
|
|
54
83
|
declare const ToastProvider: React__default.FC<ToastProviderProps>;
|
|
55
84
|
|
|
@@ -58,14 +87,14 @@ declare const ToastContext: React.Context<ToastContextType | null>;
|
|
|
58
87
|
interface UseToastReturn {
|
|
59
88
|
/** Show a toast with custom options */
|
|
60
89
|
toast: (options: ToastOptions) => string;
|
|
90
|
+
/** Show an alert toast */
|
|
91
|
+
alert: (options: Omit<ToastOptions, "type">) => string;
|
|
61
92
|
/** Show a success toast */
|
|
62
|
-
success: (
|
|
63
|
-
/** Show
|
|
64
|
-
|
|
93
|
+
success: (options: Omit<ToastOptions, "type">) => string;
|
|
94
|
+
/** Show a neutral toast */
|
|
95
|
+
neutral: (options: Omit<ToastOptions, "type">) => string;
|
|
65
96
|
/** Show a warning toast */
|
|
66
|
-
warning: (
|
|
67
|
-
/** Show an error toast */
|
|
68
|
-
error: (message: string, options?: Omit<ToastOptions, "message" | "variant">) => string;
|
|
97
|
+
warning: (options: Omit<ToastOptions, "type">) => string;
|
|
69
98
|
/** Dismiss a specific toast by ID */
|
|
70
99
|
dismiss: (id: string) => void;
|
|
71
100
|
/** Dismiss all toasts */
|
|
@@ -73,4 +102,4 @@ interface UseToastReturn {
|
|
|
73
102
|
}
|
|
74
103
|
declare const useToast: () => UseToastReturn;
|
|
75
104
|
|
|
76
|
-
export { Toast, type ToastAlign, ToastContext, type ToastContextType, type ToastData, ToastGroup, type ToastGroupProps, type ToastOptions, type ToastPosition, type ToastProps, ToastProvider, type ToastProviderProps, type
|
|
105
|
+
export { Toast, type ToastAlign, type ToastColorScheme, ToastContext, type ToastContextType, type ToastData, ToastGroup, type ToastGroupProps, type ToastOptions, type ToastPosition, type ToastProps, ToastProvider, type ToastProviderProps, type ToastType, type UseToastReturn, useToast };
|
package/native/index.js
CHANGED
|
@@ -242,6 +242,8 @@ var Text = ({
|
|
|
242
242
|
numberOfLines,
|
|
243
243
|
id,
|
|
244
244
|
role,
|
|
245
|
+
testID,
|
|
246
|
+
"data-testid": dataTestId,
|
|
245
247
|
style: styleProp,
|
|
246
248
|
...props
|
|
247
249
|
}) => {
|
|
@@ -271,7 +273,7 @@ var Text = ({
|
|
|
271
273
|
{
|
|
272
274
|
style: baseStyle,
|
|
273
275
|
numberOfLines,
|
|
274
|
-
testID: id,
|
|
276
|
+
testID: dataTestId || testID || id,
|
|
275
277
|
accessibilityRole,
|
|
276
278
|
children
|
|
277
279
|
}
|
|
@@ -282,7 +284,13 @@ var Text = ({
|
|
|
282
284
|
var import_react = __toESM(require("react"));
|
|
283
285
|
var import_react_native3 = require("react-native");
|
|
284
286
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
285
|
-
var Icon = ({
|
|
287
|
+
var Icon = ({
|
|
288
|
+
children,
|
|
289
|
+
color,
|
|
290
|
+
size,
|
|
291
|
+
testID,
|
|
292
|
+
"data-testid": dataTestId
|
|
293
|
+
}) => {
|
|
286
294
|
const style = {
|
|
287
295
|
width: typeof size === "number" ? size : void 0,
|
|
288
296
|
height: typeof size === "number" ? size : void 0,
|
|
@@ -299,50 +307,104 @@ var Icon = ({ children, color, size }) => {
|
|
|
299
307
|
}
|
|
300
308
|
return child;
|
|
301
309
|
});
|
|
302
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native3.View, { style, children: childrenWithProps });
|
|
310
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native3.View, { style, testID: dataTestId || testID, children: childrenWithProps });
|
|
303
311
|
};
|
|
304
312
|
|
|
305
313
|
// src/Toast.tsx
|
|
306
314
|
var import_xui_core = require("@xsolla/xui-core");
|
|
307
|
-
var
|
|
315
|
+
var import_xui_icons_base = require("@xsolla/xui-icons-base");
|
|
308
316
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
309
|
-
var
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
case "warning":
|
|
315
|
-
case "error":
|
|
316
|
-
default:
|
|
317
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_xui_icons.AlertCircle, { size, color });
|
|
318
|
-
}
|
|
317
|
+
var TOAST_COLORS = {
|
|
318
|
+
alert: "#ff553d",
|
|
319
|
+
success: "#47d94a",
|
|
320
|
+
neutral: "#7899a1",
|
|
321
|
+
warning: "#ffb95c"
|
|
319
322
|
};
|
|
320
|
-
var
|
|
321
|
-
|
|
323
|
+
var DEFAULT_COLOR_SCHEME = {
|
|
324
|
+
background: "#34474b",
|
|
325
|
+
text: "#ffffff",
|
|
326
|
+
descriptionText: "rgba(255, 255, 255, 0.7)",
|
|
327
|
+
divider: "rgba(255, 255, 255, 0.16)",
|
|
328
|
+
actionText: "#ffffff"
|
|
329
|
+
};
|
|
330
|
+
var getDefaultIcon = (type, size, color) => {
|
|
331
|
+
switch (type) {
|
|
322
332
|
case "success":
|
|
323
|
-
return
|
|
333
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
334
|
+
import_xui_icons_base.CheckCr,
|
|
335
|
+
{
|
|
336
|
+
variant: "solid",
|
|
337
|
+
size,
|
|
338
|
+
color,
|
|
339
|
+
"data-testid": "toast-icon-success"
|
|
340
|
+
}
|
|
341
|
+
);
|
|
342
|
+
case "neutral":
|
|
343
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
344
|
+
import_xui_icons_base.InfoCr,
|
|
345
|
+
{
|
|
346
|
+
variant: "solid",
|
|
347
|
+
size,
|
|
348
|
+
color,
|
|
349
|
+
"data-testid": "toast-icon-neutral"
|
|
350
|
+
}
|
|
351
|
+
);
|
|
324
352
|
case "warning":
|
|
325
|
-
return
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
353
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
354
|
+
import_xui_icons_base.Warning,
|
|
355
|
+
{
|
|
356
|
+
variant: "solid",
|
|
357
|
+
size,
|
|
358
|
+
color,
|
|
359
|
+
"data-testid": "toast-icon-warning"
|
|
360
|
+
}
|
|
361
|
+
);
|
|
362
|
+
case "alert":
|
|
329
363
|
default:
|
|
330
|
-
return
|
|
364
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
365
|
+
import_xui_icons_base.ExclamationMarkCr,
|
|
366
|
+
{
|
|
367
|
+
variant: "solid",
|
|
368
|
+
size,
|
|
369
|
+
color,
|
|
370
|
+
"data-testid": "toast-icon-alert"
|
|
371
|
+
}
|
|
372
|
+
);
|
|
331
373
|
}
|
|
332
374
|
};
|
|
333
375
|
var ANIMATION_DURATION = 200;
|
|
376
|
+
var PROGRESS_HEIGHT = 4;
|
|
377
|
+
var TOAST_CONFIG = {
|
|
378
|
+
minHeight: 56,
|
|
379
|
+
paddingHorizontal: 16,
|
|
380
|
+
paddingVertical: 12,
|
|
381
|
+
borderRadius: 4,
|
|
382
|
+
gap: 12,
|
|
383
|
+
iconSize: 24,
|
|
384
|
+
closeButtonSize: 24,
|
|
385
|
+
closeIconSize: 20,
|
|
386
|
+
fontSize: 16,
|
|
387
|
+
lineHeight: 20,
|
|
388
|
+
maxWidth: 440
|
|
389
|
+
};
|
|
334
390
|
var Toast = ({
|
|
335
391
|
id,
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
392
|
+
type = "neutral",
|
|
393
|
+
title,
|
|
394
|
+
description,
|
|
395
|
+
icon = true,
|
|
396
|
+
action,
|
|
397
|
+
showCloseButton = true,
|
|
398
|
+
progress = false,
|
|
339
399
|
duration,
|
|
340
400
|
onClose,
|
|
401
|
+
colorScheme = DEFAULT_COLOR_SCHEME,
|
|
402
|
+
testID,
|
|
341
403
|
themeMode,
|
|
342
404
|
themeProductContext
|
|
343
405
|
}) => {
|
|
344
|
-
|
|
345
|
-
const config =
|
|
406
|
+
(0, import_xui_core.useResolvedTheme)({ themeMode, themeProductContext });
|
|
407
|
+
const config = TOAST_CONFIG;
|
|
346
408
|
const [visible, setVisible] = (0, import_react2.useState)(false);
|
|
347
409
|
const [dismissing, setDismissing] = (0, import_react2.useState)(false);
|
|
348
410
|
(0, import_react2.useEffect)(() => {
|
|
@@ -359,63 +421,147 @@ var Toast = ({
|
|
|
359
421
|
const timer = setTimeout(handleClose, duration);
|
|
360
422
|
return () => clearTimeout(timer);
|
|
361
423
|
}, [duration]);
|
|
362
|
-
const iconColor =
|
|
363
|
-
const
|
|
424
|
+
const iconColor = TOAST_COLORS[type];
|
|
425
|
+
const shouldShowIcon = icon !== false;
|
|
426
|
+
const displayIcon = icon === true || icon === void 0 ? getDefaultIcon(type, config.iconSize, iconColor) : icon;
|
|
427
|
+
const renderedAction = (0, import_react2.isValidElement)(action) && typeof action.type !== "string" ? (0, import_react2.cloneElement)(action, {
|
|
428
|
+
size: "xs",
|
|
429
|
+
variant: "inverse",
|
|
430
|
+
background: false,
|
|
431
|
+
themeMode: "dark",
|
|
432
|
+
themeProductContext,
|
|
433
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { color: colorScheme.actionText }, children: action.props.children })
|
|
434
|
+
}) : action;
|
|
435
|
+
const hasAction = Boolean(action);
|
|
436
|
+
const hasCloseButton = showCloseButton && Boolean(onClose);
|
|
437
|
+
const hasActions = hasAction || hasCloseButton;
|
|
438
|
+
const role = type === "neutral" || type === "success" ? "status" : "alert";
|
|
439
|
+
const ariaLive = type === "neutral" || type === "success" ? "polite" : "assertive";
|
|
364
440
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
365
441
|
Box,
|
|
366
442
|
{
|
|
367
|
-
|
|
443
|
+
testID,
|
|
444
|
+
backgroundColor: colorScheme.background,
|
|
368
445
|
borderRadius: config.borderRadius,
|
|
369
|
-
paddingHorizontal: config.paddingHorizontal,
|
|
370
|
-
paddingVertical: config.paddingVertical,
|
|
371
446
|
minHeight: config.minHeight,
|
|
372
447
|
flexDirection: "row",
|
|
373
448
|
alignItems: "center",
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
449
|
+
justifyContent: "center",
|
|
450
|
+
overflow: "hidden",
|
|
451
|
+
width: config.maxWidth,
|
|
452
|
+
maxWidth: "100%",
|
|
453
|
+
role,
|
|
454
|
+
"aria-live": ariaLive,
|
|
378
455
|
"data-toast-id": id,
|
|
379
456
|
style: {
|
|
380
457
|
opacity: visible && !dismissing ? 1 : 0,
|
|
381
458
|
transform: visible && !dismissing ? "translateY(0)" : "translateY(-8px)",
|
|
382
|
-
transition: `opacity ${ANIMATION_DURATION}ms ease-out, transform ${ANIMATION_DURATION}ms ease-out
|
|
459
|
+
transition: `opacity ${ANIMATION_DURATION}ms ease-out, transform ${ANIMATION_DURATION}ms ease-out`,
|
|
460
|
+
boxShadow: colorScheme.shadow,
|
|
461
|
+
backdropFilter: colorScheme.backdropFilter
|
|
383
462
|
},
|
|
384
463
|
children: [
|
|
385
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.
|
|
464
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
386
465
|
Box,
|
|
387
466
|
{
|
|
388
|
-
|
|
389
|
-
|
|
467
|
+
flex: 1,
|
|
468
|
+
minHeight: config.minHeight,
|
|
469
|
+
minWidth: 0,
|
|
470
|
+
flexDirection: "row",
|
|
390
471
|
alignItems: "center",
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
472
|
+
gap: config.gap,
|
|
473
|
+
paddingHorizontal: config.paddingHorizontal,
|
|
474
|
+
paddingVertical: config.paddingVertical,
|
|
475
|
+
children: [
|
|
476
|
+
shouldShowIcon && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
477
|
+
Box,
|
|
478
|
+
{
|
|
479
|
+
width: config.iconSize,
|
|
480
|
+
height: config.iconSize,
|
|
481
|
+
alignItems: "center",
|
|
482
|
+
justifyContent: "center",
|
|
483
|
+
flexShrink: 0,
|
|
484
|
+
children: icon === true || icon === void 0 ? displayIcon : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { size: config.iconSize, color: iconColor, children: displayIcon })
|
|
485
|
+
}
|
|
486
|
+
),
|
|
487
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Box, { flex: 1, minWidth: 0, gap: 2, children: [
|
|
488
|
+
title && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
489
|
+
Text,
|
|
490
|
+
{
|
|
491
|
+
color: colorScheme.text,
|
|
492
|
+
fontSize: config.fontSize,
|
|
493
|
+
lineHeight: config.lineHeight,
|
|
494
|
+
fontWeight: "500",
|
|
495
|
+
numberOfLines: 1,
|
|
496
|
+
children: title
|
|
497
|
+
}
|
|
498
|
+
),
|
|
499
|
+
description && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
500
|
+
Text,
|
|
501
|
+
{
|
|
502
|
+
color: colorScheme.descriptionText,
|
|
503
|
+
fontSize: 14,
|
|
504
|
+
lineHeight: 18,
|
|
505
|
+
numberOfLines: 1,
|
|
506
|
+
children: description
|
|
507
|
+
}
|
|
508
|
+
)
|
|
509
|
+
] }),
|
|
510
|
+
hasActions && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
511
|
+
Box,
|
|
512
|
+
{
|
|
513
|
+
height: 32,
|
|
514
|
+
flexDirection: "row",
|
|
515
|
+
alignItems: "center",
|
|
516
|
+
gap: config.gap,
|
|
517
|
+
flexShrink: 0,
|
|
518
|
+
children: [
|
|
519
|
+
renderedAction,
|
|
520
|
+
hasAction && hasCloseButton && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
521
|
+
Box,
|
|
522
|
+
{
|
|
523
|
+
width: 1,
|
|
524
|
+
height: "100%",
|
|
525
|
+
backgroundColor: colorScheme.divider,
|
|
526
|
+
testID: "toast-divider"
|
|
527
|
+
}
|
|
528
|
+
),
|
|
529
|
+
hasCloseButton && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
530
|
+
Box,
|
|
531
|
+
{
|
|
532
|
+
onPress: handleClose,
|
|
533
|
+
width: config.closeButtonSize,
|
|
534
|
+
height: config.closeButtonSize,
|
|
535
|
+
alignItems: "center",
|
|
536
|
+
justifyContent: "center",
|
|
537
|
+
flexShrink: 0,
|
|
538
|
+
role: "button",
|
|
539
|
+
"aria-label": "Dismiss notification",
|
|
540
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
541
|
+
import_xui_icons_base.Remove,
|
|
542
|
+
{
|
|
543
|
+
variant: "line",
|
|
544
|
+
size: config.closeIconSize,
|
|
545
|
+
color: colorScheme.text
|
|
546
|
+
}
|
|
547
|
+
)
|
|
548
|
+
}
|
|
549
|
+
)
|
|
550
|
+
]
|
|
551
|
+
}
|
|
552
|
+
)
|
|
553
|
+
]
|
|
394
554
|
}
|
|
395
555
|
),
|
|
396
|
-
|
|
397
|
-
Text,
|
|
398
|
-
{
|
|
399
|
-
color: theme.colors.content.inverse,
|
|
400
|
-
fontSize: config.fontSize,
|
|
401
|
-
lineHeight: config.lineHeight,
|
|
402
|
-
fontWeight: "500",
|
|
403
|
-
numberOfLines: 2,
|
|
404
|
-
children: message
|
|
405
|
-
}
|
|
406
|
-
) }),
|
|
407
|
-
onClose && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
556
|
+
progress && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
408
557
|
Box,
|
|
409
558
|
{
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
role: "button",
|
|
417
|
-
"aria-label": "Dismiss toast",
|
|
418
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_xui_icons.X, { size: config.closeIconSize, color: theme.colors.content.inverse })
|
|
559
|
+
position: "absolute",
|
|
560
|
+
left: 0,
|
|
561
|
+
right: 0,
|
|
562
|
+
bottom: 0,
|
|
563
|
+
height: PROGRESS_HEIGHT,
|
|
564
|
+
backgroundColor: iconColor
|
|
419
565
|
}
|
|
420
566
|
)
|
|
421
567
|
]
|
|
@@ -428,17 +574,22 @@ Toast.displayName = "Toast";
|
|
|
428
574
|
var import_react3 = require("react");
|
|
429
575
|
var import_xui_core2 = require("@xsolla/xui-core");
|
|
430
576
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
577
|
+
var TOAST_GROUP_CONFIG = {
|
|
578
|
+
containerPadding: 12,
|
|
579
|
+
groupGap: 8
|
|
580
|
+
};
|
|
431
581
|
var ToastGroup = (0, import_react3.memo)(
|
|
432
582
|
({
|
|
433
583
|
toasts,
|
|
434
584
|
position = "top",
|
|
435
585
|
maxWidth,
|
|
436
586
|
onDismiss,
|
|
587
|
+
testID,
|
|
437
588
|
themeMode,
|
|
438
589
|
themeProductContext
|
|
439
590
|
}) => {
|
|
440
|
-
|
|
441
|
-
const config =
|
|
591
|
+
(0, import_xui_core2.useResolvedTheme)({ themeMode, themeProductContext });
|
|
592
|
+
const config = TOAST_GROUP_CONFIG;
|
|
442
593
|
if (toasts.length === 0) {
|
|
443
594
|
return null;
|
|
444
595
|
}
|
|
@@ -446,6 +597,7 @@ var ToastGroup = (0, import_react3.memo)(
|
|
|
446
597
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
447
598
|
Box,
|
|
448
599
|
{
|
|
600
|
+
testID,
|
|
449
601
|
position: "absolute",
|
|
450
602
|
left: 0,
|
|
451
603
|
right: 0,
|
|
@@ -465,9 +617,13 @@ var ToastGroup = (0, import_react3.memo)(
|
|
|
465
617
|
Toast,
|
|
466
618
|
{
|
|
467
619
|
id: toast.id,
|
|
468
|
-
|
|
469
|
-
|
|
620
|
+
type: toast.type,
|
|
621
|
+
title: toast.title,
|
|
622
|
+
description: toast.description,
|
|
470
623
|
icon: toast.icon,
|
|
624
|
+
action: toast.action,
|
|
625
|
+
showCloseButton: toast.showCloseButton,
|
|
626
|
+
progress: toast.progress,
|
|
471
627
|
duration: toast.duration,
|
|
472
628
|
onClose: () => onDismiss(toast.id)
|
|
473
629
|
},
|
|
@@ -499,7 +655,8 @@ var ToastProvider = ({
|
|
|
499
655
|
position = "top",
|
|
500
656
|
align = "center",
|
|
501
657
|
defaultDuration = 5e3,
|
|
502
|
-
maxWidth
|
|
658
|
+
maxWidth,
|
|
659
|
+
testID
|
|
503
660
|
}) => {
|
|
504
661
|
const [toasts, setToasts] = (0, import_react5.useState)([]);
|
|
505
662
|
const dismissToast = (0, import_react5.useCallback)((id) => {
|
|
@@ -514,9 +671,13 @@ var ToastProvider = ({
|
|
|
514
671
|
const duration = options.duration ?? defaultDuration;
|
|
515
672
|
const newToast = {
|
|
516
673
|
id,
|
|
517
|
-
|
|
518
|
-
|
|
674
|
+
type: options.type ?? "neutral",
|
|
675
|
+
title: options.title,
|
|
676
|
+
description: options.description,
|
|
519
677
|
icon: options.icon,
|
|
678
|
+
action: options.action,
|
|
679
|
+
showCloseButton: options.showCloseButton,
|
|
680
|
+
progress: options.progress,
|
|
520
681
|
duration
|
|
521
682
|
};
|
|
522
683
|
setToasts((prev) => [...prev, newToast]);
|
|
@@ -542,7 +703,8 @@ var ToastProvider = ({
|
|
|
542
703
|
position,
|
|
543
704
|
align,
|
|
544
705
|
maxWidth,
|
|
545
|
-
onDismiss: dismissToast
|
|
706
|
+
onDismiss: dismissToast,
|
|
707
|
+
testID
|
|
546
708
|
}
|
|
547
709
|
)
|
|
548
710
|
] });
|
|
@@ -562,27 +724,27 @@ var useToast = () => {
|
|
|
562
724
|
},
|
|
563
725
|
[addToast]
|
|
564
726
|
);
|
|
565
|
-
const
|
|
566
|
-
(
|
|
567
|
-
return addToast({ ...options,
|
|
727
|
+
const alert = (0, import_react6.useCallback)(
|
|
728
|
+
(options) => {
|
|
729
|
+
return addToast({ ...options, type: "alert" });
|
|
568
730
|
},
|
|
569
731
|
[addToast]
|
|
570
732
|
);
|
|
571
|
-
const
|
|
572
|
-
(
|
|
573
|
-
return addToast({ ...options,
|
|
733
|
+
const success = (0, import_react6.useCallback)(
|
|
734
|
+
(options) => {
|
|
735
|
+
return addToast({ ...options, type: "success" });
|
|
574
736
|
},
|
|
575
737
|
[addToast]
|
|
576
738
|
);
|
|
577
|
-
const
|
|
578
|
-
(
|
|
579
|
-
return addToast({ ...options,
|
|
739
|
+
const neutral = (0, import_react6.useCallback)(
|
|
740
|
+
(options) => {
|
|
741
|
+
return addToast({ ...options, type: "neutral" });
|
|
580
742
|
},
|
|
581
743
|
[addToast]
|
|
582
744
|
);
|
|
583
|
-
const
|
|
584
|
-
(
|
|
585
|
-
return addToast({ ...options,
|
|
745
|
+
const warning = (0, import_react6.useCallback)(
|
|
746
|
+
(options) => {
|
|
747
|
+
return addToast({ ...options, type: "warning" });
|
|
586
748
|
},
|
|
587
749
|
[addToast]
|
|
588
750
|
);
|
|
@@ -597,10 +759,10 @@ var useToast = () => {
|
|
|
597
759
|
}, [dismissAllToasts]);
|
|
598
760
|
return {
|
|
599
761
|
toast,
|
|
762
|
+
alert,
|
|
600
763
|
success,
|
|
601
|
-
|
|
764
|
+
neutral,
|
|
602
765
|
warning,
|
|
603
|
-
error,
|
|
604
766
|
dismiss,
|
|
605
767
|
dismissAll
|
|
606
768
|
};
|