diff --git a/client/src/components/Tabs/index.ts b/client/src/components/Tabs/index.ts new file mode 100644 index 0000000..6b0e757 --- /dev/null +++ b/client/src/components/Tabs/index.ts @@ -0,0 +1,10 @@ +document.addEventListener("DOMContentLoaded", () => { + const tabs = document.querySelector("ui-tabs"); + const typeTabContent = document.getElementById("type-tab-content"); + const historyTabContent = document.getElementById("history-tab-content"); + + if (tabs && typeTabContent && historyTabContent) { + tabs.addTab("type", "Type", typeTabContent, true); + tabs.addTab("history", "History", historyTabContent, false); + } +}); diff --git a/client/src/components/Tabs/tabs.ts b/client/src/components/Tabs/tabs.ts new file mode 100644 index 0000000..4657c1f --- /dev/null +++ b/client/src/components/Tabs/tabs.ts @@ -0,0 +1,135 @@ +declare global { + interface TabsTagNameMap { + [Tabs.tag]: Tabs; + } + interface HTMLElementTagNameMap extends TabsTagNameMap {} + + interface TabsEventMap { + [Tabs.events.change]: CustomEvent<{ activeTab: string }>; + } + interface ElementEventMap extends TabsEventMap {} +} + +export class Tabs extends HTMLElement { + static tag = "ui-tabs" as const; + static events = { + change: "change", + } as const; + + private tabButtons: HTMLButtonElement[] = []; + private tabContents: HTMLElement[] = []; + private activeTab: string = ""; + + constructor() { + super(); + this.classList.add("ui-tabs"); + } + + connectedCallback() { + this.render(); + this.setupEventListeners(); + } + + private render() { + this.innerHTML = ` +
+Complete some typing sessions to see your progress here!
+