aboutsummaryrefslogtreecommitdiff
path: root/client-web/source/helper.ts
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2022-10-03 11:28:16 +0200
committermetamuffin <metamuffin@disroot.org>2022-10-03 11:28:16 +0200
commit4e99a3325318c902cd78ea9f760f46d79acde5c0 (patch)
treecc2bc54f4a0eb27db2b5d38dfbb785c1e9b84bd6 /client-web/source/helper.ts
parentfa44b02da29a0bd1b60026d4f6ffd6c9748a09da (diff)
downloadkeks-meet-4e99a3325318c902cd78ea9f760f46d79acde5c0.tar
keks-meet-4e99a3325318c902cd78ea9f760f46d79acde5c0.tar.bz2
keks-meet-4e99a3325318c902cd78ea9f760f46d79acde5c0.tar.zst
riesencommit (part 1)
Diffstat (limited to 'client-web/source/helper.ts')
-rw-r--r--client-web/source/helper.ts12
1 files changed, 6 insertions, 6 deletions
diff --git a/client-web/source/helper.ts b/client-web/source/helper.ts
index 1ec42aa..d43fc3e 100644
--- a/client-web/source/helper.ts
+++ b/client-web/source/helper.ts
@@ -7,24 +7,24 @@
import { PREFS } from "./preferences/mod.ts";
-const elem = (s: string) => document.createElement(s)
+const elem = <K extends keyof HTMLElementTagNameMap>(s: K): HTMLElementTagNameMap[K] => document.createElement(s)
-interface Opts { class?: string[] | string, id?: string, src?: string, onclick?: (e: HTMLElement) => void }
+interface Opts<El> { class?: string[] | string, id?: string, src?: string, onclick?: (e: El) => void }
-function apply_opts(e: HTMLElement, o: Opts | undefined) {
+function apply_opts<El extends HTMLElement>(e: El, o: Opts<El> | undefined) {
if (!o) return
if (o.id) e.id = o.id
if (o.onclick) e.onclick = () => o.onclick!(e)
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 elem_with_content = <K extends keyof HTMLElementTagNameMap>(s: K) => (c: string, opts?: Opts<HTMLElementTagNameMap[K]>) => {
const e = elem(s)
apply_opts(e, opts)
e.textContent = c
return e
}
-const elem_with_children = (s: string) => (opts?: Opts, ...cs: (HTMLElement | string)[]) => {
+const elem_with_children = <K extends keyof HTMLElementTagNameMap>(s: K) => (opts?: Opts<HTMLElementTagNameMap[K]>, ...cs: (HTMLElement | string)[]) => {
const e = elem(s)
apply_opts(e, opts)
for (const c of cs) {
@@ -65,7 +65,7 @@ export class OverlayUi {
}
}
-export function image_view(url: string, opts?: Opts): HTMLElement {
+export function image_view(url: string, opts?: Opts<HTMLElement>): HTMLElement {
const img = document.createElement("img")
apply_opts(img, opts)
img.src = url