sonner 2.0.0-beta.1 → 2.0.0-beta.3
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/dist/index.d.mts +151 -0
- package/dist/index.d.ts +8 -13
- package/dist/index.js +1165 -3
- package/dist/index.mjs +1156 -3
- package/dist/styles.css +25 -15
- package/package.json +14 -7
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
type ToastTypes = 'normal' | 'action' | 'success' | 'info' | 'warning' | 'error' | 'loading' | 'default';
|
|
4
|
+
type PromiseT<Data = any> = Promise<Data> | (() => Promise<Data>);
|
|
5
|
+
interface PromiseIExtendedResult extends ExternalToast {
|
|
6
|
+
message: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
type PromiseTExtendedResult<Data = any> = PromiseIExtendedResult | ((data: Data) => PromiseIExtendedResult | Promise<PromiseIExtendedResult>);
|
|
9
|
+
type PromiseTResult<Data = any> = string | React.ReactNode | ((data: Data) => React.ReactNode | string | Promise<React.ReactNode | string>);
|
|
10
|
+
type PromiseExternalToast = Omit<ExternalToast, 'description'>;
|
|
11
|
+
type PromiseData<ToastData = any> = PromiseExternalToast & {
|
|
12
|
+
loading?: string | React.ReactNode;
|
|
13
|
+
success?: PromiseTResult<ToastData> | PromiseTExtendedResult<ToastData>;
|
|
14
|
+
error?: PromiseTResult | PromiseTExtendedResult;
|
|
15
|
+
description?: PromiseTResult;
|
|
16
|
+
finally?: () => void | Promise<void>;
|
|
17
|
+
};
|
|
18
|
+
interface ToastClassnames {
|
|
19
|
+
toast?: string;
|
|
20
|
+
title?: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
loader?: string;
|
|
23
|
+
closeButton?: string;
|
|
24
|
+
cancelButton?: string;
|
|
25
|
+
actionButton?: string;
|
|
26
|
+
success?: string;
|
|
27
|
+
error?: string;
|
|
28
|
+
info?: string;
|
|
29
|
+
warning?: string;
|
|
30
|
+
loading?: string;
|
|
31
|
+
default?: string;
|
|
32
|
+
content?: string;
|
|
33
|
+
icon?: string;
|
|
34
|
+
}
|
|
35
|
+
interface ToastIcons {
|
|
36
|
+
success?: React.ReactNode;
|
|
37
|
+
info?: React.ReactNode;
|
|
38
|
+
warning?: React.ReactNode;
|
|
39
|
+
error?: React.ReactNode;
|
|
40
|
+
loading?: React.ReactNode;
|
|
41
|
+
close?: React.ReactNode;
|
|
42
|
+
}
|
|
43
|
+
interface Action {
|
|
44
|
+
label: React.ReactNode;
|
|
45
|
+
onClick: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
|
46
|
+
actionButtonStyle?: React.CSSProperties;
|
|
47
|
+
}
|
|
48
|
+
interface ToastT {
|
|
49
|
+
id: number | string;
|
|
50
|
+
title?: (() => React.ReactNode) | React.ReactNode;
|
|
51
|
+
type?: ToastTypes;
|
|
52
|
+
icon?: React.ReactNode;
|
|
53
|
+
jsx?: React.ReactNode;
|
|
54
|
+
richColors?: boolean;
|
|
55
|
+
invert?: boolean;
|
|
56
|
+
closeButton?: boolean;
|
|
57
|
+
dismissible?: boolean;
|
|
58
|
+
description?: (() => React.ReactNode) | React.ReactNode;
|
|
59
|
+
duration?: number;
|
|
60
|
+
delete?: boolean;
|
|
61
|
+
action?: Action | React.ReactNode;
|
|
62
|
+
cancel?: Action | React.ReactNode;
|
|
63
|
+
onDismiss?: (toast: ToastT) => void;
|
|
64
|
+
onAutoClose?: (toast: ToastT) => void;
|
|
65
|
+
promise?: PromiseT;
|
|
66
|
+
cancelButtonStyle?: React.CSSProperties;
|
|
67
|
+
actionButtonStyle?: React.CSSProperties;
|
|
68
|
+
style?: React.CSSProperties;
|
|
69
|
+
unstyled?: boolean;
|
|
70
|
+
className?: string;
|
|
71
|
+
classNames?: ToastClassnames;
|
|
72
|
+
descriptionClassName?: string;
|
|
73
|
+
position?: Position;
|
|
74
|
+
}
|
|
75
|
+
type Position = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'top-center' | 'bottom-center';
|
|
76
|
+
interface ToastOptions {
|
|
77
|
+
className?: string;
|
|
78
|
+
closeButton?: boolean;
|
|
79
|
+
descriptionClassName?: string;
|
|
80
|
+
style?: React.CSSProperties;
|
|
81
|
+
cancelButtonStyle?: React.CSSProperties;
|
|
82
|
+
actionButtonStyle?: React.CSSProperties;
|
|
83
|
+
duration?: number;
|
|
84
|
+
unstyled?: boolean;
|
|
85
|
+
classNames?: ToastClassnames;
|
|
86
|
+
closeButtonAriaLabel?: string;
|
|
87
|
+
}
|
|
88
|
+
type Offset = {
|
|
89
|
+
top?: string | number;
|
|
90
|
+
right?: string | number;
|
|
91
|
+
bottom?: string | number;
|
|
92
|
+
left?: string | number;
|
|
93
|
+
} | string | number;
|
|
94
|
+
interface ToasterProps {
|
|
95
|
+
invert?: boolean;
|
|
96
|
+
theme?: 'light' | 'dark' | 'system';
|
|
97
|
+
position?: Position;
|
|
98
|
+
hotkey?: string[];
|
|
99
|
+
richColors?: boolean;
|
|
100
|
+
expand?: boolean;
|
|
101
|
+
duration?: number;
|
|
102
|
+
gap?: number;
|
|
103
|
+
visibleToasts?: number;
|
|
104
|
+
closeButton?: boolean;
|
|
105
|
+
toastOptions?: ToastOptions;
|
|
106
|
+
className?: string;
|
|
107
|
+
style?: React.CSSProperties;
|
|
108
|
+
offset?: Offset;
|
|
109
|
+
mobileOffset?: Offset;
|
|
110
|
+
dir?: 'rtl' | 'ltr' | 'auto';
|
|
111
|
+
swipeDirections?: SwipeDirection[];
|
|
112
|
+
icons?: ToastIcons;
|
|
113
|
+
containerAriaLabel?: string;
|
|
114
|
+
}
|
|
115
|
+
type SwipeDirection = 'top' | 'right' | 'bottom' | 'left';
|
|
116
|
+
interface ToastToDismiss {
|
|
117
|
+
id: number | string;
|
|
118
|
+
dismiss: boolean;
|
|
119
|
+
}
|
|
120
|
+
type ExternalToast = Omit<ToastT, 'id' | 'type' | 'title' | 'jsx' | 'delete' | 'promise'> & {
|
|
121
|
+
id?: number | string;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
type titleT = (() => React.ReactNode) | React.ReactNode;
|
|
125
|
+
declare const toast: ((message: titleT, data?: ExternalToast) => string | number) & {
|
|
126
|
+
success: (message: titleT | React.ReactNode, data?: ExternalToast) => string | number;
|
|
127
|
+
info: (message: titleT | React.ReactNode, data?: ExternalToast) => string | number;
|
|
128
|
+
warning: (message: titleT | React.ReactNode, data?: ExternalToast) => string | number;
|
|
129
|
+
error: (message: titleT | React.ReactNode, data?: ExternalToast) => string | number;
|
|
130
|
+
custom: (jsx: (id: number | string) => React.ReactElement, data?: ExternalToast) => string | number;
|
|
131
|
+
message: (message: titleT | React.ReactNode, data?: ExternalToast) => string | number;
|
|
132
|
+
promise: <ToastData>(promise: PromiseT<ToastData>, data?: PromiseData<ToastData>) => (string & {
|
|
133
|
+
unwrap: () => Promise<ToastData>;
|
|
134
|
+
}) | (number & {
|
|
135
|
+
unwrap: () => Promise<ToastData>;
|
|
136
|
+
}) | {
|
|
137
|
+
unwrap: () => Promise<ToastData>;
|
|
138
|
+
};
|
|
139
|
+
dismiss: (id?: number | string) => string | number;
|
|
140
|
+
loading: (message: titleT | React.ReactNode, data?: ExternalToast) => string | number;
|
|
141
|
+
} & {
|
|
142
|
+
getHistory: () => (ToastT | ToastToDismiss)[];
|
|
143
|
+
getToasts: () => (ToastT | ToastToDismiss)[];
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
declare function useSonner(): {
|
|
147
|
+
toasts: ToastT[];
|
|
148
|
+
};
|
|
149
|
+
declare const Toaster: React.ForwardRefExoticComponent<ToasterProps & React.RefAttributes<HTMLElement>>;
|
|
150
|
+
|
|
151
|
+
export { type Action, type ExternalToast, type ToastClassnames, type ToastT, type ToastToDismiss, Toaster, type ToasterProps, toast, useSonner };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,12 +2,16 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
type ToastTypes = 'normal' | 'action' | 'success' | 'info' | 'warning' | 'error' | 'loading' | 'default';
|
|
4
4
|
type PromiseT<Data = any> = Promise<Data> | (() => Promise<Data>);
|
|
5
|
+
interface PromiseIExtendedResult extends ExternalToast {
|
|
6
|
+
message: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
type PromiseTExtendedResult<Data = any> = PromiseIExtendedResult | ((data: Data) => PromiseIExtendedResult | Promise<PromiseIExtendedResult>);
|
|
5
9
|
type PromiseTResult<Data = any> = string | React.ReactNode | ((data: Data) => React.ReactNode | string | Promise<React.ReactNode | string>);
|
|
6
10
|
type PromiseExternalToast = Omit<ExternalToast, 'description'>;
|
|
7
11
|
type PromiseData<ToastData = any> = PromiseExternalToast & {
|
|
8
12
|
loading?: string | React.ReactNode;
|
|
9
|
-
success?: PromiseTResult<ToastData>;
|
|
10
|
-
error?: PromiseTResult;
|
|
13
|
+
success?: PromiseTResult<ToastData> | PromiseTExtendedResult<ToastData>;
|
|
14
|
+
error?: PromiseTResult | PromiseTExtendedResult;
|
|
11
15
|
description?: PromiseTResult;
|
|
12
16
|
finally?: () => void | Promise<void>;
|
|
13
17
|
};
|
|
@@ -79,6 +83,7 @@ interface ToastOptions {
|
|
|
79
83
|
duration?: number;
|
|
80
84
|
unstyled?: boolean;
|
|
81
85
|
classNames?: ToastClassnames;
|
|
86
|
+
closeButtonAriaLabel?: string;
|
|
82
87
|
}
|
|
83
88
|
type Offset = {
|
|
84
89
|
top?: string | number;
|
|
@@ -104,18 +109,8 @@ interface ToasterProps {
|
|
|
104
109
|
mobileOffset?: Offset;
|
|
105
110
|
dir?: 'rtl' | 'ltr' | 'auto';
|
|
106
111
|
swipeDirections?: SwipeDirection[];
|
|
107
|
-
/**
|
|
108
|
-
* @deprecated Please use the `icons` prop instead:
|
|
109
|
-
* ```jsx
|
|
110
|
-
* <Toaster
|
|
111
|
-
* icons={{ loading: <LoadingIcon /> }}
|
|
112
|
-
* />
|
|
113
|
-
* ```
|
|
114
|
-
*/
|
|
115
|
-
loadingIcon?: React.ReactNode;
|
|
116
112
|
icons?: ToastIcons;
|
|
117
113
|
containerAriaLabel?: string;
|
|
118
|
-
pauseWhenPageIsHidden?: boolean;
|
|
119
114
|
}
|
|
120
115
|
type SwipeDirection = 'top' | 'right' | 'bottom' | 'left';
|
|
121
116
|
interface ToastToDismiss {
|
|
@@ -153,4 +148,4 @@ declare function useSonner(): {
|
|
|
153
148
|
};
|
|
154
149
|
declare const Toaster: React.ForwardRefExoticComponent<ToasterProps & React.RefAttributes<HTMLElement>>;
|
|
155
150
|
|
|
156
|
-
export { Action, ExternalToast, ToastClassnames, ToastT, ToastToDismiss, Toaster, ToasterProps, toast, useSonner };
|
|
151
|
+
export { type Action, type ExternalToast, type ToastClassnames, type ToastT, type ToastToDismiss, Toaster, type ToasterProps, toast, useSonner };
|