react-toast-msg 2.5.9 → 2.6.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/LICENSE.md CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 SudhuCodes
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 SudhuCodes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,79 +1,79 @@
1
- ![banner](https://rtm.sudhucodes.com/opengraph-image.png)
2
-
3
- # React Toast MSG
4
-
5
- A lightweight, customizable, and high-performance React toast notification library with zero-config and fast setup.
6
-
7
- ![Version](https://img.shields.io/npm/v/react-toast-msg)
8
- ![License](https://img.shields.io/npm/l/react-toast-msg)
9
- ![Downloads](https://img.shields.io/npm/dt/react-toast-msg)
10
-
11
- ## ✨ Features
12
-
13
- - **🚀 Zero Config**: Works out of the box with sensible defaults.
14
- - **🎨 Tailwind Driven**: Styled with Tailwind CSS for modern aesthetics.
15
- - **⚡ Performance**: Built with tsup for high performance and small bundle size.
16
- - **🔧 Customizable**: Easily customize duration, type, and icons.
17
- - **🧩 Promise Support**: First-class support for `toast.promise`.
18
-
19
- ## 📦 Installation
20
-
21
- ```bash
22
- npm install react-toast-msg
23
- # or
24
- pnpm add react-toast-msg
25
- # or
26
- yarn add react-toast-msg
27
- ```
28
-
29
- ## 🛠️ Usage
30
-
31
- 1. **Add the ToastContainer** to the root of your application:
32
-
33
- ```tsx
34
- import { ToastContainer } from 'react-toast-msg';
35
- import 'react-toast-msg/style.css';
36
-
37
- function App() {
38
- return (
39
- <>
40
- <YourApp />
41
- <ToastContainer />
42
- </>
43
- );
44
- }
45
- ```
46
-
47
- 2. **Trigger toasts** from anywhere:
48
-
49
- ```tsx
50
- import { toast } from 'react-toast-msg';
51
-
52
- // Basic toast
53
- toast('Hello World!');
54
-
55
- // Typed toasts
56
- toast.success('Your changes have been saved.');
57
- toast.error('An error occurred. Please try again.');
58
- toast.warning('Check your internet connection.');
59
- toast.loading('Saving results...');
60
-
61
- // Promise toast
62
- toast.promise(saveData(), {
63
- loading: 'Saving...',
64
- success: 'Saved successfully!',
65
- error: 'Failed to save.'
66
- });
67
- ```
68
-
69
- ## 📄 Documentation
70
-
71
- Learn more and explore examples at [rtm.sudhucodes.com](https://rtm.sudhucodes.com/docs).
72
-
73
- ## 🤝 Contributing
74
-
75
- We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for more details.
76
-
77
- ## 📜 License
78
-
79
- This project is licensed under the [MIT License](LICENSE.md).
1
+ ![banner](https://rtm.sudhucodes.com/opengraph-image.png)
2
+
3
+ # React Toast MSG
4
+
5
+ A lightweight, customizable, and high-performance React toast notification library with zero-config and fast setup.
6
+
7
+ ![Version](https://img.shields.io/npm/v/react-toast-msg)
8
+ ![License](https://img.shields.io/npm/l/react-toast-msg)
9
+ ![Downloads](https://img.shields.io/npm/dt/react-toast-msg)
10
+
11
+ ## ✨ Features
12
+
13
+ - **🚀 Zero Config**: Works out of the box with sensible defaults.
14
+ - **🎨 Tailwind Driven**: Styled with Tailwind CSS for modern aesthetics.
15
+ - **⚡ Performance**: Built with tsup for high performance and small bundle size.
16
+ - **🔧 Customizable**: Easily customize duration, type, and icons.
17
+ - **🧩 Promise Support**: First-class support for `toast.promise`.
18
+
19
+ ## 📦 Installation
20
+
21
+ ```bash
22
+ npm install react-toast-msg
23
+ # or
24
+ pnpm add react-toast-msg
25
+ # or
26
+ yarn add react-toast-msg
27
+ ```
28
+
29
+ ## 🛠️ Usage
30
+
31
+ 1. **Add the ToastContainer** to the root of your application:
32
+
33
+ ```tsx
34
+ import { ToastContainer } from 'react-toast-msg';
35
+ import 'react-toast-msg/style.css';
36
+
37
+ function App() {
38
+ return (
39
+ <>
40
+ <YourApp />
41
+ <ToastContainer />
42
+ </>
43
+ );
44
+ }
45
+ ```
46
+
47
+ 2. **Trigger toasts** from anywhere:
48
+
49
+ ```tsx
50
+ import { toast } from 'react-toast-msg';
51
+
52
+ // Basic toast
53
+ toast('Hello World!');
54
+
55
+ // Typed toasts
56
+ toast.success('Your changes have been saved.');
57
+ toast.error('An error occurred. Please try again.');
58
+ toast.warning('Check your internet connection.');
59
+ toast.loading('Saving results...');
60
+
61
+ // Promise toast
62
+ toast.promise(saveData(), {
63
+ loading: 'Saving...',
64
+ success: 'Saved successfully!',
65
+ error: 'Failed to save.'
66
+ });
67
+ ```
68
+
69
+ ## 📄 Documentation
70
+
71
+ Learn more and explore examples at [rtm.sudhucodes.com](https://rtm.sudhucodes.com/docs).
72
+
73
+ ## 🤝 Contributing
74
+
75
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for more details.
76
+
77
+ ## 📜 License
78
+
79
+ This project is licensed under the [MIT License](LICENSE.md).
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var react=require('react'),tailwindMerge=require('tailwind-merge'),Z=require('clsx'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Z__default=/*#__PURE__*/_interopDefault(Z);function a(...t){return tailwindMerge.twMerge(Z__default.default(t))}function y({message:t,type:o="default",icon:p,leaving:n,setToasts:e,id:c,closeButton:m}){let[h,i]=react.useState(false);react.useEffect(()=>{requestAnimationFrame(()=>i(true));},[]);let d=()=>{i(false),setTimeout(()=>{e==null||e(l=>l.filter(v=>v.id!==c));},300);};return jsxRuntime.jsxs("div",{className:a("pointer-events-auto relative flex max-w-80 min-w-62 items-center gap-1 rounded-lg border border-gray-200/70 bg-white py-3 text-sm text-zinc-800 transition-all duration-300 ease-out",h&&!n?"translate-y-0 opacity-100":"translate-y-10 opacity-0",o==="default"?"px-4":"px-3"),children:[p,t,m&&jsxRuntime.jsx("button",{onClick:d,className:"absolute -top-2 -right-2 cursor-pointer rounded-full border border-gray-200/70 bg-white p-px text-zinc-500",children:jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 16 16",fill:"currentColor",className:"size-3",children:jsxRuntime.jsx("path",{d:"M5.28 4.22a.75.75 0 0 0-1.06 1.06L6.94 8l-2.72 2.72a.75.75 0 1 0 1.06 1.06L8 9.06l2.72 2.72a.75.75 0 1 0 1.06-1.06L9.06 8l2.72-2.72a.75.75 0 0 0-1.06-1.06L8 6.94 5.28 4.22Z"})})})]})}function I(t){switch(t){case "success":return jsxRuntime.jsx(M,{});case "error":return jsxRuntime.jsx(b,{});case "warning":return jsxRuntime.jsx(L,{});case "loading":return jsxRuntime.jsx(P,{});default:return null}}var T=null;function B({autoClose:t=3e3,closeButton:o=false}){let[p,n]=react.useState([]);return react.useEffect(()=>{T=(e,c={})=>{let{type:m="default",duration:h,closeButton:i,id:d}=c,l=d!=null?d:Date.now(),v=h||t;return n(g=>g.find(f=>f.id===l)?g.map(f=>f.id===l?{...f,message:e,type:m,leaving:false,closeButton:i!=null?i:o}:f):[...g,{id:l,message:e,type:m,leaving:false,closeButton:i!=null?i:o}]),m!=="loading"&&setTimeout(()=>{n(g=>g.map(u=>u.id===l?{...u,leaving:true}:u)),setTimeout(()=>{n(g=>g.filter(u=>u.id!==l));},300);},v),l};},[t,o]),jsxRuntime.jsx("div",{className:a("pointer-events-none fixed inset-0 z-9999 flex flex-col items-end justify-end gap-2 p-4 text-sm"),children:p.map(e=>jsxRuntime.jsx(y,{id:e.id,message:e.message,setToasts:n,type:e.type,icon:I(e.type),leaving:e.leaving,closeButton:e.closeButton},e.id))})}function s(t,o){if(T)return T(t,o)}s.success=(t,o)=>s(t,{...o,type:"success"});s.error=(t,o)=>s(t,{...o,type:"error"});s.warning=(t,o)=>s(t,{...o,type:"warning"});s.loading=(t,o)=>s(t,{...o,type:"loading"});s.promise=(t,o,p)=>{let n=Date.now().toString()+Math.random().toString(36).substring(2);return s(o.loading,{...p,type:"loading",id:n,duration:1/0}),t.then(e=>{let c=typeof o.success=="function"?o.success(e):o.success;s(c,{...p,type:"success",id:n});}).catch(e=>{let c=typeof o.error=="function"?o.error(e):o.error;s(c,{...p,type:"error",id:n});}),t};var M=({className:t})=>jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:a("size-5.5",t),height:24,width:24,children:jsxRuntime.jsx("path",{fillRule:"evenodd",d:"M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12Zm13.36-1.814a.75.75 0 1 0-1.22-.872l-3.236 4.53L9.53 12.22a.75.75 0 0 0-1.06 1.06l2.25 2.25a.75.75 0 0 0 1.14-.094l3.75-5.25Z",clipRule:"evenodd"})}),b=({className:t})=>jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:a("size-5.5",t),height:24,width:24,children:jsxRuntime.jsx("path",{fillRule:"evenodd",d:"M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12ZM12 8.25a.75.75 0 0 1 .75.75v3.75a.75.75 0 0 1-1.5 0V9a.75.75 0 0 1 .75-.75Zm0 8.25a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Z",clipRule:"evenodd"})}),L=({className:t})=>jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:a("size-5.5",t),height:24,width:24,children:jsxRuntime.jsx("path",{fillRule:"evenodd",d:"M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003ZM12 8.25a.75.75 0 0 1 .75.75v3.75a.75.75 0 0 1-1.5 0V9a.75.75 0 0 1 .75-.75Zm0 8.25a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Z",clipRule:"evenodd"})}),P=({className:t})=>jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:a("size-5.5 animate-spin",t),children:[jsxRuntime.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),jsxRuntime.jsx("path",{d:"M12 6l0 -3"}),jsxRuntime.jsx("path",{d:"M16.25 7.75l2.15 -2.15"}),jsxRuntime.jsx("path",{d:"M18 12l3 0"}),jsxRuntime.jsx("path",{d:"M16.25 16.25l2.15 2.15"}),jsxRuntime.jsx("path",{d:"M12 18l0 3"}),jsxRuntime.jsx("path",{d:"M7.75 16.25l-2.15 2.15"}),jsxRuntime.jsx("path",{d:"M6 12l-3 0"}),jsxRuntime.jsx("path",{d:"M7.75 7.75l-2.15 -2.15"})]});
2
- exports.ToastContainer=B;exports.toast=s;
1
+ "use client";
2
+ "use strict";var B=Object.create;var v=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var F=(t,o)=>{for(var s in o)v(t,s,{get:o[s],enumerable:!0})},L=(t,o,s,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of E(o))!D.call(t,e)&&e!==s&&v(t,e,{get:()=>o[e],enumerable:!(i=V(o,e))||i.enumerable});return t};var H=(t,o,s)=>(s=t!=null?B(W(t)):{},L(o||!t||!t.__esModule?v(s,"default",{value:t,enumerable:!0}):s,t)),q=t=>L(v({},"__esModule",{value:!0}),t);var A={};F(A,{ToastContainer:()=>R,toast:()=>n});module.exports=q(A);var x=require("react");var P=require("tailwind-merge"),z=H(require("clsx"));function l(...t){return(0,P.twMerge)((0,z.default)(t))}var m=require("react/jsx-runtime");function C({message:t,type:o="default",icon:s,leaving:i,setToasts:e,id:c,closeButton:d}){let[y,a]=(0,x.useState)(!1);(0,x.useEffect)(()=>{requestAnimationFrame(()=>a(!0))},[]);let f=()=>{a(!1),setTimeout(()=>{e==null||e(p=>p.filter(I=>I.id!==c))},300)};return(0,m.jsxs)("div",{className:l("pointer-events-auto relative flex max-w-80 min-w-62 items-center gap-1 rounded-lg border border-gray-200/70 bg-white py-3 text-sm text-zinc-800 transition-all duration-300 ease-out",y&&!i?"translate-y-0 opacity-100":"translate-y-10 opacity-0",o==="default"?"px-4":"px-3"),children:[s,t,d&&(0,m.jsx)("button",{onClick:f,className:"absolute -top-2 -right-2 cursor-pointer rounded-full border border-gray-200/70 bg-white p-px text-zinc-500",children:(0,m.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 16 16",fill:"currentColor",className:"size-3",children:(0,m.jsx)("path",{d:"M5.28 4.22a.75.75 0 0 0-1.06 1.06L6.94 8l-2.72 2.72a.75.75 0 1 0 1.06 1.06L8 9.06l2.72 2.72a.75.75 0 1 0 1.06-1.06L9.06 8l2.72-2.72a.75.75 0 0 0-1.06-1.06L8 6.94 5.28 4.22Z"})})})]})}var T=require("react");var h=require("react/jsx-runtime");function Z(t){switch(t){case"success":return(0,h.jsx)(k,{});case"error":return(0,h.jsx)(N,{});case"warning":return(0,h.jsx)(O,{});case"loading":return(0,h.jsx)(S,{});default:return null}}var b=require("react/jsx-runtime"),M=null;function R({autoClose:t=3e3,closeButton:o=!1}){let[s,i]=(0,T.useState)([]);return(0,T.useEffect)(()=>{M=(e,c={})=>{let{type:d="default",duration:y,closeButton:a,id:f}=c,p=f!=null?f:Date.now(),I=y||t;return i(g=>g.find(w=>w.id===p)?g.map(w=>w.id===p?{...w,message:e,type:d,leaving:!1,closeButton:a!=null?a:o}:w):[...g,{id:p,message:e,type:d,leaving:!1,closeButton:a!=null?a:o}]),d!=="loading"&&setTimeout(()=>{i(g=>g.map(u=>u.id===p?{...u,leaving:!0}:u)),setTimeout(()=>{i(g=>g.filter(u=>u.id!==p))},300)},I),p}},[t,o]),(0,b.jsx)("div",{className:l("pointer-events-none fixed inset-0 z-9999 flex flex-col items-end justify-end gap-2 p-4 text-sm"),children:s.map(e=>(0,b.jsx)(C,{id:e.id,message:e.message,setToasts:i,type:e.type,icon:Z(e.type),leaving:e.leaving,closeButton:e.closeButton},e.id))})}function n(t,o){if(M)return M(t,o)}n.success=(t,o)=>n(t,{...o,type:"success"});n.error=(t,o)=>n(t,{...o,type:"error"});n.warning=(t,o)=>n(t,{...o,type:"warning"});n.loading=(t,o)=>n(t,{...o,type:"loading"});n.promise=(t,o,s)=>{let i=Date.now().toString()+Math.random().toString(36).substring(2);return n(o.loading,{...s,type:"loading",id:i,duration:1/0}),t.then(e=>{let c=typeof o.success=="function"?o.success(e):o.success;n(c,{...s,type:"success",id:i})}).catch(e=>{let c=typeof o.error=="function"?o.error(e):o.error;n(c,{...s,type:"error",id:i})}),t};var r=require("react/jsx-runtime"),k=({className:t})=>(0,r.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:l("size-5.5",t),height:24,width:24,children:(0,r.jsx)("path",{fillRule:"evenodd",d:"M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12Zm13.36-1.814a.75.75 0 1 0-1.22-.872l-3.236 4.53L9.53 12.22a.75.75 0 0 0-1.06 1.06l2.25 2.25a.75.75 0 0 0 1.14-.094l3.75-5.25Z",clipRule:"evenodd"})}),N=({className:t})=>(0,r.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:l("size-5.5",t),height:24,width:24,children:(0,r.jsx)("path",{fillRule:"evenodd",d:"M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12ZM12 8.25a.75.75 0 0 1 .75.75v3.75a.75.75 0 0 1-1.5 0V9a.75.75 0 0 1 .75-.75Zm0 8.25a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Z",clipRule:"evenodd"})}),O=({className:t})=>(0,r.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:l("size-5.5",t),height:24,width:24,children:(0,r.jsx)("path",{fillRule:"evenodd",d:"M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003ZM12 8.25a.75.75 0 0 1 .75.75v3.75a.75.75 0 0 1-1.5 0V9a.75.75 0 0 1 .75-.75Zm0 8.25a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Z",clipRule:"evenodd"})}),S=({className:t})=>(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:l("size-5.5 animate-spin",t),children:[(0,r.jsx)("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),(0,r.jsx)("path",{d:"M12 6l0 -3"}),(0,r.jsx)("path",{d:"M16.25 7.75l2.15 -2.15"}),(0,r.jsx)("path",{d:"M18 12l3 0"}),(0,r.jsx)("path",{d:"M16.25 16.25l2.15 2.15"}),(0,r.jsx)("path",{d:"M12 18l0 3"}),(0,r.jsx)("path",{d:"M7.75 16.25l-2.15 2.15"}),(0,r.jsx)("path",{d:"M6 12l-3 0"}),(0,r.jsx)("path",{d:"M7.75 7.75l-2.15 -2.15"})]});0&&(module.exports={ToastContainer,toast});
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import {useState,useEffect}from'react';import {twMerge}from'tailwind-merge';import Z from'clsx';import {jsx,jsxs}from'react/jsx-runtime';function a(...t){return twMerge(Z(t))}function y({message:t,type:o="default",icon:p,leaving:n,setToasts:e,id:c,closeButton:m}){let[h,i]=useState(false);useEffect(()=>{requestAnimationFrame(()=>i(true));},[]);let d=()=>{i(false),setTimeout(()=>{e==null||e(l=>l.filter(v=>v.id!==c));},300);};return jsxs("div",{className:a("pointer-events-auto relative flex max-w-80 min-w-62 items-center gap-1 rounded-lg border border-gray-200/70 bg-white py-3 text-sm text-zinc-800 transition-all duration-300 ease-out",h&&!n?"translate-y-0 opacity-100":"translate-y-10 opacity-0",o==="default"?"px-4":"px-3"),children:[p,t,m&&jsx("button",{onClick:d,className:"absolute -top-2 -right-2 cursor-pointer rounded-full border border-gray-200/70 bg-white p-px text-zinc-500",children:jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 16 16",fill:"currentColor",className:"size-3",children:jsx("path",{d:"M5.28 4.22a.75.75 0 0 0-1.06 1.06L6.94 8l-2.72 2.72a.75.75 0 1 0 1.06 1.06L8 9.06l2.72 2.72a.75.75 0 1 0 1.06-1.06L9.06 8l2.72-2.72a.75.75 0 0 0-1.06-1.06L8 6.94 5.28 4.22Z"})})})]})}function I(t){switch(t){case "success":return jsx(M,{});case "error":return jsx(b,{});case "warning":return jsx(L,{});case "loading":return jsx(P,{});default:return null}}var T=null;function B({autoClose:t=3e3,closeButton:o=false}){let[p,n]=useState([]);return useEffect(()=>{T=(e,c={})=>{let{type:m="default",duration:h,closeButton:i,id:d}=c,l=d!=null?d:Date.now(),v=h||t;return n(g=>g.find(f=>f.id===l)?g.map(f=>f.id===l?{...f,message:e,type:m,leaving:false,closeButton:i!=null?i:o}:f):[...g,{id:l,message:e,type:m,leaving:false,closeButton:i!=null?i:o}]),m!=="loading"&&setTimeout(()=>{n(g=>g.map(u=>u.id===l?{...u,leaving:true}:u)),setTimeout(()=>{n(g=>g.filter(u=>u.id!==l));},300);},v),l};},[t,o]),jsx("div",{className:a("pointer-events-none fixed inset-0 z-9999 flex flex-col items-end justify-end gap-2 p-4 text-sm"),children:p.map(e=>jsx(y,{id:e.id,message:e.message,setToasts:n,type:e.type,icon:I(e.type),leaving:e.leaving,closeButton:e.closeButton},e.id))})}function s(t,o){if(T)return T(t,o)}s.success=(t,o)=>s(t,{...o,type:"success"});s.error=(t,o)=>s(t,{...o,type:"error"});s.warning=(t,o)=>s(t,{...o,type:"warning"});s.loading=(t,o)=>s(t,{...o,type:"loading"});s.promise=(t,o,p)=>{let n=Date.now().toString()+Math.random().toString(36).substring(2);return s(o.loading,{...p,type:"loading",id:n,duration:1/0}),t.then(e=>{let c=typeof o.success=="function"?o.success(e):o.success;s(c,{...p,type:"success",id:n});}).catch(e=>{let c=typeof o.error=="function"?o.error(e):o.error;s(c,{...p,type:"error",id:n});}),t};var M=({className:t})=>jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:a("size-5.5",t),height:24,width:24,children:jsx("path",{fillRule:"evenodd",d:"M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12Zm13.36-1.814a.75.75 0 1 0-1.22-.872l-3.236 4.53L9.53 12.22a.75.75 0 0 0-1.06 1.06l2.25 2.25a.75.75 0 0 0 1.14-.094l3.75-5.25Z",clipRule:"evenodd"})}),b=({className:t})=>jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:a("size-5.5",t),height:24,width:24,children:jsx("path",{fillRule:"evenodd",d:"M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12ZM12 8.25a.75.75 0 0 1 .75.75v3.75a.75.75 0 0 1-1.5 0V9a.75.75 0 0 1 .75-.75Zm0 8.25a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Z",clipRule:"evenodd"})}),L=({className:t})=>jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:a("size-5.5",t),height:24,width:24,children:jsx("path",{fillRule:"evenodd",d:"M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003ZM12 8.25a.75.75 0 0 1 .75.75v3.75a.75.75 0 0 1-1.5 0V9a.75.75 0 0 1 .75-.75Zm0 8.25a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Z",clipRule:"evenodd"})}),P=({className:t})=>jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:a("size-5.5 animate-spin",t),children:[jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),jsx("path",{d:"M12 6l0 -3"}),jsx("path",{d:"M16.25 7.75l2.15 -2.15"}),jsx("path",{d:"M18 12l3 0"}),jsx("path",{d:"M16.25 16.25l2.15 2.15"}),jsx("path",{d:"M12 18l0 3"}),jsx("path",{d:"M7.75 16.25l-2.15 2.15"}),jsx("path",{d:"M6 12l-3 0"}),jsx("path",{d:"M7.75 7.75l-2.15 -2.15"})]});
2
- export{B as ToastContainer,s as toast};
1
+ "use client";
2
+ import{useEffect as k,useState as N}from"react";import{twMerge as C}from"tailwind-merge";import Z from"clsx";function a(...t){return C(Z(t))}import{jsx as x,jsxs as O}from"react/jsx-runtime";function y({message:t,type:o="default",icon:p,leaving:n,setToasts:e,id:c,closeButton:m}){let[h,i]=N(!1);k(()=>{requestAnimationFrame(()=>i(!0))},[]);let d=()=>{i(!1),setTimeout(()=>{e==null||e(l=>l.filter(v=>v.id!==c))},300)};return O("div",{className:a("pointer-events-auto relative flex max-w-80 min-w-62 items-center gap-1 rounded-lg border border-gray-200/70 bg-white py-3 text-sm text-zinc-800 transition-all duration-300 ease-out",h&&!n?"translate-y-0 opacity-100":"translate-y-10 opacity-0",o==="default"?"px-4":"px-3"),children:[p,t,m&&x("button",{onClick:d,className:"absolute -top-2 -right-2 cursor-pointer rounded-full border border-gray-200/70 bg-white p-px text-zinc-500",children:x("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 16 16",fill:"currentColor",className:"size-3",children:x("path",{d:"M5.28 4.22a.75.75 0 0 0-1.06 1.06L6.94 8l-2.72 2.72a.75.75 0 1 0 1.06 1.06L8 9.06l2.72 2.72a.75.75 0 1 0 1.06-1.06L9.06 8l2.72-2.72a.75.75 0 0 0-1.06-1.06L8 6.94 5.28 4.22Z"})})})]})}import{useState as S,useEffect as R}from"react";import{jsx as w}from"react/jsx-runtime";function I(t){switch(t){case"success":return w(M,{});case"error":return w(b,{});case"warning":return w(L,{});case"loading":return w(P,{});default:return null}}import{jsx as z}from"react/jsx-runtime";var T=null;function B({autoClose:t=3e3,closeButton:o=!1}){let[p,n]=S([]);return R(()=>{T=(e,c={})=>{let{type:m="default",duration:h,closeButton:i,id:d}=c,l=d!=null?d:Date.now(),v=h||t;return n(g=>g.find(f=>f.id===l)?g.map(f=>f.id===l?{...f,message:e,type:m,leaving:!1,closeButton:i!=null?i:o}:f):[...g,{id:l,message:e,type:m,leaving:!1,closeButton:i!=null?i:o}]),m!=="loading"&&setTimeout(()=>{n(g=>g.map(u=>u.id===l?{...u,leaving:!0}:u)),setTimeout(()=>{n(g=>g.filter(u=>u.id!==l))},300)},v),l}},[t,o]),z("div",{className:a("pointer-events-none fixed inset-0 z-9999 flex flex-col items-end justify-end gap-2 p-4 text-sm"),children:p.map(e=>z(y,{id:e.id,message:e.message,setToasts:n,type:e.type,icon:I(e.type),leaving:e.leaving,closeButton:e.closeButton},e.id))})}function s(t,o){if(T)return T(t,o)}s.success=(t,o)=>s(t,{...o,type:"success"});s.error=(t,o)=>s(t,{...o,type:"error"});s.warning=(t,o)=>s(t,{...o,type:"warning"});s.loading=(t,o)=>s(t,{...o,type:"loading"});s.promise=(t,o,p)=>{let n=Date.now().toString()+Math.random().toString(36).substring(2);return s(o.loading,{...p,type:"loading",id:n,duration:1/0}),t.then(e=>{let c=typeof o.success=="function"?o.success(e):o.success;s(c,{...p,type:"success",id:n})}).catch(e=>{let c=typeof o.error=="function"?o.error(e):o.error;s(c,{...p,type:"error",id:n})}),t};import{jsx as r,jsxs as V}from"react/jsx-runtime";var M=({className:t})=>r("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:a("size-5.5",t),height:24,width:24,children:r("path",{fillRule:"evenodd",d:"M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12Zm13.36-1.814a.75.75 0 1 0-1.22-.872l-3.236 4.53L9.53 12.22a.75.75 0 0 0-1.06 1.06l2.25 2.25a.75.75 0 0 0 1.14-.094l3.75-5.25Z",clipRule:"evenodd"})}),b=({className:t})=>r("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:a("size-5.5",t),height:24,width:24,children:r("path",{fillRule:"evenodd",d:"M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12ZM12 8.25a.75.75 0 0 1 .75.75v3.75a.75.75 0 0 1-1.5 0V9a.75.75 0 0 1 .75-.75Zm0 8.25a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Z",clipRule:"evenodd"})}),L=({className:t})=>r("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:a("size-5.5",t),height:24,width:24,children:r("path",{fillRule:"evenodd",d:"M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003ZM12 8.25a.75.75 0 0 1 .75.75v3.75a.75.75 0 0 1-1.5 0V9a.75.75 0 0 1 .75-.75Zm0 8.25a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Z",clipRule:"evenodd"})}),P=({className:t})=>V("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:a("size-5.5 animate-spin",t),children:[r("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),r("path",{d:"M12 6l0 -3"}),r("path",{d:"M16.25 7.75l2.15 -2.15"}),r("path",{d:"M18 12l3 0"}),r("path",{d:"M16.25 16.25l2.15 2.15"}),r("path",{d:"M12 18l0 3"}),r("path",{d:"M7.75 16.25l-2.15 2.15"}),r("path",{d:"M6 12l-3 0"}),r("path",{d:"M7.75 7.75l-2.15 -2.15"})]});export{B as ToastContainer,s as toast};
package/dist/style.css CHANGED
@@ -1 +1 @@
1
- @source '.';
1
+ @source '.';
package/package.json CHANGED
@@ -1,73 +1,73 @@
1
- {
2
- "name": "react-toast-msg",
3
- "version": "2.5.9",
4
- "description": "A lightweight, customizable React toast notification library with zero-config and fast setup.",
5
- "files": [
6
- "dist"
7
- ],
8
- "scripts": {
9
- "dev": "tsup --watch ./src",
10
- "prettier": "prettier --write src",
11
- "build": "pnpm build:ts && pnpm build:css",
12
- "build:ts": "tsup",
13
- "build:css": "pnpx @tailwindcss/cli -i ./src/style.css -o ./dist/style.css",
14
- "test": "vitest"
15
- },
16
- "main": "dist/index.js",
17
- "module": "dist/index.mjs",
18
- "types": "dist/index.d.ts",
19
- "exports": {
20
- ".": {
21
- "import": "./dist/index.mjs",
22
- "require": "./dist/index.js"
23
- },
24
- "./style.css": "./dist/style.css"
25
- },
26
- "keywords": [
27
- "react",
28
- "toast",
29
- "notification",
30
- "react-toast",
31
- "react-toastify",
32
- "snackbar",
33
- "react-toast-msg",
34
- "rtm",
35
- "toast-component"
36
- ],
37
- "author": "SudhuCodes",
38
- "license": "MIT",
39
- "repository": {
40
- "type": "git",
41
- "url": "https://github.com/sudhucodes/react-toast-msg.git"
42
- },
43
- "bugs": {
44
- "url": "https://github.com/sudhucodes/react-toast-msg/issues"
45
- },
46
- "homepage": "https://rtm.sudhucodes.com",
47
- "peerDependencies": {
48
- "react": "^18 || ^19",
49
- "react-dom": "^18 || ^19"
50
- },
51
- "devDependencies": {
52
- "@tailwindcss/cli": "^4.1.18",
53
- "@testing-library/dom": "^10.4.1",
54
- "@testing-library/jest-dom": "^6.9.1",
55
- "@testing-library/react": "^16.3.2",
56
- "@types/react": "^19.2.2",
57
- "@types/react-dom": "^19.2.2",
58
- "@vitejs/plugin-react": "^4.3.4",
59
- "jsdom": "^29.0.1",
60
- "prettier": "^3.6.2",
61
- "prettier-plugin-tailwindcss": "^0.7.2",
62
- "react": "^19.2.4",
63
- "react-dom": "^19.2.4",
64
- "tailwindcss": "^4.1.18",
65
- "tsup": "^8.5.0",
66
- "typescript": "^5.9.3",
67
- "vitest": "^4.1.0"
68
- },
69
- "dependencies": {
70
- "clsx": "^2.1.1",
71
- "tailwind-merge": "^3.4.0"
72
- }
1
+ {
2
+ "name": "react-toast-msg",
3
+ "version": "2.6.0",
4
+ "description": "A lightweight, customizable React toast notification library with zero-config and fast setup.",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "scripts": {
9
+ "dev": "tsup --watch ./src",
10
+ "prettier": "prettier --write src",
11
+ "build": "pnpm build:ts && pnpm build:css",
12
+ "build:ts": "tsup",
13
+ "build:css": "pnpx @tailwindcss/cli -i ./src/style.css -o ./dist/style.css",
14
+ "test": "vitest"
15
+ },
16
+ "main": "dist/index.js",
17
+ "module": "dist/index.mjs",
18
+ "types": "dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "import": "./dist/index.mjs",
22
+ "require": "./dist/index.js"
23
+ },
24
+ "./style.css": "./dist/style.css"
25
+ },
26
+ "keywords": [
27
+ "react",
28
+ "toast",
29
+ "notification",
30
+ "react-toast",
31
+ "react-toastify",
32
+ "snackbar",
33
+ "react-toast-msg",
34
+ "rtm",
35
+ "toast-component"
36
+ ],
37
+ "author": "SudhuCodes",
38
+ "license": "MIT",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/sudhucodes/react-toast-msg.git"
42
+ },
43
+ "bugs": {
44
+ "url": "https://github.com/sudhucodes/react-toast-msg/issues"
45
+ },
46
+ "homepage": "https://rtm.sudhucodes.com",
47
+ "peerDependencies": {
48
+ "react": "^18 || ^19",
49
+ "react-dom": "^18 || ^19"
50
+ },
51
+ "devDependencies": {
52
+ "@tailwindcss/cli": "^4.1.18",
53
+ "@testing-library/dom": "^10.4.1",
54
+ "@testing-library/jest-dom": "^6.9.1",
55
+ "@testing-library/react": "^16.3.2",
56
+ "@types/react": "^19.2.2",
57
+ "@types/react-dom": "^19.2.2",
58
+ "@vitejs/plugin-react": "^4.3.4",
59
+ "jsdom": "^29.0.1",
60
+ "prettier": "^3.6.2",
61
+ "prettier-plugin-tailwindcss": "^0.7.2",
62
+ "react": "^19.2.4",
63
+ "react-dom": "^19.2.4",
64
+ "tailwindcss": "^4.1.18",
65
+ "tsup": "^8.5.0",
66
+ "typescript": "^5.9.3",
67
+ "vitest": "^4.1.0"
68
+ },
69
+ "dependencies": {
70
+ "clsx": "^2.1.1",
71
+ "tailwind-merge": "^3.4.0"
72
+ }
73
73
  }