mr-crocs-adventures/tilorswift/js/menu/MenuGroup.js

34 lines
734 B
JavaScript
Raw Permalink Normal View History

export default class MenuGroup
{
className = 'menu-group';
constructor(title)
{
this.title = title;
this.menuEntries = [];
}
addMenuEntry(entry)
{
this.menuEntries.push(entry);
}
getElement()
{
let htmlElement = document.createElement('div');
htmlElement.classList.add(this.className);
htmlElement.innerText = this.title;
let dropdown = document.createElement('ul');
dropdown.classList.add('menu-dropdown');
htmlElement.appendChild(dropdown);
this.menuEntries.forEach(
(entry) => {
dropdown.appendChild(entry.getElement());
}
);
return htmlElement;
}
}