diff --git a/frontend/src/components/tag.njk b/frontend/src/components/tag.njk new file mode 100644 index 0000000..d95bea4 --- /dev/null +++ b/frontend/src/components/tag.njk @@ -0,0 +1,27 @@ + + + +{% includeOnce 'components/badge.njk' %} diff --git a/frontend/src/components/tag.ts b/frontend/src/components/tag.ts new file mode 100644 index 0000000..cea72f2 --- /dev/null +++ b/frontend/src/components/tag.ts @@ -0,0 +1,36 @@ +import {TesoftComponent} from "../scripts/main.ts"; + +export class TesoftTag extends TesoftComponent { + static observedAttributes = ["href"]; + + private readonly anchor: HTMLAnchorElement; + + constructor() { + super(); + + const template = document.getElementById("tesoft-tag-template") as HTMLTemplateElement; + const templateContent = template.content; + + const shadowRoot = this.attachShadow({mode: "open"}); + shadowRoot.appendChild(templateContent.cloneNode(true)); + + this.anchor = shadowRoot.querySelector("a")!; + } + + // noinspection JSUnusedGlobalSymbols + attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null) { + if (name === "href") { + this.anchor.href = newValue ?? ""; + } + } + + set href(value: string | null) { + if (value) { + this.setAttribute("href", value); + } else { + this.removeAttribute("href"); + } + } +} + +customElements.define("tesoft-tag", TesoftTag);