raku-toast-react 1.0.7 → 1.0.9
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/ToastProvider.d.ts.map +1 -1
- package/dist/ToastProvider.js +9 -10
- package/dist/toast-store.d.ts +3 -1
- package/dist/toast-store.d.ts.map +1 -1
- package/dist/toast-store.js +43 -16
- package/dist/toast.css +22 -10
- package/dist/toast.d.ts.map +1 -1
- package/dist/toast.js +0 -1
- package/package.json +10 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToastProvider.d.ts","sourceRoot":"","sources":["../src/ToastProvider.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ToastProvider.d.ts","sourceRoot":"","sources":["../src/ToastProvider.tsx"],"names":[],"mappings":"AAKA,OAAO,aAAa,CAAC;AAErB,eAAO,MAAM,aAAa,+CAwFzB,CAAC"}
|
package/dist/ToastProvider.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// src/ToastProvider.tsx
|
|
2
1
|
"use client";
|
|
3
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
3
|
import { useEffect, useState } from "react";
|
|
@@ -13,7 +12,7 @@ export const ToastProvider = () => {
|
|
|
13
12
|
error: _jsx(XCircle, { size: 22, className: "text-white" }),
|
|
14
13
|
info: _jsx(Info, { size: 22, className: "text-white" }),
|
|
15
14
|
};
|
|
16
|
-
return (_jsx("div", { className: "fixed top-1/2 -translate-y-1/2 right-4 z-50 w-
|
|
15
|
+
return (_jsx("div", { className: "fixed top-1/2 -translate-y-1/2 right-4 z-50 w-60 sm:w-72 pointer-events-none", children: _jsx("div", { className: "relative h-[600px]", children: toasts.map((t, index) => {
|
|
17
16
|
const offset = index * 78;
|
|
18
17
|
const scale = 1 - index * 0.03;
|
|
19
18
|
const opacity = 1 - index * 0.12;
|
|
@@ -26,14 +25,14 @@ export const ToastProvider = () => {
|
|
|
26
25
|
}, className: "toast-item absolute top-0 right-0 w-full flex items-start gap-3 sm:gap-4 px-4 py-3 sm:px-5 sm:py-4 rounded-2xl sm:rounded-lg shadow-2xl backdrop-blur-lg hover:scale-[1.02]", onMouseEnter: () => toastStore.pause(t.id), onMouseLeave: () => toastStore.resume(t.id), children: [_jsx("div", { className: `absolute inset-0 rounded-2xl sm:rounded-lg opacity-90 blur-sm shadow-lg ${t.type === "success"
|
|
27
26
|
? "bg-gradient-to-r from-purple-500 to-indigo-500"
|
|
28
27
|
: t.type === "error"
|
|
29
|
-
? "bg-gradient-to-r from-pink-500 to-
|
|
30
|
-
: "bg-gradient-to-r from-indigo-500 to-purple-600"}` }), _jsxs("div", { className: "relative flex w-full gap-3 sm:gap-4", children: [_jsx("div", { className: "mt-1", children: icons[t.type] }), _jsxs("div", { className: "flex-1", children: [_jsx("p", { className: "text-sm sm:text-base font-bold text-white drop-shadow-md", children: t.type.toUpperCase() }), _jsx("p", { className: "text-xs sm:text-sm text-white/90 leading-snug drop-shadow", children: t.message }), _jsx("div", { className: "mt-2 sm:mt-3 h-
|
|
31
|
-
? "
|
|
28
|
+
? "bg-gradient-to-r from-pink-500 to-rose-500"
|
|
29
|
+
: "bg-gradient-to-r from-indigo-500 to-purple-600"}` }), _jsxs("div", { className: "relative flex w-full gap-3 sm:gap-4", children: [_jsx("div", { className: "mt-1", children: icons[t.type] }), _jsxs("div", { className: "flex-1", children: [_jsx("p", { className: "text-sm sm:text-base font-bold text-white drop-shadow-md", children: t.type.toUpperCase() }), _jsx("p", { className: "text-xs sm:text-sm text-white/90 leading-snug drop-shadow", children: t.message }), _jsx("div", { className: "mt-2 sm:mt-3 h-1 sm:h-2 w-full rounded-full bg-white/20 overflow-hidden", children: _jsx("div", { className: `toast-progress ${t.type === "success"
|
|
30
|
+
? "toast-success"
|
|
32
31
|
: t.type === "error"
|
|
33
|
-
? "
|
|
34
|
-
: "
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
} }) })] }), _jsx("button", { onClick: () => toastStore.remove(t.id), className: "text-white
|
|
32
|
+
? "toast-error"
|
|
33
|
+
: "toast-info"} ${t._animate ? "animate-progress" : ""}`, style: {
|
|
34
|
+
animationDuration: `${t._remaining ?? t.duration ?? 3000}ms`,
|
|
35
|
+
animationPlayState: t._paused ? "paused" : "running",
|
|
36
|
+
} }) })] }), _jsx("button", { onClick: () => toastStore.remove(t.id), className: "text-white transition p-1 sm:p-2 rounded-lg hover:bg-white/20 cursor-pointer", children: _jsx(X, { size: 18, className: "sm:text-[20px]" }) })] })] }, t.id));
|
|
38
37
|
}) }) }));
|
|
39
38
|
};
|
package/dist/toast-store.d.ts
CHANGED
|
@@ -7,9 +7,11 @@ export interface Toast {
|
|
|
7
7
|
_timeout?: number;
|
|
8
8
|
_startTime?: number;
|
|
9
9
|
_remaining?: number;
|
|
10
|
+
_animate?: boolean;
|
|
11
|
+
_paused?: boolean;
|
|
10
12
|
}
|
|
11
13
|
export declare const toastStore: {
|
|
12
|
-
subscribe(fn: (
|
|
14
|
+
subscribe(fn: (toasts: Toast[]) => void): () => void;
|
|
13
15
|
push(message: string, type?: ToastType, duration?: number): void;
|
|
14
16
|
remove(toastId: number): void;
|
|
15
17
|
pause(toastId: number): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toast-store.d.ts","sourceRoot":"","sources":["../src/toast-store.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAErD,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"toast-store.d.ts","sourceRoot":"","sources":["../src/toast-store.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAErD,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAMD,eAAO,MAAM,UAAU;kBACP,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,IAAI;kBAQzB,MAAM,SAAQ,SAAS,aAAqB,MAAM;oBA8BhD,MAAM;mBASP,MAAM;oBAyBL,MAAM;CAsBvB,CAAC"}
|
package/dist/toast-store.js
CHANGED
|
@@ -10,44 +10,71 @@ export const toastStore = {
|
|
|
10
10
|
};
|
|
11
11
|
},
|
|
12
12
|
push(message, type = "info", duration = 3000) {
|
|
13
|
-
const
|
|
13
|
+
const newToast = {
|
|
14
14
|
id: ++id,
|
|
15
15
|
message,
|
|
16
16
|
type,
|
|
17
17
|
duration,
|
|
18
18
|
_remaining: duration,
|
|
19
|
+
_animate: false, // start false
|
|
20
|
+
_paused: false,
|
|
19
21
|
};
|
|
20
|
-
|
|
22
|
+
// Add toast immutably
|
|
23
|
+
toasts = [newToast, ...toasts];
|
|
21
24
|
listeners.forEach((l) => l(toasts));
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
// Trigger animation on next tick
|
|
26
|
+
requestAnimationFrame(() => {
|
|
27
|
+
toasts = toasts.map((t) => t.id === newToast.id ? { ...t, _animate: true } : t);
|
|
28
|
+
listeners.forEach((l) => l(toasts));
|
|
29
|
+
});
|
|
30
|
+
// Start auto-remove timer
|
|
31
|
+
newToast._startTime = Date.now();
|
|
32
|
+
newToast._timeout = window.setTimeout(() => {
|
|
33
|
+
toastStore.remove(newToast.id);
|
|
26
34
|
}, duration);
|
|
27
35
|
},
|
|
28
36
|
remove(toastId) {
|
|
29
|
-
const toast = toasts.find(t => t.id === toastId);
|
|
37
|
+
const toast = toasts.find((t) => t.id === toastId);
|
|
30
38
|
if (toast?._timeout)
|
|
31
39
|
clearTimeout(toast._timeout);
|
|
40
|
+
// Remove immutably
|
|
32
41
|
toasts = toasts.filter((t) => t.id !== toastId);
|
|
33
42
|
listeners.forEach((l) => l(toasts));
|
|
34
43
|
},
|
|
35
44
|
pause(toastId) {
|
|
36
45
|
const toast = toasts.find((t) => t.id === toastId);
|
|
37
|
-
if (!toast)
|
|
46
|
+
if (!toast || !toast._timeout)
|
|
38
47
|
return;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
toast.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
clearTimeout(toast._timeout);
|
|
49
|
+
const remaining = (toast._remaining ?? toast.duration ?? 3000) -
|
|
50
|
+
(Date.now() - (toast._startTime ?? 0));
|
|
51
|
+
// Update immutably
|
|
52
|
+
toasts = toasts.map((t) => t.id === toastId
|
|
53
|
+
? {
|
|
54
|
+
...t,
|
|
55
|
+
_paused: true,
|
|
56
|
+
_timeout: undefined,
|
|
57
|
+
_remaining: remaining,
|
|
58
|
+
}
|
|
59
|
+
: t);
|
|
60
|
+
listeners.forEach((l) => l(toasts));
|
|
45
61
|
},
|
|
46
62
|
resume(toastId) {
|
|
47
63
|
const toast = toasts.find((t) => t.id === toastId);
|
|
48
64
|
if (!toast || toast._timeout)
|
|
49
65
|
return;
|
|
50
|
-
|
|
51
|
-
|
|
66
|
+
const timeout = window.setTimeout(() => {
|
|
67
|
+
toastStore.remove(toastId);
|
|
68
|
+
}, toast._remaining ?? 3000);
|
|
69
|
+
// Update immutably
|
|
70
|
+
toasts = toasts.map((t) => t.id === toastId
|
|
71
|
+
? {
|
|
72
|
+
...t,
|
|
73
|
+
_paused: false,
|
|
74
|
+
_startTime: Date.now(),
|
|
75
|
+
_timeout: timeout,
|
|
76
|
+
}
|
|
77
|
+
: t);
|
|
78
|
+
listeners.forEach((l) => l(toasts));
|
|
52
79
|
},
|
|
53
80
|
};
|
package/dist/toast.css
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
/* src/toast.css */
|
|
2
|
-
@keyframes toast-progress {
|
|
3
|
-
from { width: 100%; }
|
|
4
|
-
to { width: 0%; }
|
|
5
|
-
}
|
|
6
|
-
|
|
7
1
|
.toast-progress {
|
|
8
|
-
width: 100%;
|
|
9
2
|
height: 100%;
|
|
10
|
-
|
|
3
|
+
width: 100%;
|
|
4
|
+
border-radius: inherit;
|
|
11
5
|
}
|
|
12
6
|
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
/* animation triggers shrink from 100% → 0% */
|
|
8
|
+
.animate-progress {
|
|
9
|
+
animation-name: progress;
|
|
10
|
+
animation-timing-function: linear;
|
|
11
|
+
animation-fill-mode: forwards;
|
|
15
12
|
}
|
|
13
|
+
|
|
14
|
+
@keyframes progress {
|
|
15
|
+
from { width: 100%; }
|
|
16
|
+
to { width: 0%; }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/* Colors */
|
|
20
|
+
/* .toast-success { background-color: #9a34ff !important; }
|
|
21
|
+
.toast-error { background-color: #ff4ae7 !important; }
|
|
22
|
+
.toast-info { background-color: #3145ff !important; } */
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
.toast-success { background-color: #ffffffec !important; }
|
|
26
|
+
.toast-error { background-color: #ffffffec !important; }
|
|
27
|
+
.toast-info { background-color: #ffffffec !important; }
|
package/dist/toast.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toast.d.ts","sourceRoot":"","sources":["../src/toast.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"toast.d.ts","sourceRoot":"","sources":["../src/toast.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,KAAK;mBACD,MAAM;iBACR,MAAM;gBACP,MAAM;CACnB,CAAC"}
|
package/dist/toast.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "raku-toast-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "A lightweight React toast library with gradient and animation",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -13,16 +13,16 @@
|
|
|
13
13
|
"postbuild": "cp src/toast.css dist/toast.css"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"react": "^
|
|
17
|
-
"react-dom": "^
|
|
18
|
-
"lucide-react": "
|
|
16
|
+
"react": "^19.2.1",
|
|
17
|
+
"react-dom": "^19.2.1",
|
|
18
|
+
"lucide-react": "^0.544.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@types/react": "^
|
|
22
|
-
"@types/react-dom": "^
|
|
23
|
-
"lucide-react": "^0.
|
|
24
|
-
"react": "^
|
|
25
|
-
"react-dom": "^
|
|
26
|
-
"typescript": "^5.
|
|
21
|
+
"@types/react": "^19.2.1",
|
|
22
|
+
"@types/react-dom": "^19.2.1",
|
|
23
|
+
"lucide-react": "^0.544.0",
|
|
24
|
+
"react": "^19.2.1",
|
|
25
|
+
"react-dom": "^19.2.1",
|
|
26
|
+
"typescript": "^5.9.3"
|
|
27
27
|
}
|
|
28
28
|
}
|