aboutsummaryrefslogtreecommitdiff
path: root/src/app/toast.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-02-08 22:36:25 +0100
committer0neGal <mail@0negal.com>2022-02-08 22:36:25 +0100
commitc1153f19e6323bbc76145d3defe0bca6b2b6088e (patch)
tree37614f44c05cdd4892b55db7c910450ba4e9fe75 /src/app/toast.js
parent3ee7928a2412b8041044afd8bd49b922c9941972 (diff)
downloadViper-c1153f19e6323bbc76145d3defe0bca6b2b6088e.tar.gz
Viper-c1153f19e6323bbc76145d3defe0bca6b2b6088e.zip
added toasts
No functional toasts yet, just the code for them, I'll add the actual toasts later...
Diffstat (limited to 'src/app/toast.js')
-rw-r--r--src/app/toast.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/app/toast.js b/src/app/toast.js
new file mode 100644
index 0000000..8d78e37
--- /dev/null
+++ b/src/app/toast.js
@@ -0,0 +1,58 @@
+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();
+ 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)
+ }
+}