customizable-toast-notification 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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ #Customizable Toast Notification Library
2
+ A highly customizable toast notification library for modern web applications, providing a simple way to create notifications with dynamic options.
3
+
4
+ #Features
5
+ Supports info, success, error, and warning notification types.
6
+ Customizable message, background color, text color, and duration.
7
+ Allows setting the position of the toast (e.g., top-right, bottom-left, etc.).
8
+ Includes an optional close button.
9
+ Built-in queuing mechanism to ensure notifications do not overlap.
10
+ Supports dynamic options like custom colors and messages.
11
+ Installation
12
+ To install this package, run:
13
+
14
+ #bash
15
+ Copy code
16
+ npm install customizable-toast-notification
17
+ Usage
18
+ Importing the Library
19
+ javascript
20
+ Copy code
21
+ import { createToast, setDefaultColors, setDefaultMessages } from 'customizable-toast-notification';
22
+ Creating a Toast Notification
23
+ You can create a toast notification by calling the createToast function with various options:
24
+
25
+ javascript
26
+ Copy code
27
+ createToast({
28
+ message: 'This is a custom message',
29
+ duration: 5000, // Display for 5 seconds
30
+ position: 'top-right', // Position on the screen
31
+ type: 'success', // Type of toast (info, success, warning, error)
32
+ backgroundColor: 'green', // Custom background color
33
+ textColor: 'white', // Custom text color
34
+ showCloseButton: true // Display the close button
35
+ });
36
+
37
+ #Available Options
38
+ Option Type Default Description
39
+ message String Depends on type The message to display in the toast.
40
+ duration Number 3000 The duration (in ms) to display the toast.
41
+ position String bottom-right Where to position the toast (top-right, bottom-left, etc.).
42
+ type String info Type of the toast (info, success, error, warning).
43
+ backgroundColor String Depends on type Custom background color for the toast.
44
+ textColor String white Custom text color.
45
+ showCloseButton Boolean false Whether to show a close button in the toast.
46
+ Customizing Default Colors and Messages
47
+ You can customize default colors and messages for different toast types:
48
+
49
+ javascript
50
+ Copy code
51
+ setDefaultColors({
52
+ success: 'green',
53
+ error: 'darkred'
54
+ });
55
+
56
+ setDefaultMessages({
57
+ success: 'Operation completed!',
58
+ error: 'Something went wrong!'
59
+ });
60
+ Example Usage in HTML
61
+ html
62
+ Copy code
63
+ <button id="showToast">Show Toast</button>
64
+
65
+ <script>
66
+ document.getElementById('showToast').addEventListener('click', () => {
67
+ createToast({
68
+ message: 'This is a custom toast message.',
69
+ duration: 4000,
70
+ position: 'top-right',
71
+ type: 'warning',
72
+ backgroundColor: 'red',
73
+ textColor: 'yellow',
74
+ showCloseButton: true
75
+ });
76
+ });
77
+ </script>
78
+
79
+ #License
80
+ This project is licensed under the MIT License.
81
+
@@ -0,0 +1,19 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});
2
+ /**
3
+ * @fileoverview A simple toast notification library for any JavaScript framework.
4
+ * @name Toast Notifications
5
+ * @author Priyanshu Patel
6
+ * @version 1.0.0
7
+ * @license MIT
8
+ * @depends None
9
+ * @description This library provides a simple way to create toast notifications.
10
+ * Author: Priyanshu Patel
11
+ * Email: priyanshu.alt191@gmail.com
12
+ * Created: July 31, 2024
13
+ * Description: A simple toast notification library for any JavaScript framework.
14
+ * Version: 1.0.0
15
+ * License: MIT
16
+ * Dependencies: None
17
+ */
18
+ let e={info:"blue",success:"green",error:"red",warning:"darkorange"},t={info:"This is an info message.",success:"Action completed successfully!",error:"An error occurred!",warning:"This is a warning message!"};const o=[];let s=!1;function n(){if(0===o.length||s)return;s=!0;const{message:r,duration:i,position:a,type:l,backgroundColor:c,textColor:d,showCloseButton:u}=o.shift(),p=r||t[l]||"This is a default message.",y=c||e[l]||"gray",g=d||("white"===y?"black":"white");let m=document.getElementById(`toast-container-${a}`);m||(m=document.createElement("div"),m.id=`toast-container-${a}`,m.style.position="fixed",m.style.zIndex="9999",a.includes("bottom")?m.style.bottom="10px":a.includes("top")&&(m.style.top="10px"),a.includes("right")?m.style.right="10px":a.includes("left")?m.style.left="10px":a.includes("center")&&(m.style.left="50%",m.style.transform="translateX(-50%)"),document.body.appendChild(m));const f=document.createElement("div");if(f.textContent=p,f.style.background=y,f.style.color=g,f.style.padding="10px 20px",f.style.marginTop="10px",f.style.borderRadius="5px",f.style.boxShadow="0 0 10px rgba(0, 0, 0, 0.1)",f.style.opacity="0",f.style.transition="opacity 0.5s",u){const e=document.createElement("button");e.textContent="×",e.style.marginLeft="10px",e.style.background="transparent",e.style.border="none",e.style.color=g,e.style.cursor="pointer",e.onclick=()=>{f.style.opacity="0",f.addEventListener("transitionend",(()=>{f.remove(),s=!1,n(),m.hasChildNodes()||m.remove()}))},f.appendChild(e)}m.appendChild(f),requestAnimationFrame((()=>{f.style.opacity="1"})),setTimeout((()=>{f.parentNode&&(f.style.opacity="0",f.addEventListener("transitionend",(()=>{f.remove(),s=!1,n(),m.hasChildNodes()||m.remove()})))}),i)}exports.createToast=function(e){const{message:t,duration:s=3e3,position:r="bottom-right",type:i="info",backgroundColor:a,textColor:l,showCloseButton:c=!1}=e;o.push({message:t,duration:s,position:r,type:i,backgroundColor:a,textColor:l,showCloseButton:c}),n()},exports.setDefaultColors=function(t){Object.assign(e,t)},exports.setDefaultMessages=function(e){Object.assign(t,e)};
19
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/index.js"],"sourcesContent":["\"use strict\";\r\n\r\n/**\r\n * @fileoverview A simple toast notification library for any JavaScript framework.\r\n * @name Toast Notifications\r\n * @author Priyanshu Patel\r\n * @version 1.0.0\r\n * @license MIT\r\n * @depends None\r\n * @description This library provides a simple way to create toast notifications.\r\n * Author: Priyanshu Patel\r\n * Email: priyanshu.alt191@gmail.com\r\n * Created: July 31, 2024\r\n * Description: A simple toast notification library for any JavaScript framework.\r\n * Version: 1.0.0\r\n * License: MIT\r\n * Dependencies: None\r\n */\r\n\r\n/**\r\n * Creates a toast notification.\r\n *\r\n * @param {Object} options - Options for the toast notification.\r\n * @param {string} [options.message] - The message to display in the toast. Defaults based on type if not provided.\r\n * @param {number} [options.duration=3000] - The duration the toast should be displayed, in milliseconds.\r\n * @param {string} [options.position='bottom-right'] - The position of the toast on the screen.\r\n * @param {string} [options.type='info'] - The type of the toast ('info', 'success', 'error', 'warning').\r\n * @param {string} [options.backgroundColor] - Custom background color for the toast notification.\r\n * @param {string} [options.textColor='white'] - Custom text color for the toast notification.\r\n * @param {string} [options.animationDuration='0.5s'] - Duration of the fade-in and fade-out animations.\r\n * @param {string} [options.animationEasing='ease'] - Easing function for the animations.\r\n * @param {boolean} [options.showCloseButton=false] - Whether to show a close button.\r\n * @return {void}\r\n */\r\n\r\n/** ########################################### Defaults ############################################ */\r\n\r\nlet defaultColors = {\r\n info: \"blue\",\r\n success: \"green\",\r\n error: \"red\",\r\n warning: \"darkorange\",\r\n};\r\n\r\nlet defaultMessages = {\r\n info: \"This is an info message.\",\r\n success: \"Action completed successfully!\",\r\n error: \"An error occurred!\",\r\n warning: \"This is a warning message!\",\r\n};\r\n\r\n// Queue to manage active toasts\r\nconst toastQueue = [];\r\nlet isToastShowing = false;\r\n\r\nfunction showNextToast() {\r\n if (toastQueue.length === 0 || isToastShowing) return;\r\n\r\n isToastShowing = true;\r\n const { message, duration, position, type, backgroundColor, textColor, showCloseButton } = toastQueue.shift();\r\n\r\n const finalMessage = message || defaultMessages[type] || \"This is a default message.\";\r\n const toastBackgroundColor = backgroundColor || defaultColors[type] || \"gray\"; // Use backgroundColor first\r\n const toastTextColor = textColor || (toastBackgroundColor === \"white\" ? \"black\" : \"white\");\r\n\r\n let toastContainer = document.getElementById(`toast-container-${position}`);\r\n if (!toastContainer) {\r\n toastContainer = document.createElement(\"div\");\r\n toastContainer.id = `toast-container-${position}`;\r\n toastContainer.style.position = \"fixed\";\r\n toastContainer.style.zIndex = \"9999\";\r\n\r\n if (position.includes(\"bottom\")) {\r\n toastContainer.style.bottom = \"10px\";\r\n } else if (position.includes(\"top\")) {\r\n toastContainer.style.top = \"10px\";\r\n }\r\n\r\n if (position.includes(\"right\")) {\r\n toastContainer.style.right = \"10px\";\r\n } else if (position.includes(\"left\")) {\r\n toastContainer.style.left = \"10px\";\r\n } else if (position.includes(\"center\")) {\r\n toastContainer.style.left = \"50%\";\r\n toastContainer.style.transform = \"translateX(-50%)\";\r\n }\r\n\r\n document.body.appendChild(toastContainer);\r\n }\r\n\r\n const toast = document.createElement(\"div\");\r\n toast.textContent = finalMessage;\r\n toast.style.background = toastBackgroundColor; // Use the determined background color\r\n toast.style.color = toastTextColor;\r\n toast.style.padding = \"10px 20px\";\r\n toast.style.marginTop = \"10px\";\r\n toast.style.borderRadius = \"5px\";\r\n toast.style.boxShadow = \"0 0 10px rgba(0, 0, 0, 0.1)\";\r\n toast.style.opacity = \"0\";\r\n toast.style.transition = \"opacity 0.5s\";\r\n\r\n // Close button\r\n if (showCloseButton) {\r\n const closeButton = document.createElement(\"button\");\r\n closeButton.textContent = \"×\";\r\n closeButton.style.marginLeft = \"10px\";\r\n closeButton.style.background = \"transparent\";\r\n closeButton.style.border = \"none\";\r\n closeButton.style.color = toastTextColor;\r\n closeButton.style.cursor = \"pointer\";\r\n\r\n closeButton.onclick = () => {\r\n toast.style.opacity = \"0\"; // Start fade out\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false;\r\n showNextToast(); // Show the next toast in the queue\r\n if (!toastContainer.hasChildNodes()) {\r\n toastContainer.remove();\r\n }\r\n });\r\n };\r\n\r\n toast.appendChild(closeButton);\r\n }\r\n\r\n toastContainer.appendChild(toast);\r\n\r\n requestAnimationFrame(() => {\r\n toast.style.opacity = \"1\";\r\n });\r\n\r\n setTimeout(() => {\r\n if (toast.parentNode) {\r\n toast.style.opacity = \"0\";\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false;\r\n showNextToast(); // Show the next toast in the queue\r\n if (!toastContainer.hasChildNodes()) {\r\n toastContainer.remove();\r\n }\r\n });\r\n }\r\n }, duration);\r\n}\r\n\r\nfunction createToast(options) {\r\n const {\r\n message,\r\n duration = 3000,\r\n position = \"bottom-right\",\r\n type = \"info\",\r\n backgroundColor,\r\n textColor,\r\n showCloseButton = false,\r\n } = options;\r\n\r\n toastQueue.push({\r\n message,\r\n duration,\r\n position,\r\n type,\r\n backgroundColor,\r\n textColor,\r\n showCloseButton,\r\n });\r\n \r\n showNextToast(); // Attempt to show the next toast\r\n}\r\n\r\nfunction setDefaultColors(newColors) {\r\n Object.assign(defaultColors, newColors);\r\n}\r\n\r\nfunction setDefaultMessages(newMessages) {\r\n Object.assign(defaultMessages, newMessages);\r\n}\r\n\r\nexport { createToast, setDefaultColors, setDefaultMessages };\r\n"],"names":["defaultColors","info","success","error","warning","defaultMessages","toastQueue","isToastShowing","showNextToast","length","message","duration","position","type","backgroundColor","textColor","showCloseButton","shift","finalMessage","toastBackgroundColor","toastTextColor","toastContainer","document","getElementById","createElement","id","style","zIndex","includes","bottom","top","right","left","transform","body","appendChild","toast","textContent","background","color","padding","marginTop","borderRadius","boxShadow","opacity","transition","closeButton","marginLeft","border","cursor","onclick","addEventListener","remove","hasChildNodes","requestAnimationFrame","setTimeout","parentNode","options","push","newColors","Object","assign","newMessages"],"mappings":";;;;;;;;;;;;;;;;;AAqCA,IAAIA,EAAgB,CAClBC,KAAM,OACNC,QAAS,QACTC,MAAO,MACPC,QAAS,cAGPC,EAAkB,CACpBJ,KAAM,2BACNC,QAAS,iCACTC,MAAO,qBACPC,QAAS,8BAIX,MAAME,EAAa,GACnB,IAAIC,GAAiB,EAErB,SAASC,IACP,GAA0B,IAAtBF,EAAWG,QAAgBF,EAAgB,OAE/CA,GAAiB,EACjB,MAAMG,QAAEA,EAAOC,SAAEA,EAAQC,SAAEA,EAAQC,KAAEA,EAAIC,gBAAEA,EAAeC,UAAEA,EAASC,gBAAEA,GAAoBV,EAAWW,QAEhGC,EAAeR,GAAWL,EAAgBQ,IAAS,6BACnDM,EAAuBL,GAAmBd,EAAca,IAAS,OACjEO,EAAiBL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AEDzB,EAAec,YAAYC,GAE3BkB,uBAAsB,KACpBlB,EAAMV,MAAMkB,QAAU,GAAG,IAG3BW,YAAW,KACLnB,EAAMoB,aACRpB,EAAMV,MAAMkB,QAAU,IACtBR,EAAMe,iBAAiB,iBAAiB,KACtCf,EAAMgB,SACN7C,GAAiB,EACjBC,IACKa,EAAegC,iBAClBhC,EAAe+B,QAChB,IAEJ,GACAzC,EACL,qBAEA,SAAqB8C,GACnB,MAAM/C,QACJA,EAAOC,SACPA,EAAW,IAAIC,SACfA,EAAW,eAAcC,KACzBA,EAAO,OAAMC,gBACbA,EAAeC,UACfA,EAASC,gBACTA,GAAkB,GAChByC,EAEJnD,EAAWoD,KAAK,CACdhD,UACAC,WACAC,WACAC,OACAC,kBACAC,YACAC,oBAGFR,GACF,2BAEA,SAA0BmD,GACxBC,OAAOC,OAAO7D,EAAe2D,EAC/B,6BAEA,SAA4BG,GAC1BF,OAAOC,OAAOxD,EAAiByD,EACjC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @fileoverview A simple toast notification library for any JavaScript framework.
3
+ * @name Toast Notifications
4
+ * @author Priyanshu Patel
5
+ * @version 1.0.0
6
+ * @license MIT
7
+ * @depends None
8
+ * @description This library provides a simple way to create toast notifications.
9
+ * Author: Priyanshu Patel
10
+ * Email: priyanshu.alt191@gmail.com
11
+ * Created: July 31, 2024
12
+ * Description: A simple toast notification library for any JavaScript framework.
13
+ * Version: 1.0.0
14
+ * License: MIT
15
+ * Dependencies: None
16
+ */
17
+ let e={info:"blue",success:"green",error:"red",warning:"darkorange"},t={info:"This is an info message.",success:"Action completed successfully!",error:"An error occurred!",warning:"This is a warning message!"};const o=[];let n=!1;function s(){if(0===o.length||n)return;n=!0;const{message:i,duration:r,position:l,type:a,backgroundColor:c,textColor:d,showCloseButton:u}=o.shift(),p=i||t[a]||"This is a default message.",y=c||e[a]||"gray",m=d||("white"===y?"black":"white");let g=document.getElementById(`toast-container-${l}`);g||(g=document.createElement("div"),g.id=`toast-container-${l}`,g.style.position="fixed",g.style.zIndex="9999",l.includes("bottom")?g.style.bottom="10px":l.includes("top")&&(g.style.top="10px"),l.includes("right")?g.style.right="10px":l.includes("left")?g.style.left="10px":l.includes("center")&&(g.style.left="50%",g.style.transform="translateX(-50%)"),document.body.appendChild(g));const h=document.createElement("div");if(h.textContent=p,h.style.background=y,h.style.color=m,h.style.padding="10px 20px",h.style.marginTop="10px",h.style.borderRadius="5px",h.style.boxShadow="0 0 10px rgba(0, 0, 0, 0.1)",h.style.opacity="0",h.style.transition="opacity 0.5s",u){const e=document.createElement("button");e.textContent="×",e.style.marginLeft="10px",e.style.background="transparent",e.style.border="none",e.style.color=m,e.style.cursor="pointer",e.onclick=()=>{h.style.opacity="0",h.addEventListener("transitionend",(()=>{h.remove(),n=!1,s(),g.hasChildNodes()||g.remove()}))},h.appendChild(e)}g.appendChild(h),requestAnimationFrame((()=>{h.style.opacity="1"})),setTimeout((()=>{h.parentNode&&(h.style.opacity="0",h.addEventListener("transitionend",(()=>{h.remove(),n=!1,s(),g.hasChildNodes()||g.remove()})))}),r)}function i(e){const{message:t,duration:n=3e3,position:i="bottom-right",type:r="info",backgroundColor:l,textColor:a,showCloseButton:c=!1}=e;o.push({message:t,duration:n,position:i,type:r,backgroundColor:l,textColor:a,showCloseButton:c}),s()}function r(t){Object.assign(e,t)}function l(e){Object.assign(t,e)}export{i as createToast,r as setDefaultColors,l as setDefaultMessages};
18
+ //# sourceMappingURL=index.esm.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.mjs","sources":["../src/index.js"],"sourcesContent":["\"use strict\";\r\n\r\n/**\r\n * @fileoverview A simple toast notification library for any JavaScript framework.\r\n * @name Toast Notifications\r\n * @author Priyanshu Patel\r\n * @version 1.0.0\r\n * @license MIT\r\n * @depends None\r\n * @description This library provides a simple way to create toast notifications.\r\n * Author: Priyanshu Patel\r\n * Email: priyanshu.alt191@gmail.com\r\n * Created: July 31, 2024\r\n * Description: A simple toast notification library for any JavaScript framework.\r\n * Version: 1.0.0\r\n * License: MIT\r\n * Dependencies: None\r\n */\r\n\r\n/**\r\n * Creates a toast notification.\r\n *\r\n * @param {Object} options - Options for the toast notification.\r\n * @param {string} [options.message] - The message to display in the toast. Defaults based on type if not provided.\r\n * @param {number} [options.duration=3000] - The duration the toast should be displayed, in milliseconds.\r\n * @param {string} [options.position='bottom-right'] - The position of the toast on the screen.\r\n * @param {string} [options.type='info'] - The type of the toast ('info', 'success', 'error', 'warning').\r\n * @param {string} [options.backgroundColor] - Custom background color for the toast notification.\r\n * @param {string} [options.textColor='white'] - Custom text color for the toast notification.\r\n * @param {string} [options.animationDuration='0.5s'] - Duration of the fade-in and fade-out animations.\r\n * @param {string} [options.animationEasing='ease'] - Easing function for the animations.\r\n * @param {boolean} [options.showCloseButton=false] - Whether to show a close button.\r\n * @return {void}\r\n */\r\n\r\n/** ########################################### Defaults ############################################ */\r\n\r\nlet defaultColors = {\r\n info: \"blue\",\r\n success: \"green\",\r\n error: \"red\",\r\n warning: \"darkorange\",\r\n};\r\n\r\nlet defaultMessages = {\r\n info: \"This is an info message.\",\r\n success: \"Action completed successfully!\",\r\n error: \"An error occurred!\",\r\n warning: \"This is a warning message!\",\r\n};\r\n\r\n// Queue to manage active toasts\r\nconst toastQueue = [];\r\nlet isToastShowing = false;\r\n\r\nfunction showNextToast() {\r\n if (toastQueue.length === 0 || isToastShowing) return;\r\n\r\n isToastShowing = true;\r\n const { message, duration, position, type, backgroundColor, textColor, showCloseButton } = toastQueue.shift();\r\n\r\n const finalMessage = message || defaultMessages[type] || \"This is a default message.\";\r\n const toastBackgroundColor = backgroundColor || defaultColors[type] || \"gray\"; // Use backgroundColor first\r\n const toastTextColor = textColor || (toastBackgroundColor === \"white\" ? \"black\" : \"white\");\r\n\r\n let toastContainer = document.getElementById(`toast-container-${position}`);\r\n if (!toastContainer) {\r\n toastContainer = document.createElement(\"div\");\r\n toastContainer.id = `toast-container-${position}`;\r\n toastContainer.style.position = \"fixed\";\r\n toastContainer.style.zIndex = \"9999\";\r\n\r\n if (position.includes(\"bottom\")) {\r\n toastContainer.style.bottom = \"10px\";\r\n } else if (position.includes(\"top\")) {\r\n toastContainer.style.top = \"10px\";\r\n }\r\n\r\n if (position.includes(\"right\")) {\r\n toastContainer.style.right = \"10px\";\r\n } else if (position.includes(\"left\")) {\r\n toastContainer.style.left = \"10px\";\r\n } else if (position.includes(\"center\")) {\r\n toastContainer.style.left = \"50%\";\r\n toastContainer.style.transform = \"translateX(-50%)\";\r\n }\r\n\r\n document.body.appendChild(toastContainer);\r\n }\r\n\r\n const toast = document.createElement(\"div\");\r\n toast.textContent = finalMessage;\r\n toast.style.background = toastBackgroundColor; // Use the determined background color\r\n toast.style.color = toastTextColor;\r\n toast.style.padding = \"10px 20px\";\r\n toast.style.marginTop = \"10px\";\r\n toast.style.borderRadius = \"5px\";\r\n toast.style.boxShadow = \"0 0 10px rgba(0, 0, 0, 0.1)\";\r\n toast.style.opacity = \"0\";\r\n toast.style.transition = \"opacity 0.5s\";\r\n\r\n // Close button\r\n if (showCloseButton) {\r\n const closeButton = document.createElement(\"button\");\r\n closeButton.textContent = \"×\";\r\n closeButton.style.marginLeft = \"10px\";\r\n closeButton.style.background = \"transparent\";\r\n closeButton.style.border = \"none\";\r\n closeButton.style.color = toastTextColor;\r\n closeButton.style.cursor = \"pointer\";\r\n\r\n closeButton.onclick = () => {\r\n toast.style.opacity = \"0\"; // Start fade out\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false;\r\n showNextToast(); // Show the next toast in the queue\r\n if (!toastContainer.hasChildNodes()) {\r\n toastContainer.remove();\r\n }\r\n });\r\n };\r\n\r\n toast.appendChild(closeButton);\r\n }\r\n\r\n toastContainer.appendChild(toast);\r\n\r\n requestAnimationFrame(() => {\r\n toast.style.opacity = \"1\";\r\n });\r\n\r\n setTimeout(() => {\r\n if (toast.parentNode) {\r\n toast.style.opacity = \"0\";\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false;\r\n showNextToast(); // Show the next toast in the queue\r\n if (!toastContainer.hasChildNodes()) {\r\n toastContainer.remove();\r\n }\r\n });\r\n }\r\n }, duration);\r\n}\r\n\r\nfunction createToast(options) {\r\n const {\r\n message,\r\n duration = 3000,\r\n position = \"bottom-right\",\r\n type = \"info\",\r\n backgroundColor,\r\n textColor,\r\n showCloseButton = false,\r\n } = options;\r\n\r\n toastQueue.push({\r\n message,\r\n duration,\r\n position,\r\n type,\r\n backgroundColor,\r\n textColor,\r\n showCloseButton,\r\n });\r\n \r\n showNextToast(); // Attempt to show the next toast\r\n}\r\n\r\nfunction setDefaultColors(newColors) {\r\n Object.assign(defaultColors, newColors);\r\n}\r\n\r\nfunction setDefaultMessages(newMessages) {\r\n Object.assign(defaultMessages, newMessages);\r\n}\r\n\r\nexport { createToast, setDefaultColors, setDefaultMessages };\r\n"],"names":["defaultColors","info","success","error","warning","defaultMessages","toastQueue","isToastShowing","showNextToast","length","message","duration","position","type","backgroundColor","textColor","showCloseButton","shift","finalMessage","toastBackgroundColor","toastTextColor","toastContainer","document","getElementById","createElement","id","style","zIndex","includes","bottom","top","right","left","transform","body","appendChild","toast","textContent","background","color","padding","marginTop","borderRadius","boxShadow","opacity","transition","closeButton","marginLeft","border","cursor","onclick","addEventListener","remove","hasChildNodes","requestAnimationFrame","setTimeout","parentNode","createToast","options","push","setDefaultColors","newColors","Object","assign","setDefaultMessages","newMessages"],"mappings":";;;;;;;;;;;;;;;;AAqCA,IAAIA,EAAgB,CAClBC,KAAM,OACNC,QAAS,QACTC,MAAO,MACPC,QAAS,cAGPC,EAAkB,CACpBJ,KAAM,2BACNC,QAAS,iCACTC,MAAO,qBACPC,QAAS,8BAIX,MAAME,EAAa,GACnB,IAAIC,GAAiB,EAErB,SAASC,IACP,GAA0B,IAAtBF,EAAWG,QAAgBF,EAAgB,OAE/CA,GAAiB,EACjB,MAAMG,QAAEA,EAAOC,SAAEA,EAAQC,SAA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ACpBd,EAAMV,MAAMkB,QAAU,IACtBR,EAAMe,iBAAiB,iBAAiB,KACtCf,EAAMgB,SACN7C,GAAiB,EACjBC,IACKa,EAAegC,iBAClBhC,EAAe+B,QAChB,GACD,EAGJhB,EAAMD,YAAYW,EACnB,CAEDzB,EAAec,YAAYC,GAE3BkB,uBAAsB,KACpBlB,EAAMV,MAAMkB,QAAU,GAAG,IAG3BW,YAAW,KACLnB,EAAMoB,aACRpB,EAAMV,MAAMkB,QAAU,IACtBR,EAAMe,iBAAiB,iBAAiB,KACtCf,EAAMgB,SACN7C,GAAiB,EACjBC,IACKa,EAAegC,iBAClBhC,EAAe+B,QAChB,IAEJ,GACAzC,EACL,CAEA,SAAS8C,EAAYC,GACnB,MAAMhD,QACJA,EAAOC,SACPA,EAAW,IAAIC,SACfA,EAAW,eAAcC,KACzBA,EAAO,OAAMC,gBACbA,EAAeC,UACfA,EAASC,gBACTA,GAAkB,GAChB0C,EAEJpD,EAAWqD,KAAK,CACdjD,UACAC,WACAC,WACAC,OACAC,kBACAC,YACAC,oBAGFR,GACF,CAEA,SAASoD,EAAiBC,GACxBC,OAAOC,OAAO/D,EAAe6D,EAC/B,CAEA,SAASG,EAAmBC,GAC1BH,OAAOC,OAAO1D,EAAiB4D,EACjC"}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "customizable-toast-notification",
3
+ "version": "1.0.0",
4
+ "description": "A highly customizable toast notification library for modern web applications.",
5
+ "main": "dist/index.cjs.js",
6
+ "module": "dist/index.esm.mjs",
7
+ "scripts": {
8
+ "build": "rollup -c",
9
+ "test": "echo \"Error: no test specified\" && exit 1"
10
+ },
11
+ "keywords": [
12
+ "toast",
13
+ "notification",
14
+ "customizable",
15
+ "UI",
16
+ "library",
17
+ "JavaScript",
18
+ "ESM",
19
+ "CJS",
20
+ "best-toast-notification",
21
+ "best-library",
22
+ "priyanshu",
23
+ "priyanshu-patel",
24
+ "toast-notification",
25
+ "npm-library",
26
+ "toast-library",
27
+ "toast",
28
+ "notification",
29
+ "npm",
30
+ "npm-package",
31
+ "javascript",
32
+ "javascript-library"
33
+ ],
34
+ "author": "Priyanshu Patel",
35
+ "license": "MIT",
36
+ "files": [
37
+ "dist"
38
+ ],
39
+ "devDependencies": {
40
+ "@rollup/plugin-commonjs": "^26.0.1",
41
+ "@rollup/plugin-node-resolve": "^15.2.3",
42
+ "@rollup/plugin-terser": "^0.4.4",
43
+ "rollup": "^2.78.0",
44
+ "rollup-plugin-size-snapshot": "^0.12.0",
45
+ "rollup-plugin-visualizer": "^5.12.0"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://github.com/sammy-cool/customizable-toast-notification"
50
+ }
51
+ }