From 3a657c2f6d4cc9f82c993a8d390c8a84ab38bcb4 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 9 Sep 2022 17:49:39 +0200 Subject: chat! --- client-web/source/helper.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'client-web/source/helper.ts') 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") -- cgit v1.2.3-70-g09d2