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:07:30 +08:00
|
|
|
super({selection:null});
|
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));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|