summaryrefslogtreecommitdiff
path: root/client-web/source/helper.ts
diff options
context:
space:
mode:
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")