summaryrefslogtreecommitdiff
path: root/src/main/resources/META-INF/resources/admin/AdminElement.js
blob: 8398d551405146de15a99673b81899181a9926fa (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
29
30
31
32
33
34
35
36
37
38
39
import {html, render} from "../node_modules/lit-html/lit-html.js";


export class AdminElement extends HTMLElement {
    constructor() {
        super();
        this.attachShadow({mode: "open"});
    }

    static get observedAttributes() {
        return ["greetee"];
    }

    connectedCallback () {
        this.render();
    }

    attributeChangedCallback(name, oldValue, newValue) {
        this.render();
    }

    onSwitchClicked = (event) => {
        this.setAttribute("greetee", "Andreas");
        this.render();
    };

    render() {
        let greetee = this.getAttribute("greetee");

        const template = `
            <p>Hello ${greetee}! <button id="switch">Switch</button></p>
            `;

        this.shadowRoot.innerHTML = template;
        this.shadowRoot.querySelector('#switch').addEventListener('click', this.onSwitchClicked);
    }
}

customElements.define("mlk-admin", AdminElement);