toastify-pro 1.0.1 → 1.0.3

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,132 +1,157 @@
1
- class ToastifyPro {
2
- constructor(options = {}) {
3
- this.defaultOptions = {
4
- position: options.position || "bottom-center", // top-left, top-right, bottom-left, bottom-right, top-center, bottom-center
5
- timeout: options.timeout || 3000,
6
- allowClose: options.allowClose !== false, // default true
7
- maxLength: options.maxLength || 100,
8
- };
9
-
10
- // create container only once
11
- const existing = document.querySelector(
12
- `.toastify-pro-container.${this.defaultOptions.position}`
13
- );
14
- if (existing) {
15
- this.container = existing;
16
- } else {
17
- this.container = document.createElement("div");
18
- this.container.className = `toastify-pro-container ${this.defaultOptions.position}`;
19
- document.body.appendChild(this.container);
20
- }
21
-
22
- this.injectStyles();
23
- }
1
+ class ToastifyPro {
2
+ constructor(options = {}) {
3
+ this.defaultOptions = {
4
+ position: options.position || "bottom-center", // top-left, top-right, bottom-left, bottom-right, top-center, bottom-center
5
+ timeout: options.timeout || 3000,
6
+ allowClose: options.allowClose !== false, // default true
7
+ maxLength: options.maxLength || 100,
8
+ };
24
9
 
25
- injectStyles() {
26
- if (document.getElementById("toastify-pro-styles")) return; // load once
27
- const style = document.createElement("style");
28
- style.id = "toastify-pro-styles";
29
- style.textContent = `
30
- .toastify-pro-container {
31
- position: fixed;
32
- z-index: 9999;
33
- display: flex;
34
- flex-direction: column;
35
- gap: 10px;
36
- pointer-events: none;
37
- }
38
- .toastify-pro-container.top-left { top: 20px; left: 20px; align-items: flex-start; }
39
- .toastify-pro-container.top-right { top: 20px; right: 20px; align-items: flex-end; }
40
- .toastify-pro-container.bottom-left { bottom: 20px; left: 20px; align-items: flex-start; }
41
- .toastify-pro-container.bottom-right { bottom: 20px; right: 20px; align-items: flex-end; }
42
- .toastify-pro-container.top-center { top: 20px; left: 50%; transform: translateX(-50%); }
43
- .toastify-pro-container.bottom-center { bottom: 150px; left: 50%; transform: translateX(-50%); }
44
-
45
- .toastify-pro {
46
- min-width: 220px;
47
- max-width: 320px;
48
- padding: 12px 18px;
49
- border-radius: 20px;
50
- font-size: 14px;
51
- font-family: sans-serif;
52
- color: white;
53
- opacity: 0;
54
- transform: translateY(20px);
55
- transition: all 0.3s ease;
56
- pointer-events: auto;
57
- position: relative;
58
- }
59
- .toastify-pro.show { opacity: 1; transform: translateY(0); }
60
- .toastify-pro.success { background: rgba(76, 175, 80, 0.9); }
61
- .toastify-pro.error { background: rgba(244, 67, 54, 0.9); }
62
- .toastify-pro.info { background: rgba(33, 150, 243, 0.9); }
63
- .toastify-pro.warning { background: rgba(255, 152, 0, 0.9); }
64
- .toastify-pro.dark { background: rgba(0,0,0,0.85); }
65
- .toastify-pro.light { background: rgba(255,255,255,0.9); color: #000; }
66
-
67
- .toastify-pro .close-btn {
68
- position: absolute;
69
- right: 20px;
70
- top: 8px;
71
- cursor: pointer;
72
- font-size: 20px;
73
- color: inherit;
74
- opacity: 0.8;
75
- }
76
- .toastify-pro .close-btn:hover { opacity: 1; }
77
- `;
78
- document.head.appendChild(style);
10
+ // create container only once
11
+ const existing = document.querySelector(
12
+ `.toastify-pro-container.${this.defaultOptions.position}`
13
+ );
14
+ if (existing) {
15
+ this.container = existing;
16
+ } else {
17
+ this.container = document.createElement("div");
18
+ this.container.className = `toastify-pro-container ${this.defaultOptions.position}`;
19
+ document.body.appendChild(this.container);
79
20
  }
80
21
 
81
- show(message, type = "dark", opts = {}) {
82
- const options = { ...this.defaultOptions, ...opts };
83
-
84
- const toast = document.createElement("div");
85
- toast.className = `toastify-pro ${type}`;
86
- toast.innerText = message.substring(0, options.maxLength);
87
-
88
- if (options.allowClose) {
89
- const closeBtn = document.createElement("span");
90
- closeBtn.className = "close-btn";
91
- closeBtn.innerHTML = "×";
92
- closeBtn.onclick = () => this.removeToast(toast);
93
- toast.appendChild(closeBtn);
94
- }
95
-
96
- this.container.appendChild(toast);
97
-
98
- // show animation
99
- setTimeout(() => toast.classList.add("show"), 50);
22
+ this.injectStyles();
23
+ }
100
24
 
101
- // auto remove
102
- if (options.timeout > 0) {
103
- setTimeout(() => this.removeToast(toast), options.timeout);
104
- }
25
+ injectStyles() {
26
+ if (document.getElementById("toastify-pro-styles")) return; // load once
27
+ const style = document.createElement("style");
28
+ style.id = "toastify-pro-styles";
29
+ style.textContent = `
30
+ .toastify-pro-container {
31
+ position: fixed;
32
+ z-index: 9999;
33
+ display: flex;
34
+ flex-direction: column;
35
+ gap: 10px;
36
+ pointer-events: none;
105
37
  }
38
+ .toastify-pro-container.top-left { top: 20px; left: 20px; align-items: flex-start; }
39
+ .toastify-pro-container.top-right { top: 20px; right: 20px; align-items: flex-end; }
40
+ .toastify-pro-container.bottom-left { bottom: 20px; left: 20px; align-items: flex-start; }
41
+ .toastify-pro-container.bottom-right { bottom: 20px; right: 20px; align-items: flex-end; }
42
+ .toastify-pro-container.top-center { top: 20px; left: 50%; transform: translateX(-50%); }
43
+ .toastify-pro-container.bottom-center { bottom: 150px; left: 50%; transform: translateX(-50%); }
106
44
 
107
- removeToast(toast) {
108
- toast.classList.remove("show");
109
- setTimeout(() => toast.remove(), 300);
45
+ .toastify-pro {
46
+ min-width: 220px;
47
+ max-width: 320px;
48
+ padding: 12px 18px;
49
+ border-radius: 20px;
50
+ font-size: 14px;
51
+ font-family: sans-serif;
52
+ color: white;
53
+ opacity: 0;
54
+ transform: translateY(20px);
55
+ transition: all 0.3s ease;
56
+ pointer-events: auto;
57
+ position: relative;
58
+ display: flex;
59
+ align-items: center;
60
+ justify-content: space-between;
61
+ gap: 12px;
110
62
  }
63
+ .toastify-pro.show { opacity: 1; transform: translateY(0); }
64
+ .toastify-pro.success { background: rgba(76, 175, 80, 0.9); }
65
+ .toastify-pro.error { background: rgba(244, 67, 54, 0.9); }
66
+ .toastify-pro.info { background: rgba(33, 150, 243, 0.9); }
67
+ .toastify-pro.warning { background: rgba(255, 152, 0, 0.9); }
68
+ .toastify-pro.dark { background: rgba(0,0,0,0.85); }
69
+ .toastify-pro.light { background: rgba(255,255,255,0.9); color: #000; }
111
70
 
112
- success(msg, opts) {
113
- this.show(msg, "success", opts);
71
+ .toastify-pro .toast-content {
72
+ flex: 1;
73
+ padding-right: 8px;
74
+ line-height: 1.4;
114
75
  }
115
- error(msg, opts) {
116
- this.show(msg, "error", opts);
76
+
77
+ .toastify-pro .close-btn {
78
+ cursor: pointer;
79
+ font-size: 18px;
80
+ color: inherit;
81
+ opacity: 0.8;
82
+ padding: 2px 4px;
83
+ border-radius: 3px;
84
+ transition: opacity 0.2s ease, background-color 0.2s ease;
85
+ flex-shrink: 0;
86
+ min-width: 20px;
87
+ text-align: center;
88
+ line-height: 1;
117
89
  }
118
- info(msg, opts) {
119
- this.show(msg, "info", opts);
90
+ .toastify-pro .close-btn:hover {
91
+ opacity: 1;
92
+ background-color: rgba(0,0,0,0.1);
120
93
  }
121
- warning(msg, opts) {
122
- this.show(msg, "warning", opts);
94
+ .toastify-pro.light .close-btn:hover {
95
+ background-color: rgba(0,0,0,0.05);
123
96
  }
124
- dark(msg, opts) {
125
- this.show(msg, "dark", opts);
97
+ `;
98
+ document.head.appendChild(style);
99
+ }
100
+
101
+ show(message, type = "dark", opts = {}) {
102
+ const options = { ...this.defaultOptions, ...opts };
103
+
104
+ const toast = document.createElement("div");
105
+ toast.className = `toastify-pro ${type}`;
106
+
107
+ // Create content wrapper for the message
108
+ const contentWrapper = document.createElement("div");
109
+ contentWrapper.className = "toast-content";
110
+ contentWrapper.textContent = message.substring(0, options.maxLength);
111
+ toast.appendChild(contentWrapper);
112
+
113
+ if (options.allowClose) {
114
+ const closeBtn = document.createElement("span");
115
+ closeBtn.className = "close-btn";
116
+ closeBtn.innerHTML = "×";
117
+ closeBtn.onclick = () => this.removeToast(toast);
118
+ toast.appendChild(closeBtn);
126
119
  }
127
- light(msg, opts) {
128
- this.show(msg, "light", opts);
120
+
121
+ this.container.appendChild(toast);
122
+
123
+ // show animation
124
+ setTimeout(() => toast.classList.add("show"), 50);
125
+
126
+ // auto remove
127
+ if (options.timeout > 0) {
128
+ setTimeout(() => this.removeToast(toast), options.timeout);
129
129
  }
130
130
  }
131
131
 
132
+ removeToast(toast) {
133
+ toast.classList.remove("show");
134
+ setTimeout(() => toast.remove(), 300);
135
+ }
136
+
137
+ success(msg, opts) {
138
+ this.show(msg, "success", opts);
139
+ }
140
+ error(msg, opts) {
141
+ this.show(msg, "error", opts);
142
+ }
143
+ info(msg, opts) {
144
+ this.show(msg, "info", opts);
145
+ }
146
+ warning(msg, opts) {
147
+ this.show(msg, "warning", opts);
148
+ }
149
+ dark(msg, opts) {
150
+ this.show(msg, "dark", opts);
151
+ }
152
+ light(msg, opts) {
153
+ this.show(msg, "light", opts);
154
+ }
155
+ }
156
+
132
157
  export default ToastifyPro;