Created
October 4, 2023 13:27
-
-
Save johnie/45143c2ad7890339db3fcc359e988648 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const showErrorToast = (message: string) => { | |
const toastTemplate = document.getElementById('toast-template') as HTMLTemplateElement; | |
if (!toastTemplate) return; | |
const toastClone = document.importNode(toastTemplate.content, true); | |
document.body.appendChild(toastClone); | |
const newToast = document.body.lastElementChild as HTMLElement; | |
if (!newToast) return; | |
const messageElement = newToast.querySelector('.toast'); | |
if (!messageElement) return; | |
messageElement.textContent = message; | |
setTimeout(() => { | |
newToast.classList.add('fade-in'); | |
}, 10); | |
setTimeout(() => { | |
newToast.remove(); | |
}, 3000); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment