diff options
author | 0neGal <mail@0negal.com> | 2022-02-13 23:32:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-13 23:32:44 +0100 |
commit | 9f2f77558238c28ceb8ff4fca2096602671779e5 (patch) | |
tree | c15586b60de31de094c2f811832ef9ad6df2f50a /src/app/toast.js | |
parent | 057b60f4843798441ad441370381b87299d5ad7f (diff) | |
parent | b2f826a39e8ecf77f85ca56906758edaa3f1dac3 (diff) | |
download | Viper-9f2f77558238c28ceb8ff4fca2096602671779e5.tar.gz Viper-9f2f77558238c28ceb8ff4fca2096602671779e5.zip |
Merge branch 'main' into enabledmods
Diffstat (limited to 'src/app/toast.js')
-rw-r--r-- | src/app/toast.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/app/toast.js b/src/app/toast.js new file mode 100644 index 0000000..2a8555e --- /dev/null +++ b/src/app/toast.js @@ -0,0 +1,59 @@ +function Toast(properties) { + let toast = { + fg: "#000000", + bg: "#FFFFFF", + timeout: 3000, + title: "Untitled Toast", + description: "No description provided for toast", + ...properties + } + + switch(toast.scheme) { + case "error": + toast.fg = "#FFFFFF"; + toast.bg = "var(--red)"; + break + case "success": + toast.fg = "#FFFFFF"; + toast.bg = "#60D394"; + break + case "warning": + toast.fg = "#FFFFFF"; + toast.bg = "#FF9B85"; + break + } + + + let id = Date.now(); + if (document.getElementById(id)) {id = id + 1} + let el = document.createElement("div"); + + el.classList.add("toast"); + + el.style.color = toast.fg; + el.style.background = toast.bg; + + el.id = id; + el.setAttribute("onclick", `dismissToast(${id})`); + + el.innerHTML = ` + <div class="title">${toast.title}</div> + <div class="description">${toast.description}</div> + ` + + toasts.appendChild(el); + + setTimeout(() => { + dismissToast(id); + }, toast.timeout) +} + +function dismissToast(id) { + id = document.getElementById(id); + if (id) { + id.classList.add("hidden"); + setTimeout(() => { + id.remove(); + }, 500) + } +} |