commit 1a527966961585da9c9aef360a01842dde3e780a
parent 7897a84026f4699724fa5b0b7048753933bbea6d
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Fri, 30 Aug 2024 17:56:13 -0700
Add warning function to ui library
This creates a warning element.
Diffstat:
2 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/files/icons/warning-outline.svg b/files/icons/warning-outline.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512"><path d="M85.57,446.25H426.43a32,32,0,0,0,28.17-47.17L284.18,82.58c-12.09-22.44-44.27-22.44-56.36,0L57.4,399.08A32,32,0,0,0,85.57,446.25Z" style="fill:none;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/><path d="M250.26,195.39l5.74,122,5.73-121.95a5.74,5.74,0,0,0-5.79-6h0A5.74,5.74,0,0,0,250.26,195.39Z" style="fill:none;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/><path d="M256,397.25a20,20,0,1,1,20-20A20,20,0,0,1,256,397.25Z"/></svg>
+\ No newline at end of file
diff --git a/files/lib/ui.js b/files/lib/ui.js
@@ -72,3 +72,28 @@ function toggle_setup_button(a, b) {
}
}, false)
}
+
+export function warning(content) {
+ let warning = document.createElement("span")
+ warning.classList.add("warning")
+
+ let icon = warning.appendChild(
+ document.createElement("img")
+ )
+ icon.classList.add("icon")
+ icon.setAttribute("src", "/icons/warning-outline.svg")
+
+ if (typeof content === "string") {
+ let s = content
+ content = document.createElement("p")
+ content.appendChild(
+ document.createTextNode(s)
+ )
+ }
+
+ // appendChild can make sure it's correct
+ warning.appendChild(content)
+ content.classList.add("content")
+
+ return warning
+}