cyp/app/js/elements/menu.js

33 lines
756 B
JavaScript
Raw Normal View History

2020-03-10 05:24:31 +08:00
import Component from "../component.js";
2020-03-09 05:11:46 +08:00
class Menu extends Component {
constructor() {
2020-03-10 17:42:13 +08:00
super();
2020-03-09 05:11:46 +08:00
this._tabs = Array.from(this.querySelectorAll("[data-for]"));
this._tabs.forEach(tab => {
tab.addEventListener("click", _ => this._activate(tab.dataset.for));
});
}
2020-03-17 05:57:13 +08:00
_onAppLoad() {
this._app.addEventListener("queue-length-change", e => {
this.querySelector(".queue-length").textContent = `(${e.detail})`;
});
}
2020-03-09 05:11:46 +08:00
async _activate(component) {
const app = await this._app;
app.setAttribute("component", component);
}
_onComponentChange(component) {
2020-03-10 17:07:30 +08:00
this._tabs.forEach(/** @param {HTMLElement} tab */ tab => {
2020-03-09 05:11:46 +08:00
tab.classList.toggle("active", tab.dataset.for == component);
});
}
}
customElements.define("cyp-menu", Menu);