mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-08 12:36:50 +03:00
feat: implement base of diagnostics
This commit is contained in:
18
fe-app-podkop/src/helpers/svgEl.ts
Normal file
18
fe-app-podkop/src/helpers/svgEl.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export function svgEl<K extends keyof SVGElementTagNameMap>(
|
||||
tag: K,
|
||||
attrs: Partial<Record<string, string | number>> = {},
|
||||
children: (SVGElement | null | undefined)[] = [],
|
||||
): SVGElementTagNameMap[K] {
|
||||
const NS = 'http://www.w3.org/2000/svg';
|
||||
const el = document.createElementNS(NS, tag);
|
||||
|
||||
for (const [k, v] of Object.entries(attrs)) {
|
||||
if (v != null) el.setAttribute(k, String(v));
|
||||
}
|
||||
|
||||
(Array.isArray(children) ? children : [children])
|
||||
.filter(Boolean)
|
||||
.forEach((ch) => el.appendChild(ch as SVGElement));
|
||||
|
||||
return el;
|
||||
}
|
||||
Reference in New Issue
Block a user