raku-toast-react 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 ADDED
File without changes
@@ -0,0 +1,3 @@
1
+ import "./toast.css";
2
+ export declare const ToastProvider: () => import("react/jsx-runtime").JSX.Element;
3
+ //# sourceMappingURL=ToastProvider.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,39 @@
1
+ // src/ToastProvider.tsx
2
+ "use client";
3
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
+ import { useEffect, useState } from "react";
5
+ import { toastStore } from "./toast-store";
6
+ import { CheckCircle, XCircle, Info, X } from "lucide-react";
7
+ import "./toast.css";
8
+ export const ToastProvider = () => {
9
+ const [toasts, setToasts] = useState([]);
10
+ useEffect(() => toastStore.subscribe(setToasts), []);
11
+ const icons = {
12
+ success: _jsx(CheckCircle, { size: 22, className: "text-white" }),
13
+ error: _jsx(XCircle, { size: 22, className: "text-white" }),
14
+ info: _jsx(Info, { size: 22, className: "text-white" }),
15
+ };
16
+ return (_jsx("div", { className: "fixed top-1/2 -translate-y-1/2 right-4 z-50 w-full max-w-[380px] sm:max-w-[360px] pointer-events-none", children: _jsx("div", { className: "relative h-[600px]", children: toasts.map((t, index) => {
17
+ const offset = index * 78;
18
+ const scale = 1 - index * 0.03;
19
+ const opacity = 1 - index * 0.12;
20
+ return (_jsxs("div", { style: {
21
+ transform: `translateY(${offset}px) scale(${scale})`,
22
+ opacity,
23
+ zIndex: 100 - index,
24
+ pointerEvents: "auto",
25
+ transition: "transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.35s ease-out",
26
+ }, 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
+ ? "bg-gradient-to-r from-purple-500 to-indigo-500"
28
+ : 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"
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 hover: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));
38
+ }) }) }));
39
+ };
@@ -0,0 +1,4 @@
1
+ export * from "./ToastProvider";
2
+ export * from "./toast-store";
3
+ export * from "./toast";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ // src/index.ts
2
+ export * from "./ToastProvider";
3
+ export * from "./toast-store";
4
+ export * from "./toast";
@@ -0,0 +1,18 @@
1
+ export type ToastType = "success" | "error" | "info";
2
+ export interface Toast {
3
+ id: number;
4
+ message: string;
5
+ type: ToastType;
6
+ duration?: number;
7
+ _timeout?: number;
8
+ _startTime?: number;
9
+ _remaining?: number;
10
+ }
11
+ export declare const toastStore: {
12
+ subscribe(fn: (t: Toast[]) => void): () => void;
13
+ push(message: string, type?: ToastType, duration?: number): void;
14
+ remove(toastId: number): void;
15
+ pause(toastId: number): void;
16
+ resume(toastId: number): void;
17
+ };
18
+ //# sourceMappingURL=toast-store.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,53 @@
1
+ let listeners = [];
2
+ let toasts = [];
3
+ let id = 0;
4
+ export const toastStore = {
5
+ subscribe(fn) {
6
+ listeners.push(fn);
7
+ fn(toasts);
8
+ return () => {
9
+ listeners = listeners.filter((l) => l !== fn);
10
+ };
11
+ },
12
+ push(message, type = "info", duration = 3000) {
13
+ const toast = {
14
+ id: ++id,
15
+ message,
16
+ type,
17
+ duration,
18
+ _remaining: duration,
19
+ };
20
+ toasts = [toast, ...toasts];
21
+ 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);
26
+ }, duration);
27
+ },
28
+ remove(toastId) {
29
+ const toast = toasts.find(t => t.id === toastId);
30
+ if (toast?._timeout)
31
+ clearTimeout(toast._timeout);
32
+ toasts = toasts.filter((t) => t.id !== toastId);
33
+ listeners.forEach((l) => l(toasts));
34
+ },
35
+ pause(toastId) {
36
+ const toast = toasts.find((t) => t.id === toastId);
37
+ if (!toast)
38
+ 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
+ }
45
+ },
46
+ resume(toastId) {
47
+ const toast = toasts.find((t) => t.id === toastId);
48
+ if (!toast || toast._timeout)
49
+ return;
50
+ toast._startTime = Date.now();
51
+ toast._timeout = setTimeout(() => toastStore.remove(toast.id), toast._remaining ?? 3000);
52
+ },
53
+ };
package/dist/toast.css ADDED
@@ -0,0 +1,15 @@
1
+ /* src/toast.css */
2
+ @keyframes toast-progress {
3
+ from { width: 100%; }
4
+ to { width: 0%; }
5
+ }
6
+
7
+ .toast-progress {
8
+ width: 100%;
9
+ height: 100%;
10
+ animation: toast-progress 3s linear forwards;
11
+ }
12
+
13
+ .toast-item:hover .toast-progress {
14
+ animation-play-state: paused; /* pauses animation on hover */
15
+ }
@@ -0,0 +1,6 @@
1
+ export declare const toast: {
2
+ success: (msg: string) => void;
3
+ error: (msg: string) => void;
4
+ info: (msg: string) => void;
5
+ };
6
+ //# sourceMappingURL=toast.d.ts.map
@@ -0,0 +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"}
package/dist/toast.js ADDED
@@ -0,0 +1,7 @@
1
+ // src/toast.ts
2
+ import { toastStore } from "./toast-store";
3
+ export const toast = {
4
+ success: (msg) => toastStore.push(msg, "success"),
5
+ error: (msg) => toastStore.push(msg, "error"),
6
+ info: (msg) => toastStore.push(msg, "info"),
7
+ };
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "raku-toast-react",
3
+ "version": "1.0.0",
4
+ "description": "A lightweight React toast library with gradient and animation",
5
+ "private": false,
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.esm.js",
8
+ "types": "dist/index.d.ts",
9
+ "files": ["dist"],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "prepare": "npm run build",
13
+ "postbuild": "cp src/toast.css dist/toast.css"
14
+ },
15
+ "peerDependencies": {
16
+ "react": "^18.0.0",
17
+ "react-dom": "^18.0.0",
18
+ "lucide-react": ">=0.300.0"
19
+ },
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"
27
+ }
28
+ }