diff --git a/frontend/src/components/input.njk b/frontend/src/components/input.njk new file mode 100644 index 0000000..feaebda --- /dev/null +++ b/frontend/src/components/input.njk @@ -0,0 +1,59 @@ + + + diff --git a/frontend/src/components/input.ts b/frontend/src/components/input.ts new file mode 100644 index 0000000..44e078e --- /dev/null +++ b/frontend/src/components/input.ts @@ -0,0 +1,34 @@ +import {TesoftComponent} from "../scripts/main.ts"; + +export class TesoftInput extends TesoftComponent { + private readonly input: HTMLInputElement; + + constructor() { + super(); + + const template = document.getElementById("tesoft-input-template") as HTMLTemplateElement; + const templateContent = template.content; + + const shadowRoot = this.attachShadow({mode: "open"}); + shadowRoot.appendChild(templateContent.cloneNode(true)); + + this.input = shadowRoot.querySelector("input")!; + + this.input.addEventListener("focusin", () => { + this.setAttribute("focused", ""); + }); + this.input.addEventListener("focusout", () => { + this.removeAttribute("focused"); + }); + } + + focus() { + this.input.focus(); + } + + set value(value: string) { + this.input.value = value; + } +} + +customElements.define("tesoft-input", TesoftInput);