support menu options with custom DOM

This commit is contained in:
Bruno Windels 2021-06-17 16:45:53 +02:00
parent 70d64f38eb
commit 4312610e7d

View file

@ -27,18 +27,7 @@ export class Menu extends TemplateView {
}
render(t) {
return t.ul({className: "menu", role: "menu"}, this._options.map(o => {
const className = {
destructive: o.destructive,
};
if (o.icon) {
className.icon = true;
className[o.icon] = true;
}
return t.li({
className,
}, t.button({onClick: o.callback}, o.label));
}));
return t.ul({className: "menu", role: "menu"}, this._options.map(o => o.toDOM(t)));
}
}
@ -59,4 +48,17 @@ class MenuOption {
this.destructive = true;
return this;
}
toDOM(t) {
const className = {
destructive: this.destructive,
};
if (this.icon) {
className.icon = true;
className[this.icon] = true;
}
return t.li({
className,
}, t.button({onClick: this.callback}, this.label));
}
}