raku-toast-react 1.0.7 → 1.0.8

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,+CAuFzB,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;
@@ -27,13 +26,6 @@ export const ToastProvider = () => {
27
26
  ? "bg-gradient-to-r from-purple-500 to-indigo-500"
28
27
  : t.type === "error"
29
28
  ? "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"
32
- : 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));
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("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
30
  }) }) }));
39
31
  };
@@ -7,9 +7,10 @@ export interface Toast {
7
7
  _timeout?: number;
8
8
  _startTime?: number;
9
9
  _remaining?: number;
10
+ _animate?: boolean;
10
11
  }
11
12
  export declare const toastStore: {
12
- subscribe(fn: (t: Toast[]) => void): () => void;
13
+ subscribe(fn: (toasts: Toast[]) => void): () => void;
13
14
  push(message: string, type?: ToastType, duration?: number): void;
14
15
  remove(toastId: number): void;
15
16
  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;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAMD,eAAO,MAAM,UAAU;kBACP,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,IAAI;kBAQzB,MAAM,SAAQ,SAAS,aAAqB,MAAM;oBA2BhD,MAAM;mBAQP,MAAM;oBAaL,MAAM;CAWvB,CAAC"}
@@ -16,17 +16,21 @@ export const toastStore = {
16
16
  type,
17
17
  duration,
18
18
  _remaining: duration,
19
+ _animate: false, // start false
19
20
  };
20
21
  toasts = [toast, ...toasts];
21
22
  listeners.forEach((l) => l(toasts));
22
- // Start the auto-remove timer
23
+ // Trigger progress bar animation on next tick
24
+ requestAnimationFrame(() => {
25
+ toast._animate = true;
26
+ listeners.forEach((l) => l(toasts));
27
+ });
28
+ // Start auto-remove timer
23
29
  toast._startTime = Date.now();
24
- toast._timeout = setTimeout(() => {
25
- toastStore.remove(toast.id);
26
- }, duration);
30
+ toast._timeout = window.setTimeout(() => toastStore.remove(toast.id), duration);
27
31
  },
28
32
  remove(toastId) {
29
- const toast = toasts.find(t => t.id === toastId);
33
+ const toast = toasts.find((t) => t.id === toastId);
30
34
  if (toast?._timeout)
31
35
  clearTimeout(toast._timeout);
32
36
  toasts = toasts.filter((t) => t.id !== toastId);
@@ -34,20 +38,21 @@ export const toastStore = {
34
38
  },
35
39
  pause(toastId) {
36
40
  const toast = toasts.find((t) => t.id === toastId);
37
- if (!toast)
41
+ if (!toast || !toast._timeout)
38
42
  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
- }
43
+ clearTimeout(toast._timeout);
44
+ toast._timeout = undefined;
45
+ // calculate remaining time
46
+ toast._remaining =
47
+ (toast._remaining ?? 3000) - (Date.now() - (toast._startTime ?? 0));
48
+ listeners.forEach((l) => l(toasts));
45
49
  },
46
50
  resume(toastId) {
47
51
  const toast = toasts.find((t) => t.id === toastId);
48
52
  if (!toast || toast._timeout)
49
53
  return;
50
54
  toast._startTime = Date.now();
51
- toast._timeout = setTimeout(() => toastStore.remove(toast.id), toast._remaining ?? 3000);
55
+ toast._timeout = window.setTimeout(() => toastStore.remove(toast.id), toast._remaining ?? 3000);
56
+ listeners.forEach((l) => l(toasts));
52
57
  },
53
58
  };
package/dist/toast.css CHANGED
@@ -1,15 +1,22 @@
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: #c084fc !important; }
21
+ .toast-error { background-color: #f87171 !important; }
22
+ .toast-info { background-color: #818cf8 !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.8",
4
4
  "description": "A lightweight React toast library with gradient and animation",
5
5
  "private": false,
6
6
  "main": "dist/index.js",