aboutsummaryrefslogtreecommitdiff
path: root/static/components/tab-element.ts
blob: 9da6c50425cf8923b82194974a4065d30763caf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
export { TabElement }

/* <tab-element /> */
class TabElement extends HTMLElement {
    constructor() {
        super();
    }

    connectedCallback() {
        let template
            = (document.getElementById('tab-template') as HTMLTemplateElement)
                .content
        // const shadowRoot = this.attachShadow({ mode: 'open' })
        //     .appendChild(template.cloneNode(true));

        let content = Array.from(this.children, (e) => e.cloneNode(true))

        this.replaceChildren(template.cloneNode(true));

        let label = this.querySelector('label')
        if (!label) throw "Invalid tab"

        label.setAttribute('title', this.getAttribute('label-title') || '')
        label.innerText = this.getAttribute('label') || 'T'

        this.querySelector('slot[name="content"]')!.replaceWith(...content);
    }
}