[SideNav] Use MenuConfiguration directly
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.
Also, icon defined as a String in @Menu cannot be used directly in SideNavItem. Prefix component is required.
Would you expect it to work on the client side as well?
Would you expect it to work on the client side as well?
I'm writing pure Java demo, didn't consider client side.
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.