/**
* Horizontal Scroll Nav Component
* Pill-style category buttons in a horizontal scroller
*/
class HorizontalScrollNav extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
this.categories = [
{ id: "asoka", label: "Asoka", active: true },
{ id: "synthese", label: "Synthese", active: false },
{ id: "de-driehoek", label: "De Driehoek", active: false },
{ id: "waerbeke", label: "Waerbeke", active: false },
{ id: "stuivenberg", label: "Stuivenberg", active: false },
];
}
connectedCallback() {
this.render();
this.addEventListeners();
}
addEventListeners() {
const buttons = this.shadowRoot.querySelectorAll(".nav-pill");
buttons.forEach((button) => {
button.addEventListener("click", (e) => {
this.setActiveCategory(e.target.dataset.id);
});
});
}
setActiveCategory(id) {
this.categories = this.categories.map((cat) => ({
...cat,
active: cat.id === id,
}));
this.render();
this.addEventListeners();
// Dispatch custom event for parent components
this.dispatchEvent(
new CustomEvent("category-change", {
detail: { categoryId: id },
bubbles: true,
composed: true,
})
);
}
render() {
this.shadowRoot.innerHTML = `
`;
}
}
customElements.define("horizontal-scroll-nav", HorizontalScrollNav);