@xsolla/xui-b2b-toast 0.150.0-pr271.1778106166
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 +103 -0
- package/native/index.d.mts +81 -0
- package/native/index.d.ts +81 -0
- package/native/index.js +801 -0
- package/native/index.js.map +1 -0
- package/native/index.mjs +787 -0
- package/native/index.mjs.map +1 -0
- package/package.json +61 -0
- package/web/index.d.mts +81 -0
- package/web/index.d.ts +81 -0
- package/web/index.js +887 -0
- package/web/index.js.map +1 -0
- package/web/index.mjs +859 -0
- package/web/index.mjs.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# B2B Toast
|
|
2
|
+
|
|
3
|
+
Floating, transient feedback for B2B page layouts. Toasts slide in from a fixed corner of the viewport, auto-dismiss after a few seconds, and stack vertically. Use for brief confirmations and non-blocking status messages.
|
|
4
|
+
|
|
5
|
+
> **See also:** [`@xsolla/xui-b2b-notification-panel`](../notification-panel/README.md) for inline (non-floating) feedback that stays in place until dismissed.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
yarn add @xsolla/xui-b2b-toast
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
Wrap your app with `ToastProvider` once, then call `useToast()` from anywhere inside.
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { ToastProvider, useToast } from "@xsolla/xui-b2b-toast";
|
|
19
|
+
import { Button } from "@xsolla/xui-button";
|
|
20
|
+
|
|
21
|
+
function App() {
|
|
22
|
+
return (
|
|
23
|
+
<ToastProvider position="top-right" limit={3}>
|
|
24
|
+
<Page />
|
|
25
|
+
</ToastProvider>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function Page() {
|
|
30
|
+
const toast = useToast();
|
|
31
|
+
return (
|
|
32
|
+
<Button
|
|
33
|
+
onPress={() =>
|
|
34
|
+
toast.success({
|
|
35
|
+
title: "Saved",
|
|
36
|
+
description: "Your changes have been saved.",
|
|
37
|
+
action: <Button onPress={() => undo()}>Undo</Button>,
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
>
|
|
41
|
+
Save
|
|
42
|
+
</Button>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## API
|
|
48
|
+
|
|
49
|
+
### `<ToastProvider>`
|
|
50
|
+
|
|
51
|
+
| Prop | Type | Default | Description |
|
|
52
|
+
| ----------- | ---------------- | -------------- | --------------------------------------------- |
|
|
53
|
+
| `position` | `ToastPosition` | `"top-right"` | Viewport corner to anchor toasts to. |
|
|
54
|
+
| `limit` | `number` | `3` | Max simultaneously visible toasts. |
|
|
55
|
+
| `container` | `HTMLElement` | `document.body`| Portal target. |
|
|
56
|
+
|
|
57
|
+
`ToastPosition` = `"top-right" \| "top-left" \| "top-center" \| "bottom-right" \| "bottom-left" \| "bottom-center"`
|
|
58
|
+
|
|
59
|
+
### `useToast()`
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
const toast = useToast();
|
|
63
|
+
toast.alert(options); // role=alert, default 9000ms
|
|
64
|
+
toast.success(options); // default 4500ms
|
|
65
|
+
toast.warning(options); // default 6500ms
|
|
66
|
+
toast.info(options); // default 6500ms
|
|
67
|
+
toast.show(type, options);
|
|
68
|
+
toast.dismiss(id);
|
|
69
|
+
toast.dismissAll();
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`ToastOptions`:
|
|
73
|
+
|
|
74
|
+
| Field | Type | Description |
|
|
75
|
+
| ----------------- | --------------------- | -------------------------------------------------------- |
|
|
76
|
+
| `title` | `string` | Title (bodyMd accent). |
|
|
77
|
+
| `description` | `string` | Optional description (bodySm). |
|
|
78
|
+
| `action` | `ReactElement` | Button/IconButton; tone & size are auto-applied. |
|
|
79
|
+
| `showCloseButton` | `boolean` | Default `true`. |
|
|
80
|
+
| `duration` | `number` | Auto-dismiss in ms. `0` disables. |
|
|
81
|
+
| `id` | `string` | Stable id; reusing replaces the existing toast. |
|
|
82
|
+
| `onDismiss` | `() => void` | Fires when toast is removed (auto, manual, or replaced). |
|
|
83
|
+
|
|
84
|
+
### `<Toast>`
|
|
85
|
+
|
|
86
|
+
The visual component, used internally by the provider but exported for advanced cases (custom rendering, snapshot stories, etc.).
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
<Toast
|
|
90
|
+
type="alert"
|
|
91
|
+
title="Project deleted"
|
|
92
|
+
description='Project "Project Name" deleted'
|
|
93
|
+
action={<Button>Undo</Button>}
|
|
94
|
+
onClose={() => {}}
|
|
95
|
+
/>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Behavior
|
|
99
|
+
|
|
100
|
+
- **Auto-dismiss** — success 4.5s, info/warning 6.5s, alert 9s. Pass `duration={0}` to make a toast sticky.
|
|
101
|
+
- **Pause on hover/focus** — auto-dismiss timer pauses while the toast is hovered or focused, and resumes on leave/blur.
|
|
102
|
+
- **Stacking** — newest toast appears closest to the screen edge. When `limit` is exceeded, the oldest toast is dropped.
|
|
103
|
+
- **Accessibility** — `alert` toasts use `role="alert"` / `aria-live="assertive"`; the rest use `role="status"` / `aria-live="polite"`.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ThemeOverrideProps } from '@xsolla/xui-core';
|
|
3
|
+
import { ButtonProps, IconButtonProps } from '@xsolla/xui-button';
|
|
4
|
+
|
|
5
|
+
type ToastType = "alert" | "success" | "warning" | "info";
|
|
6
|
+
type ToastActionElement = React.ReactElement<ButtonProps | IconButtonProps>;
|
|
7
|
+
interface ToastProps extends ThemeOverrideProps {
|
|
8
|
+
/** Visual variant/tone of the toast */
|
|
9
|
+
type?: ToastType;
|
|
10
|
+
/** Title text (required for accessibility) */
|
|
11
|
+
title?: string;
|
|
12
|
+
/** Optional description text shown beneath the title */
|
|
13
|
+
description?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Action element (Button/IconButton). The toast will inject
|
|
16
|
+
* `size="xs"`, `variant="tertiary"`, and a tone matching the toast type.
|
|
17
|
+
*/
|
|
18
|
+
action?: React.ReactElement;
|
|
19
|
+
/** Show/hide close button */
|
|
20
|
+
showCloseButton?: boolean;
|
|
21
|
+
/** Close button click handler */
|
|
22
|
+
onClose?: () => void;
|
|
23
|
+
/** Test ID for testing frameworks */
|
|
24
|
+
testID?: string;
|
|
25
|
+
}
|
|
26
|
+
declare const Toast: React.FC<ToastProps>;
|
|
27
|
+
|
|
28
|
+
type ToastPosition = "top-right" | "top-left" | "top-center" | "bottom-right" | "bottom-left" | "bottom-center";
|
|
29
|
+
type ToastVariant = "default" | "sonner";
|
|
30
|
+
interface ToastOptions extends Omit<ToastProps, "type" | "onClose" | "testID"> {
|
|
31
|
+
/**
|
|
32
|
+
* Auto-dismiss duration in ms. Pass 0 to disable auto-dismiss.
|
|
33
|
+
* Defaults derived from `type`: success 4500, info/warning 6500, alert 9000.
|
|
34
|
+
*/
|
|
35
|
+
duration?: number;
|
|
36
|
+
/** Stable id — if provided and a toast with that id already exists, it's replaced. */
|
|
37
|
+
id?: string;
|
|
38
|
+
/** Called when the toast is dismissed (auto or manual). */
|
|
39
|
+
onDismiss?: () => void;
|
|
40
|
+
}
|
|
41
|
+
interface ToastQueueItem extends ToastOptions {
|
|
42
|
+
id: string;
|
|
43
|
+
type: ToastType;
|
|
44
|
+
createdAt: number;
|
|
45
|
+
}
|
|
46
|
+
interface ToastApi {
|
|
47
|
+
alert: (options: ToastOptions) => string;
|
|
48
|
+
success: (options: ToastOptions) => string;
|
|
49
|
+
warning: (options: ToastOptions) => string;
|
|
50
|
+
info: (options: ToastOptions) => string;
|
|
51
|
+
show: (type: ToastType, options: ToastOptions) => string;
|
|
52
|
+
dismiss: (id: string) => void;
|
|
53
|
+
dismissAll: () => void;
|
|
54
|
+
}
|
|
55
|
+
interface ToastProviderProps {
|
|
56
|
+
children: React.ReactNode;
|
|
57
|
+
/** Where toasts appear on screen. Defaults to top-right. */
|
|
58
|
+
position?: ToastPosition;
|
|
59
|
+
/** Maximum number of simultaneously visible toasts. Defaults to 3. */
|
|
60
|
+
limit?: number;
|
|
61
|
+
/** DOM node to portal the viewport into. Defaults to document.body. */
|
|
62
|
+
container?: HTMLElement | null;
|
|
63
|
+
/**
|
|
64
|
+
* Enable enter & exit animations. Defaults to `true`.
|
|
65
|
+
* When `false`, toasts appear and disappear instantly.
|
|
66
|
+
*/
|
|
67
|
+
animated?: boolean;
|
|
68
|
+
/** Animation duration in ms. Defaults to 220 (default variant) / 400 (sonner). */
|
|
69
|
+
animationDuration?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Visual variant.
|
|
72
|
+
* - `"default"` — toasts slide in from the edge and stack vertically.
|
|
73
|
+
* - `"sonner"` — shadcn/sonner-style stacked-cards: toasts overlap as a deck
|
|
74
|
+
* with back cards scaled & peeking; hovering the stack expands it.
|
|
75
|
+
*/
|
|
76
|
+
variant?: ToastVariant;
|
|
77
|
+
}
|
|
78
|
+
declare const ToastProvider: React.FC<ToastProviderProps>;
|
|
79
|
+
declare const useToast: () => ToastApi;
|
|
80
|
+
|
|
81
|
+
export { Toast, type ToastActionElement, type ToastApi, type ToastOptions, type ToastPosition, type ToastProps, ToastProvider, type ToastProviderProps, type ToastQueueItem, type ToastType, type ToastVariant, useToast };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ThemeOverrideProps } from '@xsolla/xui-core';
|
|
3
|
+
import { ButtonProps, IconButtonProps } from '@xsolla/xui-button';
|
|
4
|
+
|
|
5
|
+
type ToastType = "alert" | "success" | "warning" | "info";
|
|
6
|
+
type ToastActionElement = React.ReactElement<ButtonProps | IconButtonProps>;
|
|
7
|
+
interface ToastProps extends ThemeOverrideProps {
|
|
8
|
+
/** Visual variant/tone of the toast */
|
|
9
|
+
type?: ToastType;
|
|
10
|
+
/** Title text (required for accessibility) */
|
|
11
|
+
title?: string;
|
|
12
|
+
/** Optional description text shown beneath the title */
|
|
13
|
+
description?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Action element (Button/IconButton). The toast will inject
|
|
16
|
+
* `size="xs"`, `variant="tertiary"`, and a tone matching the toast type.
|
|
17
|
+
*/
|
|
18
|
+
action?: React.ReactElement;
|
|
19
|
+
/** Show/hide close button */
|
|
20
|
+
showCloseButton?: boolean;
|
|
21
|
+
/** Close button click handler */
|
|
22
|
+
onClose?: () => void;
|
|
23
|
+
/** Test ID for testing frameworks */
|
|
24
|
+
testID?: string;
|
|
25
|
+
}
|
|
26
|
+
declare const Toast: React.FC<ToastProps>;
|
|
27
|
+
|
|
28
|
+
type ToastPosition = "top-right" | "top-left" | "top-center" | "bottom-right" | "bottom-left" | "bottom-center";
|
|
29
|
+
type ToastVariant = "default" | "sonner";
|
|
30
|
+
interface ToastOptions extends Omit<ToastProps, "type" | "onClose" | "testID"> {
|
|
31
|
+
/**
|
|
32
|
+
* Auto-dismiss duration in ms. Pass 0 to disable auto-dismiss.
|
|
33
|
+
* Defaults derived from `type`: success 4500, info/warning 6500, alert 9000.
|
|
34
|
+
*/
|
|
35
|
+
duration?: number;
|
|
36
|
+
/** Stable id — if provided and a toast with that id already exists, it's replaced. */
|
|
37
|
+
id?: string;
|
|
38
|
+
/** Called when the toast is dismissed (auto or manual). */
|
|
39
|
+
onDismiss?: () => void;
|
|
40
|
+
}
|
|
41
|
+
interface ToastQueueItem extends ToastOptions {
|
|
42
|
+
id: string;
|
|
43
|
+
type: ToastType;
|
|
44
|
+
createdAt: number;
|
|
45
|
+
}
|
|
46
|
+
interface ToastApi {
|
|
47
|
+
alert: (options: ToastOptions) => string;
|
|
48
|
+
success: (options: ToastOptions) => string;
|
|
49
|
+
warning: (options: ToastOptions) => string;
|
|
50
|
+
info: (options: ToastOptions) => string;
|
|
51
|
+
show: (type: ToastType, options: ToastOptions) => string;
|
|
52
|
+
dismiss: (id: string) => void;
|
|
53
|
+
dismissAll: () => void;
|
|
54
|
+
}
|
|
55
|
+
interface ToastProviderProps {
|
|
56
|
+
children: React.ReactNode;
|
|
57
|
+
/** Where toasts appear on screen. Defaults to top-right. */
|
|
58
|
+
position?: ToastPosition;
|
|
59
|
+
/** Maximum number of simultaneously visible toasts. Defaults to 3. */
|
|
60
|
+
limit?: number;
|
|
61
|
+
/** DOM node to portal the viewport into. Defaults to document.body. */
|
|
62
|
+
container?: HTMLElement | null;
|
|
63
|
+
/**
|
|
64
|
+
* Enable enter & exit animations. Defaults to `true`.
|
|
65
|
+
* When `false`, toasts appear and disappear instantly.
|
|
66
|
+
*/
|
|
67
|
+
animated?: boolean;
|
|
68
|
+
/** Animation duration in ms. Defaults to 220 (default variant) / 400 (sonner). */
|
|
69
|
+
animationDuration?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Visual variant.
|
|
72
|
+
* - `"default"` — toasts slide in from the edge and stack vertically.
|
|
73
|
+
* - `"sonner"` — shadcn/sonner-style stacked-cards: toasts overlap as a deck
|
|
74
|
+
* with back cards scaled & peeking; hovering the stack expands it.
|
|
75
|
+
*/
|
|
76
|
+
variant?: ToastVariant;
|
|
77
|
+
}
|
|
78
|
+
declare const ToastProvider: React.FC<ToastProviderProps>;
|
|
79
|
+
declare const useToast: () => ToastApi;
|
|
80
|
+
|
|
81
|
+
export { Toast, type ToastActionElement, type ToastApi, type ToastOptions, type ToastPosition, type ToastProps, ToastProvider, type ToastProviderProps, type ToastQueueItem, type ToastType, type ToastVariant, useToast };
|