@cookified/toastify 1.0.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/LICENSE +21 -0
- package/README.md +296 -0
- package/dist/index.cjs +779 -0
- package/dist/index.d.cts +155 -0
- package/dist/index.d.ts +155 -0
- package/dist/index.js +742 -0
- package/package.json +89 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode, CSSProperties } from 'react';
|
|
3
|
+
|
|
4
|
+
type ToastType = "neutral" | "success" | "error" | "warning" | "info" | "loading" | "custom";
|
|
5
|
+
type ToastAction = {
|
|
6
|
+
label: string;
|
|
7
|
+
onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
|
8
|
+
};
|
|
9
|
+
type ToastOptions = {
|
|
10
|
+
id?: string;
|
|
11
|
+
description?: ReactNode;
|
|
12
|
+
action?: ToastAction;
|
|
13
|
+
cancel?: ToastAction;
|
|
14
|
+
icon?: ReactNode;
|
|
15
|
+
duration?: number | false;
|
|
16
|
+
autoClose?: number | false;
|
|
17
|
+
className?: string;
|
|
18
|
+
style?: CSSProperties;
|
|
19
|
+
};
|
|
20
|
+
type ToastPromiseOptions<T = unknown> = {
|
|
21
|
+
loading: string;
|
|
22
|
+
success: string | ((data: T) => string);
|
|
23
|
+
error: string | ((err: unknown) => string);
|
|
24
|
+
description?: ReactNode | ((data: T) => ReactNode);
|
|
25
|
+
action?: ToastAction;
|
|
26
|
+
cancel?: ToastAction;
|
|
27
|
+
};
|
|
28
|
+
type ToastPosition = "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right";
|
|
29
|
+
type ToastTheme = "light" | "dark" | "system";
|
|
30
|
+
type SpringConfig = {
|
|
31
|
+
stiffness?: number;
|
|
32
|
+
damping?: number;
|
|
33
|
+
mass?: number;
|
|
34
|
+
};
|
|
35
|
+
type ToastAnimationProps = {
|
|
36
|
+
toast: ToastData;
|
|
37
|
+
index: number;
|
|
38
|
+
totalToasts: number;
|
|
39
|
+
isHovered: boolean;
|
|
40
|
+
position: ToastPosition;
|
|
41
|
+
isDismissing: boolean;
|
|
42
|
+
onDismiss: () => void;
|
|
43
|
+
springConfig?: SpringConfig;
|
|
44
|
+
children: ReactNode;
|
|
45
|
+
};
|
|
46
|
+
type ToastAnimationComponent = React.ComponentType<ToastAnimationProps>;
|
|
47
|
+
type AnimationPreset = "stack" | "slide" | "fade";
|
|
48
|
+
type ToasterProps = {
|
|
49
|
+
position?: ToastPosition;
|
|
50
|
+
duration?: number | false;
|
|
51
|
+
autoClose?: number | false;
|
|
52
|
+
theme?: ToastTheme;
|
|
53
|
+
className?: string;
|
|
54
|
+
style?: CSSProperties;
|
|
55
|
+
visibleToasts?: number;
|
|
56
|
+
closeOnClick?: boolean;
|
|
57
|
+
animation?: AnimationPreset | ToastAnimationComponent;
|
|
58
|
+
springConfig?: SpringConfig;
|
|
59
|
+
icons?: Partial<Record<ToastType, ReactNode>>;
|
|
60
|
+
toastOptions?: {
|
|
61
|
+
className?: string;
|
|
62
|
+
style?: CSSProperties;
|
|
63
|
+
duration?: number;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
type ToastData = {
|
|
67
|
+
id: string;
|
|
68
|
+
type: ToastType;
|
|
69
|
+
title: ReactNode;
|
|
70
|
+
description?: ReactNode;
|
|
71
|
+
action?: ToastAction;
|
|
72
|
+
cancel?: ToastAction;
|
|
73
|
+
icon?: ReactNode;
|
|
74
|
+
duration?: number | false;
|
|
75
|
+
className?: string;
|
|
76
|
+
style?: CSSProperties;
|
|
77
|
+
customRenderer?: (id: string) => ReactNode;
|
|
78
|
+
createdAt: number;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
declare function Toaster({ position, duration, autoClose, theme, className, style, visibleToasts, closeOnClick, animation, springConfig, icons, toastOptions, }: ToasterProps): react.JSX.Element;
|
|
82
|
+
declare const ToastContainer: typeof Toaster;
|
|
83
|
+
|
|
84
|
+
type ToastProps = {
|
|
85
|
+
toast: ToastData;
|
|
86
|
+
onDismiss: () => void;
|
|
87
|
+
closeOnClick?: boolean;
|
|
88
|
+
globalIcons?: Partial<Record<ToastType, ReactNode>>;
|
|
89
|
+
globalOptions?: {
|
|
90
|
+
className?: string;
|
|
91
|
+
style?: CSSProperties;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
declare function DefaultToastIcon({ type }: {
|
|
95
|
+
type: ToastType;
|
|
96
|
+
}): react.JSX.Element;
|
|
97
|
+
declare function Toast({ toast, onDismiss, closeOnClick, globalIcons, globalOptions, }: ToastProps): react.JSX.Element;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* FadeAnimation
|
|
101
|
+
* Minimalist in-place fade & scale animation.
|
|
102
|
+
*/
|
|
103
|
+
declare function FadeAnimation({ index, position, isDismissing, onDismiss, springConfig, children, }: ToastAnimationProps): react.JSX.Element;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* FolderStackAnimation (Default)
|
|
107
|
+
* Elegant card-stacking animation with smooth hover expansion and lateral exit.
|
|
108
|
+
*/
|
|
109
|
+
declare function FolderStackAnimation({ index, isHovered, position, isDismissing, onDismiss, springConfig, children, }: ToastAnimationProps): react.JSX.Element;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* SlideAnimation
|
|
113
|
+
* Classic horizontal edge-sliding animation.
|
|
114
|
+
*/
|
|
115
|
+
declare function SlideAnimation({ index, position, isDismissing, onDismiss, springConfig, children, }: ToastAnimationProps): react.JSX.Element;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* ToastAnimation Component
|
|
119
|
+
* Dispatches to preset animation or custom animation component.
|
|
120
|
+
*/
|
|
121
|
+
declare function ToastAnimation({ animation, ...props }: ToastAnimationProps & {
|
|
122
|
+
animation?: AnimationPreset | ToastAnimationComponent;
|
|
123
|
+
}): react.JSX.Element;
|
|
124
|
+
|
|
125
|
+
declare const defaultSpring: SpringConfig;
|
|
126
|
+
|
|
127
|
+
type Listener = (toasts: ToastData[]) => void;
|
|
128
|
+
declare function subscribe(listener: Listener): () => void;
|
|
129
|
+
declare function remove(id?: string): void;
|
|
130
|
+
declare function update(id: string, updates: Partial<Omit<ToastData, "id" | "createdAt">>): void;
|
|
131
|
+
declare function promise<T>(promiseOrFn: Promise<T> | (() => Promise<T>), options: ToastPromiseOptions<T>): Promise<T>;
|
|
132
|
+
declare const toastStore: {
|
|
133
|
+
subscribe: typeof subscribe;
|
|
134
|
+
remove: typeof remove;
|
|
135
|
+
update: typeof update;
|
|
136
|
+
getToasts: () => ToastData[];
|
|
137
|
+
};
|
|
138
|
+
declare function toastFn(title: ReactNode, options?: ToastOptions): string;
|
|
139
|
+
declare const toast: typeof toastFn & {
|
|
140
|
+
show(title: ReactNode, options?: ToastOptions): string;
|
|
141
|
+
success(title: ReactNode, options?: ToastOptions): string;
|
|
142
|
+
error(title: ReactNode, options?: ToastOptions): string;
|
|
143
|
+
warning(title: ReactNode, options?: ToastOptions): string;
|
|
144
|
+
info(title: ReactNode, options?: ToastOptions): string;
|
|
145
|
+
loading(title: ReactNode, options?: ToastOptions): string;
|
|
146
|
+
custom(renderer: (id: string) => ReactNode, options?: ToastOptions): string;
|
|
147
|
+
promise: typeof promise;
|
|
148
|
+
dismiss(id?: string): void;
|
|
149
|
+
update(id: string, options: Partial<ToastOptions> & {
|
|
150
|
+
title?: ReactNode;
|
|
151
|
+
type?: ToastType;
|
|
152
|
+
}): void;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export { type AnimationPreset, DefaultToastIcon, FadeAnimation, FolderStackAnimation, SlideAnimation, type SpringConfig, Toast, type ToastAction, ToastAnimation, type ToastAnimationComponent, type ToastAnimationProps, ToastContainer, type ToastData, type ToastOptions, type ToastPosition, type ToastPromiseOptions, type ToastProps, type ToastTheme, type ToastType, Toaster, type ToasterProps, defaultSpring, toast, toastStore };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode, CSSProperties } from 'react';
|
|
3
|
+
|
|
4
|
+
type ToastType = "neutral" | "success" | "error" | "warning" | "info" | "loading" | "custom";
|
|
5
|
+
type ToastAction = {
|
|
6
|
+
label: string;
|
|
7
|
+
onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
|
8
|
+
};
|
|
9
|
+
type ToastOptions = {
|
|
10
|
+
id?: string;
|
|
11
|
+
description?: ReactNode;
|
|
12
|
+
action?: ToastAction;
|
|
13
|
+
cancel?: ToastAction;
|
|
14
|
+
icon?: ReactNode;
|
|
15
|
+
duration?: number | false;
|
|
16
|
+
autoClose?: number | false;
|
|
17
|
+
className?: string;
|
|
18
|
+
style?: CSSProperties;
|
|
19
|
+
};
|
|
20
|
+
type ToastPromiseOptions<T = unknown> = {
|
|
21
|
+
loading: string;
|
|
22
|
+
success: string | ((data: T) => string);
|
|
23
|
+
error: string | ((err: unknown) => string);
|
|
24
|
+
description?: ReactNode | ((data: T) => ReactNode);
|
|
25
|
+
action?: ToastAction;
|
|
26
|
+
cancel?: ToastAction;
|
|
27
|
+
};
|
|
28
|
+
type ToastPosition = "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right";
|
|
29
|
+
type ToastTheme = "light" | "dark" | "system";
|
|
30
|
+
type SpringConfig = {
|
|
31
|
+
stiffness?: number;
|
|
32
|
+
damping?: number;
|
|
33
|
+
mass?: number;
|
|
34
|
+
};
|
|
35
|
+
type ToastAnimationProps = {
|
|
36
|
+
toast: ToastData;
|
|
37
|
+
index: number;
|
|
38
|
+
totalToasts: number;
|
|
39
|
+
isHovered: boolean;
|
|
40
|
+
position: ToastPosition;
|
|
41
|
+
isDismissing: boolean;
|
|
42
|
+
onDismiss: () => void;
|
|
43
|
+
springConfig?: SpringConfig;
|
|
44
|
+
children: ReactNode;
|
|
45
|
+
};
|
|
46
|
+
type ToastAnimationComponent = React.ComponentType<ToastAnimationProps>;
|
|
47
|
+
type AnimationPreset = "stack" | "slide" | "fade";
|
|
48
|
+
type ToasterProps = {
|
|
49
|
+
position?: ToastPosition;
|
|
50
|
+
duration?: number | false;
|
|
51
|
+
autoClose?: number | false;
|
|
52
|
+
theme?: ToastTheme;
|
|
53
|
+
className?: string;
|
|
54
|
+
style?: CSSProperties;
|
|
55
|
+
visibleToasts?: number;
|
|
56
|
+
closeOnClick?: boolean;
|
|
57
|
+
animation?: AnimationPreset | ToastAnimationComponent;
|
|
58
|
+
springConfig?: SpringConfig;
|
|
59
|
+
icons?: Partial<Record<ToastType, ReactNode>>;
|
|
60
|
+
toastOptions?: {
|
|
61
|
+
className?: string;
|
|
62
|
+
style?: CSSProperties;
|
|
63
|
+
duration?: number;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
type ToastData = {
|
|
67
|
+
id: string;
|
|
68
|
+
type: ToastType;
|
|
69
|
+
title: ReactNode;
|
|
70
|
+
description?: ReactNode;
|
|
71
|
+
action?: ToastAction;
|
|
72
|
+
cancel?: ToastAction;
|
|
73
|
+
icon?: ReactNode;
|
|
74
|
+
duration?: number | false;
|
|
75
|
+
className?: string;
|
|
76
|
+
style?: CSSProperties;
|
|
77
|
+
customRenderer?: (id: string) => ReactNode;
|
|
78
|
+
createdAt: number;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
declare function Toaster({ position, duration, autoClose, theme, className, style, visibleToasts, closeOnClick, animation, springConfig, icons, toastOptions, }: ToasterProps): react.JSX.Element;
|
|
82
|
+
declare const ToastContainer: typeof Toaster;
|
|
83
|
+
|
|
84
|
+
type ToastProps = {
|
|
85
|
+
toast: ToastData;
|
|
86
|
+
onDismiss: () => void;
|
|
87
|
+
closeOnClick?: boolean;
|
|
88
|
+
globalIcons?: Partial<Record<ToastType, ReactNode>>;
|
|
89
|
+
globalOptions?: {
|
|
90
|
+
className?: string;
|
|
91
|
+
style?: CSSProperties;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
declare function DefaultToastIcon({ type }: {
|
|
95
|
+
type: ToastType;
|
|
96
|
+
}): react.JSX.Element;
|
|
97
|
+
declare function Toast({ toast, onDismiss, closeOnClick, globalIcons, globalOptions, }: ToastProps): react.JSX.Element;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* FadeAnimation
|
|
101
|
+
* Minimalist in-place fade & scale animation.
|
|
102
|
+
*/
|
|
103
|
+
declare function FadeAnimation({ index, position, isDismissing, onDismiss, springConfig, children, }: ToastAnimationProps): react.JSX.Element;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* FolderStackAnimation (Default)
|
|
107
|
+
* Elegant card-stacking animation with smooth hover expansion and lateral exit.
|
|
108
|
+
*/
|
|
109
|
+
declare function FolderStackAnimation({ index, isHovered, position, isDismissing, onDismiss, springConfig, children, }: ToastAnimationProps): react.JSX.Element;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* SlideAnimation
|
|
113
|
+
* Classic horizontal edge-sliding animation.
|
|
114
|
+
*/
|
|
115
|
+
declare function SlideAnimation({ index, position, isDismissing, onDismiss, springConfig, children, }: ToastAnimationProps): react.JSX.Element;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* ToastAnimation Component
|
|
119
|
+
* Dispatches to preset animation or custom animation component.
|
|
120
|
+
*/
|
|
121
|
+
declare function ToastAnimation({ animation, ...props }: ToastAnimationProps & {
|
|
122
|
+
animation?: AnimationPreset | ToastAnimationComponent;
|
|
123
|
+
}): react.JSX.Element;
|
|
124
|
+
|
|
125
|
+
declare const defaultSpring: SpringConfig;
|
|
126
|
+
|
|
127
|
+
type Listener = (toasts: ToastData[]) => void;
|
|
128
|
+
declare function subscribe(listener: Listener): () => void;
|
|
129
|
+
declare function remove(id?: string): void;
|
|
130
|
+
declare function update(id: string, updates: Partial<Omit<ToastData, "id" | "createdAt">>): void;
|
|
131
|
+
declare function promise<T>(promiseOrFn: Promise<T> | (() => Promise<T>), options: ToastPromiseOptions<T>): Promise<T>;
|
|
132
|
+
declare const toastStore: {
|
|
133
|
+
subscribe: typeof subscribe;
|
|
134
|
+
remove: typeof remove;
|
|
135
|
+
update: typeof update;
|
|
136
|
+
getToasts: () => ToastData[];
|
|
137
|
+
};
|
|
138
|
+
declare function toastFn(title: ReactNode, options?: ToastOptions): string;
|
|
139
|
+
declare const toast: typeof toastFn & {
|
|
140
|
+
show(title: ReactNode, options?: ToastOptions): string;
|
|
141
|
+
success(title: ReactNode, options?: ToastOptions): string;
|
|
142
|
+
error(title: ReactNode, options?: ToastOptions): string;
|
|
143
|
+
warning(title: ReactNode, options?: ToastOptions): string;
|
|
144
|
+
info(title: ReactNode, options?: ToastOptions): string;
|
|
145
|
+
loading(title: ReactNode, options?: ToastOptions): string;
|
|
146
|
+
custom(renderer: (id: string) => ReactNode, options?: ToastOptions): string;
|
|
147
|
+
promise: typeof promise;
|
|
148
|
+
dismiss(id?: string): void;
|
|
149
|
+
update(id: string, options: Partial<ToastOptions> & {
|
|
150
|
+
title?: ReactNode;
|
|
151
|
+
type?: ToastType;
|
|
152
|
+
}): void;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export { type AnimationPreset, DefaultToastIcon, FadeAnimation, FolderStackAnimation, SlideAnimation, type SpringConfig, Toast, type ToastAction, ToastAnimation, type ToastAnimationComponent, type ToastAnimationProps, ToastContainer, type ToastData, type ToastOptions, type ToastPosition, type ToastPromiseOptions, type ToastProps, type ToastTheme, type ToastType, Toaster, type ToasterProps, defaultSpring, toast, toastStore };
|