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.
@@ -1 +1 @@
1
- {"version":3,"file":"ToastProvider.d.ts","sourceRoot":"","sources":["../src/ToastProvider.tsx"],"names":[],"mappings":"AAMA,OAAO,aAAa,CAAC;AAErB,eAAO,MAAM,aAAa,+CAqFzB,CAAC"}
1
+ {"version":3,"file":"ToastProvider.d.ts","sourceRoot":"","sources":["../src/ToastProvider.tsx"],"names":[],"mappings":"AAKA,OAAO,aAAa,CAAC;AAErB,eAAO,MAAM,aAAa,+CAwFzB,CAAC"}
@@ -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-64 sm:w-74 pointer-events-none", children: _jsx("div", { className: "relative h-[600px] w-64 sm:w-74", children: toasts.map((t, index) => {
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-red-500"
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-[3px] sm:h-[4px] w-full rounded-full bg-white/20 overflow-hidden", children: _jsx("div", { className: `toast-progress ${t.type === "success"
31
- ? "bg-purple-300"
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
- ? "bg-red-300"
34
- : "bg-indigo-300"}`, style: {
35
- width: `${((t._remaining ?? t.duration) / t.duration) * 100}%`,
36
- transition: `width ${t._remaining}ms linear`,
37
- } }) })] }), _jsx("button", { onClick: () => toastStore.remove(t.id), className: "text-white/80 text-white transition p-1 sm:p-2 rounded-lg hover:bg-white/20", children: _jsx(X, { size: 18, className: "sm:text-[20px]" }) })] })] }, t.id));
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
  };
@@ -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: (t: Toast[]) => void): () => void;
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;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAMD,eAAO,MAAM,UAAU;kBACP,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,IAAI;kBASpB,MAAM,SAAQ,SAAS,aAAqB,MAAM;oBAmBhD,MAAM;mBAQP,MAAM;oBAYL,MAAM;CAOvB,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"}
@@ -10,44 +10,71 @@ export const toastStore = {
10
10
  };
11
11
  },
12
12
  push(message, type = "info", duration = 3000) {
13
- const toast = {
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
- toasts = [toast, ...toasts];
22
+ // Add toast immutably
23
+ toasts = [newToast, ...toasts];
21
24
  listeners.forEach((l) => l(toasts));
22
- // Start the auto-remove timer
23
- toast._startTime = Date.now();
24
- toast._timeout = setTimeout(() => {
25
- toastStore.remove(toast.id);
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
- if (toast._timeout) {
40
- clearTimeout(toast._timeout);
41
- toast._timeout = undefined;
42
- // calculate remaining time
43
- toast._remaining = (toast._remaining ?? 3000) - (Date.now() - (toast._startTime ?? 0));
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
- toast._startTime = Date.now();
51
- toast._timeout = setTimeout(() => toastStore.remove(toast.id), toast._remaining ?? 3000);
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
- animation: toast-progress 3s linear forwards;
3
+ width: 100%;
4
+ border-radius: inherit;
11
5
  }
12
6
 
13
- .toast-item:hover .toast-progress {
14
- animation-play-state: paused; /* pauses animation on hover */
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; }
@@ -1 +1 @@
1
- {"version":3,"file":"toast.d.ts","sourceRoot":"","sources":["../src/toast.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,KAAK;mBACD,MAAM;iBACR,MAAM;gBACP,MAAM;CACnB,CAAC"}
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
@@ -1,4 +1,3 @@
1
- // src/toast.ts
2
1
  import { toastStore } from "./toast-store";
3
2
  export const toast = {
4
3
  success: (msg) => toastStore.push(msg, "success"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "raku-toast-react",
3
- "version": "1.0.7",
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": "^18.0.0",
17
- "react-dom": "^18.0.0",
18
- "lucide-react": ">=0.300.0"
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": "^18.2.0",
22
- "@types/react-dom": "^18.2.0",
23
- "lucide-react": "^0.300.0",
24
- "react": "^18.2.0",
25
- "react-dom": "^18.2.0",
26
- "typescript": "^5.1.6"
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
  }