Skip to content

Commit 035db8c

Browse files
committed
Resolves #31 Enhance MenuItem methods for setting icons
1 parent f1e4c34 commit 035db8c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/main/java/com/flowingcode/addons/applayout/menu/MenuItem.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Arrays;
2626
import java.util.List;
2727

28+
import com.vaadin.flow.component.icon.VaadinIcon;
2829
import com.vaadin.flow.server.Command;
2930

3031
/**
@@ -64,6 +65,14 @@ public MenuItem(String label, String icon, Command command) {
6465
this.icon = icon;
6566
}
6667

68+
public MenuItem(String label, VaadinIcon icon, Command command) {
69+
this(label, getIconName(icon), command);
70+
}
71+
72+
private static String getIconName(VaadinIcon icon) {
73+
return icon.create().getElement().getAttribute("icon");
74+
}
75+
6776
public String getLabel() {
6877
return label;
6978
}

src/test/java/com/flowingcode/addons/applayout/DemoView.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.io.InputStreamReader;
2626
import java.util.stream.Collectors;
2727

28-
2928
import com.flowingcode.addons.applayout.menu.MenuItem;
3029
import com.vaadin.flow.component.Component;
3130
import com.vaadin.flow.component.button.Button;
@@ -38,6 +37,7 @@
3837
import com.vaadin.flow.component.html.H5;
3938
import com.vaadin.flow.component.html.Image;
4039
import com.vaadin.flow.component.html.Span;
40+
import com.vaadin.flow.component.icon.VaadinIcon;
4141
import com.vaadin.flow.component.notification.Notification;
4242
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
4343
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
@@ -177,7 +177,7 @@ private MenuItem[] createMenuItems() {
177177
toggleSettings.getCommand().execute();
178178

179179
return new MenuItem[] {
180-
new MenuItem("Content", "vaadin:book", () -> showHamletContent()),
180+
new MenuItem("Content", VaadinIcon.BOOK, () -> showHamletContent()),
181181
toggleSettings,
182182
mi,
183183
new MenuItem("About", "cloud", () -> showContent("About")),

0 commit comments

Comments
 (0)