Skip to content

Instantly share code, notes, and snippets.

@fredriccliver
Created November 20, 2020 08:41
Show Gist options
  • Save fredriccliver/ccde29cba4574db571839a75cd7e520f to your computer and use it in GitHub Desktop.
Save fredriccliver/ccde29cba4574db571839a75cd7e520f to your computer and use it in GitHub Desktop.
export class UI {
toastTemplate?: HTMLTemplateElement
constructor(templateSelector: string) {
this.toastTemplate = document.querySelector<HTMLTemplateElement>(
templateSelector
)!
}
showToast() {
if (!!this.toastTemplate) {
let div = document.createElement('div')
div.innerHTML = this.toastTemplate.innerHTML
const appendedChild = document.body.appendChild(div)
setTimeout(() => {
console.log(`time is done`)
this.hideToast(appendedChild)
}, 1000)
}
}
hideToast(toast: HTMLElement) {
toast.remove()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment