@octanejs/sonner 0.1.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 +76 -0
- package/package.json +51 -0
- package/src/assets.tsrx +103 -0
- package/src/hooks.tsrx +18 -0
- package/src/index.ts +8 -0
- package/src/sonner.tsrx +831 -0
- package/src/sonner.tsrx.d.ts +6 -0
- package/src/state.ts +292 -0
- package/src/styles.css +756 -0
- package/src/types.ts +226 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import type { ElementDescriptor } from 'octane';
|
|
2
|
+
|
|
3
|
+
// Octane renderable holes accept descriptors, primitives, arrays and nullish
|
|
4
|
+
// values. Keep this deliberately broad: it is the Sonner-facing equivalent of
|
|
5
|
+
// ReactNode, while ElementDescriptor gives custom() its upstream element-only
|
|
6
|
+
// return contract.
|
|
7
|
+
export type ToastContent = any;
|
|
8
|
+
export type ToastElement = ElementDescriptor<any>;
|
|
9
|
+
export type CSSProperties = Record<string, any>;
|
|
10
|
+
export type StateSetter<T> = (value: T | ((previous: T) => T)) => void;
|
|
11
|
+
export type Ref<T> = ((value: T | null) => void) | { current: T | null } | null;
|
|
12
|
+
|
|
13
|
+
export type ToastTypes =
|
|
14
|
+
| 'normal'
|
|
15
|
+
| 'action'
|
|
16
|
+
| 'success'
|
|
17
|
+
| 'info'
|
|
18
|
+
| 'warning'
|
|
19
|
+
| 'error'
|
|
20
|
+
| 'loading'
|
|
21
|
+
| 'default';
|
|
22
|
+
|
|
23
|
+
export type PromiseT<Data = any> = Promise<Data> | (() => Promise<Data>);
|
|
24
|
+
|
|
25
|
+
export interface PromiseIExtendedResult extends ExternalToast {
|
|
26
|
+
message: ToastContent;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type PromiseTExtendedResult<Data = any> =
|
|
30
|
+
| PromiseIExtendedResult
|
|
31
|
+
| ((data: Data) => PromiseIExtendedResult | Promise<PromiseIExtendedResult>);
|
|
32
|
+
|
|
33
|
+
export type PromiseTResult<Data = any> =
|
|
34
|
+
| string
|
|
35
|
+
| ToastContent
|
|
36
|
+
| ((data: Data) => ToastContent | string | Promise<ToastContent | string>);
|
|
37
|
+
|
|
38
|
+
export type PromiseExternalToast = Omit<ExternalToast, 'description'>;
|
|
39
|
+
|
|
40
|
+
export type PromiseData<ToastData = any> = PromiseExternalToast & {
|
|
41
|
+
loading?: string | ToastContent;
|
|
42
|
+
success?: PromiseTResult<ToastData> | PromiseTExtendedResult<ToastData>;
|
|
43
|
+
error?: PromiseTResult | PromiseTExtendedResult;
|
|
44
|
+
description?: PromiseTResult;
|
|
45
|
+
finally?: () => void | Promise<void>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export interface ToastClassnames {
|
|
49
|
+
toast?: string;
|
|
50
|
+
title?: string;
|
|
51
|
+
description?: string;
|
|
52
|
+
loader?: string;
|
|
53
|
+
closeButton?: string;
|
|
54
|
+
cancelButton?: string;
|
|
55
|
+
actionButton?: string;
|
|
56
|
+
success?: string;
|
|
57
|
+
error?: string;
|
|
58
|
+
info?: string;
|
|
59
|
+
warning?: string;
|
|
60
|
+
loading?: string;
|
|
61
|
+
default?: string;
|
|
62
|
+
content?: string;
|
|
63
|
+
icon?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface ToastIcons {
|
|
67
|
+
success?: ToastContent;
|
|
68
|
+
info?: ToastContent;
|
|
69
|
+
warning?: ToastContent;
|
|
70
|
+
error?: ToastContent;
|
|
71
|
+
loading?: ToastContent;
|
|
72
|
+
close?: ToastContent;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type ActionEvent = MouseEvent & { currentTarget: HTMLButtonElement };
|
|
76
|
+
|
|
77
|
+
export interface Action {
|
|
78
|
+
label: ToastContent;
|
|
79
|
+
onClick: (event: ActionEvent) => void;
|
|
80
|
+
actionButtonStyle?: CSSProperties;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface ToastT {
|
|
84
|
+
id: number | string;
|
|
85
|
+
toasterId?: string;
|
|
86
|
+
title?: (() => ToastContent) | ToastContent;
|
|
87
|
+
type?: ToastTypes;
|
|
88
|
+
icon?: ToastContent;
|
|
89
|
+
jsx?: ToastContent;
|
|
90
|
+
richColors?: boolean;
|
|
91
|
+
invert?: boolean;
|
|
92
|
+
closeButton?: boolean;
|
|
93
|
+
dismissible?: boolean;
|
|
94
|
+
description?: (() => ToastContent) | ToastContent;
|
|
95
|
+
duration?: number;
|
|
96
|
+
delete?: boolean;
|
|
97
|
+
action?: Action | ToastContent;
|
|
98
|
+
cancel?: Action | ToastContent;
|
|
99
|
+
onDismiss?: (toast: ToastT) => void;
|
|
100
|
+
onAutoClose?: (toast: ToastT) => void;
|
|
101
|
+
promise?: PromiseT;
|
|
102
|
+
cancelButtonStyle?: CSSProperties;
|
|
103
|
+
actionButtonStyle?: CSSProperties;
|
|
104
|
+
style?: CSSProperties;
|
|
105
|
+
unstyled?: boolean;
|
|
106
|
+
className?: string;
|
|
107
|
+
classNames?: ToastClassnames;
|
|
108
|
+
descriptionClassName?: string;
|
|
109
|
+
position?: Position;
|
|
110
|
+
testId?: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function isAction(action: Action | ToastContent): action is Action {
|
|
114
|
+
return (action as Action).label !== undefined;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export type Position =
|
|
118
|
+
| 'top-left'
|
|
119
|
+
| 'top-right'
|
|
120
|
+
| 'bottom-left'
|
|
121
|
+
| 'bottom-right'
|
|
122
|
+
| 'top-center'
|
|
123
|
+
| 'bottom-center';
|
|
124
|
+
|
|
125
|
+
export interface HeightT {
|
|
126
|
+
height: number;
|
|
127
|
+
toastId: number | string;
|
|
128
|
+
position: Position | undefined;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
interface ToastOptions {
|
|
132
|
+
className?: string;
|
|
133
|
+
closeButton?: boolean;
|
|
134
|
+
descriptionClassName?: string;
|
|
135
|
+
style?: CSSProperties;
|
|
136
|
+
cancelButtonStyle?: CSSProperties;
|
|
137
|
+
actionButtonStyle?: CSSProperties;
|
|
138
|
+
duration?: number;
|
|
139
|
+
unstyled?: boolean;
|
|
140
|
+
classNames?: ToastClassnames;
|
|
141
|
+
closeButtonAriaLabel?: string;
|
|
142
|
+
toasterId?: string;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
type Offset =
|
|
146
|
+
| {
|
|
147
|
+
top?: string | number;
|
|
148
|
+
right?: string | number;
|
|
149
|
+
bottom?: string | number;
|
|
150
|
+
left?: string | number;
|
|
151
|
+
}
|
|
152
|
+
| string
|
|
153
|
+
| number;
|
|
154
|
+
|
|
155
|
+
export interface ToasterProps {
|
|
156
|
+
id?: string;
|
|
157
|
+
invert?: boolean;
|
|
158
|
+
theme?: 'light' | 'dark' | 'system';
|
|
159
|
+
position?: Position;
|
|
160
|
+
hotkey?: string[];
|
|
161
|
+
richColors?: boolean;
|
|
162
|
+
expand?: boolean;
|
|
163
|
+
duration?: number;
|
|
164
|
+
gap?: number;
|
|
165
|
+
visibleToasts?: number;
|
|
166
|
+
closeButton?: boolean;
|
|
167
|
+
toastOptions?: ToastOptions;
|
|
168
|
+
className?: string;
|
|
169
|
+
style?: CSSProperties;
|
|
170
|
+
offset?: Offset;
|
|
171
|
+
mobileOffset?: Offset;
|
|
172
|
+
dir?: 'rtl' | 'ltr' | 'auto';
|
|
173
|
+
swipeDirections?: SwipeDirection[];
|
|
174
|
+
icons?: ToastIcons;
|
|
175
|
+
containerAriaLabel?: string;
|
|
176
|
+
ref?: Ref<HTMLElement>;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export type SwipeDirection = 'top' | 'right' | 'bottom' | 'left';
|
|
180
|
+
|
|
181
|
+
export interface ToastProps {
|
|
182
|
+
toast: ToastT;
|
|
183
|
+
toasts: ToastT[];
|
|
184
|
+
index: number;
|
|
185
|
+
swipeDirections?: SwipeDirection[];
|
|
186
|
+
expanded: boolean;
|
|
187
|
+
invert: boolean | undefined;
|
|
188
|
+
heights: HeightT[];
|
|
189
|
+
setHeights: StateSetter<HeightT[]>;
|
|
190
|
+
removeToast: (toast: ToastT) => void;
|
|
191
|
+
gap: number;
|
|
192
|
+
position: Position;
|
|
193
|
+
visibleToasts: number;
|
|
194
|
+
expandByDefault: boolean | undefined;
|
|
195
|
+
closeButton: boolean | undefined;
|
|
196
|
+
interacting: boolean;
|
|
197
|
+
style?: CSSProperties;
|
|
198
|
+
cancelButtonStyle?: CSSProperties;
|
|
199
|
+
actionButtonStyle?: CSSProperties;
|
|
200
|
+
duration?: number;
|
|
201
|
+
className?: string;
|
|
202
|
+
unstyled?: boolean;
|
|
203
|
+
descriptionClassName?: string;
|
|
204
|
+
classNames?: ToastClassnames;
|
|
205
|
+
icons?: ToastIcons;
|
|
206
|
+
closeButtonAriaLabel?: string;
|
|
207
|
+
defaultRichColors?: boolean;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export enum SwipeStateTypes {
|
|
211
|
+
SwipedOut = 'SwipedOut',
|
|
212
|
+
SwipedBack = 'SwipedBack',
|
|
213
|
+
NotSwiped = 'NotSwiped',
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export type Theme = 'light' | 'dark';
|
|
217
|
+
|
|
218
|
+
export interface ToastToDismiss {
|
|
219
|
+
id: number | string;
|
|
220
|
+
dismiss: boolean;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export type ExternalToast = Omit<ToastT, 'id' | 'type' | 'title' | 'jsx' | 'delete' | 'promise'> & {
|
|
224
|
+
id?: number | string;
|
|
225
|
+
toasterId?: string;
|
|
226
|
+
};
|