MCPcopy Create free account
hub / github.com/Yorick-Ryu/deep-share / showToastNotification

Function showToastNotification

scripts/notifications.js:189–253  ·  view source on GitHub ↗
(message, type = 'success', duration = 3000)

Source from the content-addressed store, hash-verified

187
188 // --- Core Function ---
189 function showToastNotification(message, type = 'success', duration = 3000) {
190 injectStyles();
191 const container = getContainer();
192 const id = ++toastIdCounter;
193
194 const toast = document.createElement('div');
195 toast.className = `ds-toast ds-toast--${type}`;
196 toast.setAttribute('role', 'alert');
197
198 // Icon
199 const iconDiv = document.createElement('div');
200 iconDiv.className = 'ds-toast__icon';
201 iconDiv.innerHTML = icons[type] || icons.info;
202
203 // Content
204 const contentDiv = document.createElement('div');
205 contentDiv.className = 'ds-toast__content';
206
207 if (message && typeof message === 'object') {
208 contentDiv.textContent = message.text || '';
209 if (message.linkText && message.linkHref) {
210 contentDiv.appendChild(document.createTextNode(' '));
211 const link = document.createElement('a');
212 link.className = 'ds-toast__link';
213 link.textContent = message.linkText;
214 link.href = message.linkHref;
215 link.target = '_blank';
216 link.rel = 'noopener noreferrer';
217 contentDiv.appendChild(link);
218 }
219 } else {
220 // Strip HTML tags to show only plain text in toasts (avoid raw HTML showing as text)
221 const tempDiv = document.createElement('div');
222 tempDiv.innerHTML = message;
223 contentDiv.textContent = tempDiv.textContent || tempDiv.innerText || message;
224 }
225
226 // Close Button
227 const closeDiv = document.createElement('div');
228 closeDiv.className = 'ds-toast__close';
229 closeDiv.innerHTML = icons.close;
230 closeDiv.onclick = (e) => {
231 e.stopPropagation();
232 dismissToastNotification(id);
233 };
234
235 toast.appendChild(iconDiv);
236 toast.appendChild(contentDiv);
237 toast.appendChild(closeDiv);
238
239 container.appendChild(toast);
240
241 // Auto dismiss
242 let timeoutId;
243 if (duration > 0 && type !== 'loading') {
244 timeoutId = setTimeout(() => {
245 dismissToastNotification(id);
246 }, duration);

Callers

nothing calls this directly

Calls 6

injectStylesFunction · 0.85
getContainerFunction · 0.85
dismissToastNotificationFunction · 0.85
setAttributeMethod · 0.45
appendChildMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected