cyp/app/js/elements/menu.js
Ondřej Žára f8dea00d8f fixes
2020-06-12 16:34:33 +02:00

28 lines
689 B
JavaScript

import Component from "../component.js";
class Menu extends Component {
connectedCallback() {
super.connectedCallback();
/** @type HTMLElement[] */
this._tabs = Array.from(this.querySelectorAll("[data-for]"));
this._tabs.forEach(tab => {
tab.addEventListener("click", _ => this._app.setAttribute("component", tab.dataset.for));
});
}
_onAppLoad() {
this._app.addEventListener("queue-length-change", e => {
this.querySelector(".queue-length").textContent = `(${e.detail})`;
});
}
_onComponentChange(component) {
this._tabs.forEach(tab => {
tab.classList.toggle("active", tab.dataset.for == component);
});
}
}
customElements.define("cyp-menu", Menu);