toastflux 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/README.md +300 -0
- package/package.json +54 -0
- package/packages/core/dist/index.d.mts +52 -0
- package/packages/core/dist/index.d.ts +52 -0
- package/packages/core/dist/index.js +84 -0
- package/packages/core/dist/index.js.map +1 -0
- package/packages/core/dist/index.mjs +56 -0
- package/packages/core/dist/index.mjs.map +1 -0
- package/packages/react/dist/index.d.mts +45 -0
- package/packages/react/dist/index.d.ts +45 -0
- package/packages/react/dist/index.js +259 -0
- package/packages/react/dist/index.js.map +1 -0
- package/packages/react/dist/index.mjs +231 -0
- package/packages/react/dist/index.mjs.map +1 -0
- package/packages/styles/toast.css +174 -0
package/README.md
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
# 🚀 ToastFlux
|
|
2
|
+
|
|
3
|
+
> ⚡ Lightweight • 🎨 Beautiful • 🧠 Fully Customizable
|
|
4
|
+
> A modern toast notification library for React & Next.js
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## ✨ Why ToastFlux?
|
|
9
|
+
|
|
10
|
+
ToastFlux is built for developers who want **speed, flexibility, and clean UI** without complexity.
|
|
11
|
+
|
|
12
|
+
- ⚡ Blazing fast & lightweight
|
|
13
|
+
- 🎨 Beautiful default UI (no extra styling needed)
|
|
14
|
+
- 🧩 Fully customizable (style, icon, font, layout)
|
|
15
|
+
- 📍 Flexible positioning system
|
|
16
|
+
- 🎯 Action buttons (Undo, Retry, etc.)
|
|
17
|
+
- ⏱ Smart duration & dismiss control
|
|
18
|
+
- 📊 Progress bar support
|
|
19
|
+
- 📝 Description text support
|
|
20
|
+
- 🌗 Built-in dark & light themes
|
|
21
|
+
- ⚛️ Works with React & Next.js App Router
|
|
22
|
+
- 👆 Swipe to dismiss (touch & pointer support)
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 📦 Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install toastflux
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 🚀 Quick Start
|
|
35
|
+
|
|
36
|
+
```jsx
|
|
37
|
+
import { Toaster, toast } from "toastflux";
|
|
38
|
+
import "toastflux/styles/toast.css";
|
|
39
|
+
|
|
40
|
+
function App() {
|
|
41
|
+
return (
|
|
42
|
+
<>
|
|
43
|
+
<Toaster theme="dark" />
|
|
44
|
+
|
|
45
|
+
<button onClick={() => toast.success("Event created 🚀")}>
|
|
46
|
+
Show Toast
|
|
47
|
+
</button>
|
|
48
|
+
</>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default App;
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 🎯 Toast Types
|
|
58
|
+
|
|
59
|
+
```jsx
|
|
60
|
+
toast.success("Saved successfully!");
|
|
61
|
+
toast.info("Meeting starts soon.");
|
|
62
|
+
toast.warning("Storage almost full.");
|
|
63
|
+
toast.error("Upload failed.");
|
|
64
|
+
toast.default("Just a message.");
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## 🎨 Customization
|
|
70
|
+
|
|
71
|
+
### 📝 Description
|
|
72
|
+
|
|
73
|
+
Add a subtitle/description below the main message:
|
|
74
|
+
|
|
75
|
+
```jsx
|
|
76
|
+
toast.success("Event has been created", {
|
|
77
|
+
description: "Monday, January 3rd at 6:00pm",
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
### ⏱ Duration & Dismiss
|
|
84
|
+
|
|
85
|
+
```jsx
|
|
86
|
+
toast.success("I stay longer!", {
|
|
87
|
+
duration: 6000,
|
|
88
|
+
dismissible: true,
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
### 🎯 Action Buttons
|
|
95
|
+
|
|
96
|
+
```jsx
|
|
97
|
+
toast.info("Item deleted", {
|
|
98
|
+
action: {
|
|
99
|
+
label: "Undo",
|
|
100
|
+
onClick: () => console.log("Undo clicked"),
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
### 📍 Positioning
|
|
108
|
+
|
|
109
|
+
```jsx
|
|
110
|
+
toast.success("Bottom right toast!", {
|
|
111
|
+
position: "bottom-right",
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Or globally via `<Toaster />`:
|
|
116
|
+
|
|
117
|
+
```jsx
|
|
118
|
+
<Toaster position="top-right" />
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
### 📊 Progress Bar
|
|
124
|
+
|
|
125
|
+
```jsx
|
|
126
|
+
toast.info("Uploading file...", {
|
|
127
|
+
progress: 45,
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
### 🎨 Custom Style & Icon
|
|
134
|
+
|
|
135
|
+
```jsx
|
|
136
|
+
toast.default("Custom styled toast", {
|
|
137
|
+
style: {
|
|
138
|
+
border: "1px solid #ec4899",
|
|
139
|
+
background: "#fdf2f8",
|
|
140
|
+
color: "#000",
|
|
141
|
+
},
|
|
142
|
+
icon: <span>🌟</span>,
|
|
143
|
+
iconColor: "#10b981",
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## 🎭 Themes
|
|
150
|
+
|
|
151
|
+
ToastFlux supports built-in dark and light themes:
|
|
152
|
+
|
|
153
|
+
```jsx
|
|
154
|
+
<Toaster theme="light" />
|
|
155
|
+
<Toaster theme="dark" />
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## 🧠 API Overview
|
|
161
|
+
|
|
162
|
+
### `toast(message, options?)`
|
|
163
|
+
|
|
164
|
+
| Option | Type | Description |
|
|
165
|
+
| ------------- | ------------------ | ----------------------------- |
|
|
166
|
+
| `description` | ReactNode | Subtitle below main message |
|
|
167
|
+
| `duration` | number | Auto dismiss time in ms |
|
|
168
|
+
| `dismissible` | boolean | Enable manual ✖ close button |
|
|
169
|
+
| `position` | ToastPosition | Where toast appears on screen |
|
|
170
|
+
| `style` | CSSProperties | Inline styles override |
|
|
171
|
+
| `className` | string | Custom CSS class |
|
|
172
|
+
| `icon` | ReactNode | Custom icon element |
|
|
173
|
+
| `iconColor` | string | Color for default icons |
|
|
174
|
+
| `action` | { label, onClick } | Action button config |
|
|
175
|
+
| `progress` | number | Progress bar value (0–100) |
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## 📍 Supported Positions
|
|
180
|
+
|
|
181
|
+
| Position | Description |
|
|
182
|
+
| --------------- | -------------------------- |
|
|
183
|
+
| `top-left` | Top left corner |
|
|
184
|
+
| `top-center` | Top center |
|
|
185
|
+
| `top-right` | Top right corner (default) |
|
|
186
|
+
| `bottom-left` | Bottom left corner |
|
|
187
|
+
| `bottom-center` | Bottom center |
|
|
188
|
+
| `bottom-right` | Bottom right corner |
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## 🔤 Custom Font (CSS Variable)
|
|
193
|
+
|
|
194
|
+
ToastFlux uses a clean system font by default. To match your app's custom font, set the `--tf-font-family` CSS variable:
|
|
195
|
+
|
|
196
|
+
```css
|
|
197
|
+
/* In your global CSS (e.g. index.css or globals.css) */
|
|
198
|
+
:root {
|
|
199
|
+
--tf-font-family: "Inter", sans-serif;
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
👉 Falls back to `system-ui, sans-serif` by default — no ugly serif fonts!
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## ⚙️ Next.js (App Router) Usage
|
|
208
|
+
|
|
209
|
+
ToastFlux works seamlessly with Next.js App Router. Since it uses client-side state, add `"use client"` where needed.
|
|
210
|
+
|
|
211
|
+
### 1. Add `<Toaster />` to Root Layout
|
|
212
|
+
|
|
213
|
+
```tsx
|
|
214
|
+
// app/layout.tsx
|
|
215
|
+
import { Toaster } from "toastflux";
|
|
216
|
+
import "toastflux/styles/toast.css";
|
|
217
|
+
|
|
218
|
+
export default function RootLayout({
|
|
219
|
+
children,
|
|
220
|
+
}: {
|
|
221
|
+
children: React.ReactNode;
|
|
222
|
+
}) {
|
|
223
|
+
return (
|
|
224
|
+
<html lang="en">
|
|
225
|
+
<body>
|
|
226
|
+
{children}
|
|
227
|
+
<Toaster theme="dark" />
|
|
228
|
+
</body>
|
|
229
|
+
</html>
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### 2. Use `toast` in Any Client Component
|
|
235
|
+
|
|
236
|
+
```tsx
|
|
237
|
+
// app/page.tsx
|
|
238
|
+
"use client";
|
|
239
|
+
|
|
240
|
+
import { toast } from "toastflux";
|
|
241
|
+
|
|
242
|
+
export default function HomePage() {
|
|
243
|
+
return (
|
|
244
|
+
<button onClick={() => toast.success("It works in Next.js too! 🚀")}>
|
|
245
|
+
Show Toast
|
|
246
|
+
</button>
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## 🧱 Architecture
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
toastflux/
|
|
257
|
+
├── packages/
|
|
258
|
+
│ ├── core/ → Framework-independent logic (store, types, toast fn)
|
|
259
|
+
│ ├── react/ → React UI components (Toaster, ToastItem)
|
|
260
|
+
│ └── styles/ → CSS (toast.css)
|
|
261
|
+
└── apps/
|
|
262
|
+
├── react-app/ → Vite + React demo
|
|
263
|
+
└── next-app/ → Next.js App Router demo
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## 🚀 Roadmap
|
|
269
|
+
|
|
270
|
+
- [x] Toast types (success, error, info, warning, default)
|
|
271
|
+
- [x] Dark & Light themes
|
|
272
|
+
- [x] Description support
|
|
273
|
+
- [x] Custom font via CSS variable
|
|
274
|
+
- [x] Action buttons
|
|
275
|
+
- [x] Progress bar
|
|
276
|
+
- [x] Swipe to dismiss
|
|
277
|
+
- [x] Next.js App Router support
|
|
278
|
+
- [ ] Promise-based toasts (`toast.promise`)
|
|
279
|
+
- [ ] Smart toast grouping
|
|
280
|
+
- [ ] Advanced animations
|
|
281
|
+
- [ ] DevTools panel
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## 🤝 Contributing
|
|
286
|
+
|
|
287
|
+
PRs and ideas are welcome!
|
|
288
|
+
Feel free to open issues or suggest improvements.
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## 📄 License
|
|
293
|
+
|
|
294
|
+
MIT
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## ❤️ Author
|
|
299
|
+
|
|
300
|
+
Built with passion by **Rahul**
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "toastflux",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "⚡ A lightweight, beautiful, and fully customizable toast notification library for React & Next.js with modern UI, themes, actions, and progress support.",
|
|
5
|
+
"author": "Rahul",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"toast",
|
|
9
|
+
"toast notification",
|
|
10
|
+
"react toast",
|
|
11
|
+
"nextjs toast",
|
|
12
|
+
"notification",
|
|
13
|
+
"react notification",
|
|
14
|
+
"toast library",
|
|
15
|
+
"ui toast",
|
|
16
|
+
"alert",
|
|
17
|
+
"snackbar",
|
|
18
|
+
"toastflux"
|
|
19
|
+
],
|
|
20
|
+
"main": "./packages/react/dist/index.js",
|
|
21
|
+
"module": "./packages/react/dist/index.mjs",
|
|
22
|
+
"types": "./packages/react/dist/index.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"packages/react/dist",
|
|
25
|
+
"packages/core/dist",
|
|
26
|
+
"packages/styles"
|
|
27
|
+
],
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"import": "./packages/react/dist/index.mjs",
|
|
31
|
+
"require": "./packages/react/dist/index.js",
|
|
32
|
+
"types": "./packages/react/dist/index.d.ts"
|
|
33
|
+
},
|
|
34
|
+
"./styles/toast.css": "./packages/styles/toast.css"
|
|
35
|
+
},
|
|
36
|
+
"sideEffects": [
|
|
37
|
+
"*.css"
|
|
38
|
+
],
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"react": ">=16.8.0",
|
|
41
|
+
"react-dom": ">=16.8.0"
|
|
42
|
+
},
|
|
43
|
+
"workspaces": [
|
|
44
|
+
"packages/*",
|
|
45
|
+
"apps/*"
|
|
46
|
+
],
|
|
47
|
+
"scripts": {
|
|
48
|
+
"dev": "tsup --watch",
|
|
49
|
+
"build": "tsup"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"tsup": "^8.5.1"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ReactNode, CSSProperties } from 'react';
|
|
2
|
+
|
|
3
|
+
type ToastType = "success" | "error" | "info" | "warning" | "loading" | "default";
|
|
4
|
+
type ToastPosition = "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right";
|
|
5
|
+
interface Toast {
|
|
6
|
+
id: string;
|
|
7
|
+
message?: string;
|
|
8
|
+
description?: ReactNode;
|
|
9
|
+
type?: ToastType;
|
|
10
|
+
createdAt: number;
|
|
11
|
+
style?: CSSProperties;
|
|
12
|
+
className?: string;
|
|
13
|
+
duration?: number;
|
|
14
|
+
dismissible?: boolean;
|
|
15
|
+
position?: ToastPosition;
|
|
16
|
+
icon?: ReactNode;
|
|
17
|
+
iconColor?: string;
|
|
18
|
+
action?: {
|
|
19
|
+
label: string;
|
|
20
|
+
onClick: () => void;
|
|
21
|
+
};
|
|
22
|
+
render?: () => ReactNode;
|
|
23
|
+
progress?: number;
|
|
24
|
+
groupId?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type ToastOptions = Partial<Omit<Toast, "id" | "type" | "createdAt">>;
|
|
28
|
+
declare const toast: {
|
|
29
|
+
(msg: string | undefined, type?: ToastType, options?: ToastOptions): string;
|
|
30
|
+
success(msg: string, options?: ToastOptions): string;
|
|
31
|
+
error(msg: string, options?: ToastOptions): string;
|
|
32
|
+
info(msg: string, options?: ToastOptions): string;
|
|
33
|
+
warning(msg: string, options?: ToastOptions): string;
|
|
34
|
+
loading(msg: string, options?: ToastOptions): string;
|
|
35
|
+
default(msg: string, options?: ToastOptions): string;
|
|
36
|
+
custom(options: ToastOptions): string;
|
|
37
|
+
dismiss(id: string): void;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type Listener = () => void;
|
|
41
|
+
declare class ToastStore {
|
|
42
|
+
private toasts;
|
|
43
|
+
private listeners;
|
|
44
|
+
subscribe(listener: Listener): () => void;
|
|
45
|
+
getToasts(): Toast[];
|
|
46
|
+
add(toast: Toast): void;
|
|
47
|
+
remove(id: string): void;
|
|
48
|
+
private emit;
|
|
49
|
+
}
|
|
50
|
+
declare const toastStore: ToastStore;
|
|
51
|
+
|
|
52
|
+
export { type Toast, type ToastOptions, type ToastPosition, type ToastType, toast, toastStore };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ReactNode, CSSProperties } from 'react';
|
|
2
|
+
|
|
3
|
+
type ToastType = "success" | "error" | "info" | "warning" | "loading" | "default";
|
|
4
|
+
type ToastPosition = "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right";
|
|
5
|
+
interface Toast {
|
|
6
|
+
id: string;
|
|
7
|
+
message?: string;
|
|
8
|
+
description?: ReactNode;
|
|
9
|
+
type?: ToastType;
|
|
10
|
+
createdAt: number;
|
|
11
|
+
style?: CSSProperties;
|
|
12
|
+
className?: string;
|
|
13
|
+
duration?: number;
|
|
14
|
+
dismissible?: boolean;
|
|
15
|
+
position?: ToastPosition;
|
|
16
|
+
icon?: ReactNode;
|
|
17
|
+
iconColor?: string;
|
|
18
|
+
action?: {
|
|
19
|
+
label: string;
|
|
20
|
+
onClick: () => void;
|
|
21
|
+
};
|
|
22
|
+
render?: () => ReactNode;
|
|
23
|
+
progress?: number;
|
|
24
|
+
groupId?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type ToastOptions = Partial<Omit<Toast, "id" | "type" | "createdAt">>;
|
|
28
|
+
declare const toast: {
|
|
29
|
+
(msg: string | undefined, type?: ToastType, options?: ToastOptions): string;
|
|
30
|
+
success(msg: string, options?: ToastOptions): string;
|
|
31
|
+
error(msg: string, options?: ToastOptions): string;
|
|
32
|
+
info(msg: string, options?: ToastOptions): string;
|
|
33
|
+
warning(msg: string, options?: ToastOptions): string;
|
|
34
|
+
loading(msg: string, options?: ToastOptions): string;
|
|
35
|
+
default(msg: string, options?: ToastOptions): string;
|
|
36
|
+
custom(options: ToastOptions): string;
|
|
37
|
+
dismiss(id: string): void;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type Listener = () => void;
|
|
41
|
+
declare class ToastStore {
|
|
42
|
+
private toasts;
|
|
43
|
+
private listeners;
|
|
44
|
+
subscribe(listener: Listener): () => void;
|
|
45
|
+
getToasts(): Toast[];
|
|
46
|
+
add(toast: Toast): void;
|
|
47
|
+
remove(id: string): void;
|
|
48
|
+
private emit;
|
|
49
|
+
}
|
|
50
|
+
declare const toastStore: ToastStore;
|
|
51
|
+
|
|
52
|
+
export { type Toast, type ToastOptions, type ToastPosition, type ToastType, toast, toastStore };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/core/src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
toast: () => toast,
|
|
24
|
+
toastStore: () => toastStore
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// packages/core/src/store.ts
|
|
29
|
+
var ToastStore = class {
|
|
30
|
+
constructor() {
|
|
31
|
+
this.toasts = [];
|
|
32
|
+
this.listeners = [];
|
|
33
|
+
}
|
|
34
|
+
subscribe(listener) {
|
|
35
|
+
this.listeners.push(listener);
|
|
36
|
+
return () => {
|
|
37
|
+
this.listeners = this.listeners.filter((l) => l !== listener);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
getToasts() {
|
|
41
|
+
return this.toasts;
|
|
42
|
+
}
|
|
43
|
+
add(toast2) {
|
|
44
|
+
this.toasts = [toast2, ...this.toasts];
|
|
45
|
+
this.emit();
|
|
46
|
+
}
|
|
47
|
+
remove(id) {
|
|
48
|
+
this.toasts = this.toasts.filter((t) => t.id !== id);
|
|
49
|
+
this.emit();
|
|
50
|
+
}
|
|
51
|
+
emit() {
|
|
52
|
+
this.listeners.forEach((l) => l());
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var toastStore = new ToastStore();
|
|
56
|
+
|
|
57
|
+
// packages/core/src/toast.ts
|
|
58
|
+
function createToast(message, type, options) {
|
|
59
|
+
const id = crypto.randomUUID();
|
|
60
|
+
toastStore.add({
|
|
61
|
+
id,
|
|
62
|
+
message,
|
|
63
|
+
type,
|
|
64
|
+
createdAt: Date.now(),
|
|
65
|
+
...options
|
|
66
|
+
});
|
|
67
|
+
return id;
|
|
68
|
+
}
|
|
69
|
+
var toastFn = (msg, type = "default", options) => createToast(msg, type, options);
|
|
70
|
+
toastFn.success = (msg, options) => createToast(msg, "success", options);
|
|
71
|
+
toastFn.error = (msg, options) => createToast(msg, "error", options);
|
|
72
|
+
toastFn.info = (msg, options) => createToast(msg, "info", options);
|
|
73
|
+
toastFn.warning = (msg, options) => createToast(msg, "warning", options);
|
|
74
|
+
toastFn.loading = (msg, options) => createToast(msg, "loading", options);
|
|
75
|
+
toastFn.default = (msg, options) => createToast(msg, "default", options);
|
|
76
|
+
toastFn.custom = (options) => createToast(options.message, "default", options);
|
|
77
|
+
toastFn.dismiss = (id) => toastStore.remove(id);
|
|
78
|
+
var toast = toastFn;
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
toast,
|
|
82
|
+
toastStore
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/store.ts","../src/toast.ts"],"sourcesContent":["export * from \"./toast\";\r\nexport * from \"./store\";\r\nexport * from \"./types\";\r\n","import { Toast } from \"./types\";\r\n\r\ntype Listener = () => void;\r\n\r\nclass ToastStore {\r\n private toasts: Toast[] = [];\r\n private listeners: Listener[] = [];\r\n\r\n subscribe(listener: Listener) {\r\n this.listeners.push(listener);\r\n return () => {\r\n this.listeners = this.listeners.filter((l) => l !== listener);\r\n };\r\n }\r\n\r\n getToasts() {\r\n return this.toasts;\r\n }\r\n\r\n add(toast: Toast) {\r\n this.toasts = [toast, ...this.toasts];\r\n this.emit();\r\n }\r\n\r\n remove(id: string) {\r\n this.toasts = this.toasts.filter((t) => t.id !== id);\r\n this.emit();\r\n }\r\n\r\n private emit() {\r\n this.listeners.forEach((l) => l());\r\n }\r\n}\r\n\r\nexport const toastStore = new ToastStore();\r\n","import { toastStore } from \"./store\";\nimport { Toast, ToastType } from \"./types\";\n\nexport type ToastOptions = Partial<Omit<Toast, \"id\" | \"type\" | \"createdAt\">>;\n\nfunction createToast(message: string | undefined, type: ToastType, options?: ToastOptions) {\n const id = crypto.randomUUID();\n\n toastStore.add({\n id,\n message,\n type,\n createdAt: Date.now(),\n ...options,\n });\n\n return id;\n}\n\nconst toastFn = (msg: string | undefined, type: ToastType = \"default\", options?: ToastOptions) => createToast(msg, type, options);\n\ntoastFn.success = (msg: string, options?: ToastOptions) => createToast(msg, \"success\", options);\ntoastFn.error = (msg: string, options?: ToastOptions) => createToast(msg, \"error\", options);\ntoastFn.info = (msg: string, options?: ToastOptions) => createToast(msg, \"info\", options);\ntoastFn.warning = (msg: string, options?: ToastOptions) => createToast(msg, \"warning\", options);\ntoastFn.loading = (msg: string, options?: ToastOptions) => createToast(msg, \"loading\", options);\ntoastFn.default = (msg: string, options?: ToastOptions) => createToast(msg, \"default\", options);\ntoastFn.custom = (options: ToastOptions) => createToast(options.message, \"default\", options);\n\ntoastFn.dismiss = (id: string) => toastStore.remove(id);\n\nexport const toast = toastFn;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIA,IAAM,aAAN,MAAiB;AAAA,EAAjB;AACE,SAAQ,SAAkB,CAAC;AAC3B,SAAQ,YAAwB,CAAC;AAAA;AAAA,EAEjC,UAAU,UAAoB;AAC5B,SAAK,UAAU,KAAK,QAAQ;AAC5B,WAAO,MAAM;AACX,WAAK,YAAY,KAAK,UAAU,OAAO,CAAC,MAAM,MAAM,QAAQ;AAAA,IAC9D;AAAA,EACF;AAAA,EAEA,YAAY;AACV,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAIA,QAAc;AAChB,SAAK,SAAS,CAACA,QAAO,GAAG,KAAK,MAAM;AACpC,SAAK,KAAK;AAAA,EACZ;AAAA,EAEA,OAAO,IAAY;AACjB,SAAK,SAAS,KAAK,OAAO,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE;AACnD,SAAK,KAAK;AAAA,EACZ;AAAA,EAEQ,OAAO;AACb,SAAK,UAAU,QAAQ,CAAC,MAAM,EAAE,CAAC;AAAA,EACnC;AACF;AAEO,IAAM,aAAa,IAAI,WAAW;;;AC7BzC,SAAS,YAAY,SAA6B,MAAiB,SAAwB;AACzF,QAAM,KAAK,OAAO,WAAW;AAE7B,aAAW,IAAI;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,KAAK,IAAI;AAAA,IACpB,GAAG;AAAA,EACL,CAAC;AAED,SAAO;AACT;AAEA,IAAM,UAAU,CAAC,KAAyB,OAAkB,WAAW,YAA2B,YAAY,KAAK,MAAM,OAAO;AAEhI,QAAQ,UAAU,CAAC,KAAa,YAA2B,YAAY,KAAK,WAAW,OAAO;AAC9F,QAAQ,QAAQ,CAAC,KAAa,YAA2B,YAAY,KAAK,SAAS,OAAO;AAC1F,QAAQ,OAAO,CAAC,KAAa,YAA2B,YAAY,KAAK,QAAQ,OAAO;AACxF,QAAQ,UAAU,CAAC,KAAa,YAA2B,YAAY,KAAK,WAAW,OAAO;AAC9F,QAAQ,UAAU,CAAC,KAAa,YAA2B,YAAY,KAAK,WAAW,OAAO;AAC9F,QAAQ,UAAU,CAAC,KAAa,YAA2B,YAAY,KAAK,WAAW,OAAO;AAC9F,QAAQ,SAAS,CAAC,YAA0B,YAAY,QAAQ,SAAS,WAAW,OAAO;AAE3F,QAAQ,UAAU,CAAC,OAAe,WAAW,OAAO,EAAE;AAE/C,IAAM,QAAQ;","names":["toast"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// packages/core/src/store.ts
|
|
2
|
+
var ToastStore = class {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.toasts = [];
|
|
5
|
+
this.listeners = [];
|
|
6
|
+
}
|
|
7
|
+
subscribe(listener) {
|
|
8
|
+
this.listeners.push(listener);
|
|
9
|
+
return () => {
|
|
10
|
+
this.listeners = this.listeners.filter((l) => l !== listener);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
getToasts() {
|
|
14
|
+
return this.toasts;
|
|
15
|
+
}
|
|
16
|
+
add(toast2) {
|
|
17
|
+
this.toasts = [toast2, ...this.toasts];
|
|
18
|
+
this.emit();
|
|
19
|
+
}
|
|
20
|
+
remove(id) {
|
|
21
|
+
this.toasts = this.toasts.filter((t) => t.id !== id);
|
|
22
|
+
this.emit();
|
|
23
|
+
}
|
|
24
|
+
emit() {
|
|
25
|
+
this.listeners.forEach((l) => l());
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var toastStore = new ToastStore();
|
|
29
|
+
|
|
30
|
+
// packages/core/src/toast.ts
|
|
31
|
+
function createToast(message, type, options) {
|
|
32
|
+
const id = crypto.randomUUID();
|
|
33
|
+
toastStore.add({
|
|
34
|
+
id,
|
|
35
|
+
message,
|
|
36
|
+
type,
|
|
37
|
+
createdAt: Date.now(),
|
|
38
|
+
...options
|
|
39
|
+
});
|
|
40
|
+
return id;
|
|
41
|
+
}
|
|
42
|
+
var toastFn = (msg, type = "default", options) => createToast(msg, type, options);
|
|
43
|
+
toastFn.success = (msg, options) => createToast(msg, "success", options);
|
|
44
|
+
toastFn.error = (msg, options) => createToast(msg, "error", options);
|
|
45
|
+
toastFn.info = (msg, options) => createToast(msg, "info", options);
|
|
46
|
+
toastFn.warning = (msg, options) => createToast(msg, "warning", options);
|
|
47
|
+
toastFn.loading = (msg, options) => createToast(msg, "loading", options);
|
|
48
|
+
toastFn.default = (msg, options) => createToast(msg, "default", options);
|
|
49
|
+
toastFn.custom = (options) => createToast(options.message, "default", options);
|
|
50
|
+
toastFn.dismiss = (id) => toastStore.remove(id);
|
|
51
|
+
var toast = toastFn;
|
|
52
|
+
export {
|
|
53
|
+
toast,
|
|
54
|
+
toastStore
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/store.ts","../src/toast.ts"],"sourcesContent":["import { Toast } from \"./types\";\r\n\r\ntype Listener = () => void;\r\n\r\nclass ToastStore {\r\n private toasts: Toast[] = [];\r\n private listeners: Listener[] = [];\r\n\r\n subscribe(listener: Listener) {\r\n this.listeners.push(listener);\r\n return () => {\r\n this.listeners = this.listeners.filter((l) => l !== listener);\r\n };\r\n }\r\n\r\n getToasts() {\r\n return this.toasts;\r\n }\r\n\r\n add(toast: Toast) {\r\n this.toasts = [toast, ...this.toasts];\r\n this.emit();\r\n }\r\n\r\n remove(id: string) {\r\n this.toasts = this.toasts.filter((t) => t.id !== id);\r\n this.emit();\r\n }\r\n\r\n private emit() {\r\n this.listeners.forEach((l) => l());\r\n }\r\n}\r\n\r\nexport const toastStore = new ToastStore();\r\n","import { toastStore } from \"./store\";\nimport { Toast, ToastType } from \"./types\";\n\nexport type ToastOptions = Partial<Omit<Toast, \"id\" | \"type\" | \"createdAt\">>;\n\nfunction createToast(message: string | undefined, type: ToastType, options?: ToastOptions) {\n const id = crypto.randomUUID();\n\n toastStore.add({\n id,\n message,\n type,\n createdAt: Date.now(),\n ...options,\n });\n\n return id;\n}\n\nconst toastFn = (msg: string | undefined, type: ToastType = \"default\", options?: ToastOptions) => createToast(msg, type, options);\n\ntoastFn.success = (msg: string, options?: ToastOptions) => createToast(msg, \"success\", options);\ntoastFn.error = (msg: string, options?: ToastOptions) => createToast(msg, \"error\", options);\ntoastFn.info = (msg: string, options?: ToastOptions) => createToast(msg, \"info\", options);\ntoastFn.warning = (msg: string, options?: ToastOptions) => createToast(msg, \"warning\", options);\ntoastFn.loading = (msg: string, options?: ToastOptions) => createToast(msg, \"loading\", options);\ntoastFn.default = (msg: string, options?: ToastOptions) => createToast(msg, \"default\", options);\ntoastFn.custom = (options: ToastOptions) => createToast(options.message, \"default\", options);\n\ntoastFn.dismiss = (id: string) => toastStore.remove(id);\n\nexport const toast = toastFn;\n"],"mappings":";AAIA,IAAM,aAAN,MAAiB;AAAA,EAAjB;AACE,SAAQ,SAAkB,CAAC;AAC3B,SAAQ,YAAwB,CAAC;AAAA;AAAA,EAEjC,UAAU,UAAoB;AAC5B,SAAK,UAAU,KAAK,QAAQ;AAC5B,WAAO,MAAM;AACX,WAAK,YAAY,KAAK,UAAU,OAAO,CAAC,MAAM,MAAM,QAAQ;AAAA,IAC9D;AAAA,EACF;AAAA,EAEA,YAAY;AACV,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAIA,QAAc;AAChB,SAAK,SAAS,CAACA,QAAO,GAAG,KAAK,MAAM;AACpC,SAAK,KAAK;AAAA,EACZ;AAAA,EAEA,OAAO,IAAY;AACjB,SAAK,SAAS,KAAK,OAAO,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE;AACnD,SAAK,KAAK;AAAA,EACZ;AAAA,EAEQ,OAAO;AACb,SAAK,UAAU,QAAQ,CAAC,MAAM,EAAE,CAAC;AAAA,EACnC;AACF;AAEO,IAAM,aAAa,IAAI,WAAW;;;AC7BzC,SAAS,YAAY,SAA6B,MAAiB,SAAwB;AACzF,QAAM,KAAK,OAAO,WAAW;AAE7B,aAAW,IAAI;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,KAAK,IAAI;AAAA,IACpB,GAAG;AAAA,EACL,CAAC;AAED,SAAO;AACT;AAEA,IAAM,UAAU,CAAC,KAAyB,OAAkB,WAAW,YAA2B,YAAY,KAAK,MAAM,OAAO;AAEhI,QAAQ,UAAU,CAAC,KAAa,YAA2B,YAAY,KAAK,WAAW,OAAO;AAC9F,QAAQ,QAAQ,CAAC,KAAa,YAA2B,YAAY,KAAK,SAAS,OAAO;AAC1F,QAAQ,OAAO,CAAC,KAAa,YAA2B,YAAY,KAAK,QAAQ,OAAO;AACxF,QAAQ,UAAU,CAAC,KAAa,YAA2B,YAAY,KAAK,WAAW,OAAO;AAC9F,QAAQ,UAAU,CAAC,KAAa,YAA2B,YAAY,KAAK,WAAW,OAAO;AAC9F,QAAQ,UAAU,CAAC,KAAa,YAA2B,YAAY,KAAK,WAAW,OAAO;AAC9F,QAAQ,SAAS,CAAC,YAA0B,YAAY,QAAQ,SAAS,WAAW,OAAO;AAE3F,QAAQ,UAAU,CAAC,OAAe,WAAW,OAAO,EAAE;AAE/C,IAAM,QAAQ;","names":["toast"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode, CSSProperties } from 'react';
|
|
3
|
+
|
|
4
|
+
declare function Toaster({ theme }?: {
|
|
5
|
+
theme?: "light" | "dark";
|
|
6
|
+
}): react_jsx_runtime.JSX.Element | null;
|
|
7
|
+
|
|
8
|
+
type ToastType = "success" | "error" | "info" | "warning" | "loading" | "default";
|
|
9
|
+
type ToastPosition = "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right";
|
|
10
|
+
interface Toast {
|
|
11
|
+
id: string;
|
|
12
|
+
message?: string;
|
|
13
|
+
description?: ReactNode;
|
|
14
|
+
type?: ToastType;
|
|
15
|
+
createdAt: number;
|
|
16
|
+
style?: CSSProperties;
|
|
17
|
+
className?: string;
|
|
18
|
+
duration?: number;
|
|
19
|
+
dismissible?: boolean;
|
|
20
|
+
position?: ToastPosition;
|
|
21
|
+
icon?: ReactNode;
|
|
22
|
+
iconColor?: string;
|
|
23
|
+
action?: {
|
|
24
|
+
label: string;
|
|
25
|
+
onClick: () => void;
|
|
26
|
+
};
|
|
27
|
+
render?: () => ReactNode;
|
|
28
|
+
progress?: number;
|
|
29
|
+
groupId?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type ToastOptions = Partial<Omit<Toast, "id" | "type" | "createdAt">>;
|
|
33
|
+
declare const toast: {
|
|
34
|
+
(msg: string | undefined, type?: ToastType, options?: ToastOptions): string;
|
|
35
|
+
success(msg: string, options?: ToastOptions): string;
|
|
36
|
+
error(msg: string, options?: ToastOptions): string;
|
|
37
|
+
info(msg: string, options?: ToastOptions): string;
|
|
38
|
+
warning(msg: string, options?: ToastOptions): string;
|
|
39
|
+
loading(msg: string, options?: ToastOptions): string;
|
|
40
|
+
default(msg: string, options?: ToastOptions): string;
|
|
41
|
+
custom(options: ToastOptions): string;
|
|
42
|
+
dismiss(id: string): void;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { Toaster, toast };
|