flow-components icon indicating copy to clipboard operation
flow-components copied to clipboard

[SideNav] Use MenuConfiguration directly

Open MarcinVaadin opened this issue 1 year ago • 4 comments

Describe your motivation

While using @Menu on Flow project I would like to put all items in SideNav ~~automatically~~ as easy as possible.

Describe the solution you'd like

I've expected something short and handy like:

List<MenuEntry> menuEntries = MenuConfiguration.getMenuEntries();
SideNav sideNav = SideNav.from(menuEntries);

or

SideNav sideNav = new SideNav();
List<MenuEntry> menuEntries = MenuConfiguration.getMenuEntries();
menuEntries.forEach(sideNav::add);

would work.

Describe alternatives you've considered

Current working approach requires:

SideNav sideNav = new SideNav();
List<MenuEntry> menuEntries = MenuConfiguration.getMenuEntries();
menuEntries.stream().map(menuEntry -> new SideNavItem(menuEntry.title(), menuEntry.path())).forEach(sideNav::addItem);

which looks like a boilerplate.

MarcinVaadin avatar Dec 04 '24 15:12 MarcinVaadin

Also, icon defined as a String in @Menu cannot be used directly in SideNavItem. Prefix component is required.

MarcinVaadin avatar Dec 05 '24 11:12 MarcinVaadin

Would you expect it to work on the client side as well?

yuriy-fix avatar Dec 05 '24 14:12 yuriy-fix

Would you expect it to work on the client side as well?

I'm writing pure Java demo, didn't consider client side.

MarcinVaadin avatar Dec 05 '24 14:12 MarcinVaadin

This isn't trivial to implement currently. Creating items with label and path from the menu configuration is straightforward. However you would also expect it to create an icon if one is specified in @Menu. When using iconsets, this would require importing Icon in SideNav. This has the side effect that the Vaadin iconset would be included in the frontend bundle for everyone using side nav, even if no icons are used.

This may become feasible at some point if Icon wouldn't automatically include the Vaadin iconset, and if there would be some way for Flow users to explicitly specify which iconsets to include in the bundle.

sissbruecker avatar Dec 20 '24 05:12 sissbruecker