aboutsummaryrefslogtreecommitdiff
path: root/client-web/source/helper.ts
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2022-09-09 17:49:39 +0200
committermetamuffin <metamuffin@disroot.org>2022-09-09 17:49:39 +0200
commit3a657c2f6d4cc9f82c993a8d390c8a84ab38bcb4 (patch)
tree731c854754d1408d189552da79bd81d79d11183f /client-web/source/helper.ts
parentb0c6062607b037ba1a6e388e5c23746bdd8dbdcf (diff)
downloadkeks-meet-3a657c2f6d4cc9f82c993a8d390c8a84ab38bcb4.tar
keks-meet-3a657c2f6d4cc9f82c993a8d390c8a84ab38bcb4.tar.bz2
keks-meet-3a657c2f6d4cc9f82c993a8d390c8a84ab38bcb4.tar.zst
chat!
Diffstat (limited to 'client-web/source/helper.ts')
-rw-r--r--client-web/source/helper.ts18
1 files changed, 15 insertions, 3 deletions
diff --git a/client-web/source/helper.ts b/client-web/source/helper.ts
index 4f97ebb..8dafd29 100644
--- a/client-web/source/helper.ts
+++ b/client-web/source/helper.ts
@@ -6,14 +6,24 @@ export function hex_id(len = 8): string {
}
const elem = (s: string) => document.createElement(s)
-const elem_with_content = (s: string) => (c: string) => {
+
+interface Opts { class?: string[] | string, id?: string }
+
+function apply_opts(e: HTMLElement, o: Opts | undefined) {
+ if (!o) return
+ if (o.id) e.id = o.id
+ if (typeof o?.class == "string") e.classList.add(o.class)
+ if (typeof o?.class == "object") e.classList.add(...o.class)
+}
+const elem_with_content = (s: string) => (c: string, opts?: Opts) => {
const e = elem(s)
+ apply_opts(e, opts)
e.textContent = c
return e
}
-const elem_with_children = (s: string) => (opts: { class?: string[] }, ...cs: (HTMLElement | string)[]) => {
+const elem_with_children = (s: string) => (opts?: Opts, ...cs: (HTMLElement | string)[]) => {
const e = elem(s)
- if (opts.class) e.classList.add(...opts.class)
+ apply_opts(e, opts)
for (const c of cs) {
e.append(c)
}
@@ -28,4 +38,6 @@ export const eh4 = elem_with_content("h4")
export const eh5 = elem_with_content("h5")
export const eh6 = elem_with_content("h6")
export const ediv = elem_with_children("div")
+export const espan = elem_with_content("span")
+export const elabel = elem_with_content("label")