Skip to content

Commit 9517de1

Browse files
committed
Closes #9: Add support for setting a custom component to the header of the menu (like the logged in user account details)
1 parent a752d24 commit 9517de1

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

src/main/java/com/flowingcode/addons/applayout/AppDrawer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,18 @@
4343
public class AppDrawer extends Component implements HasComponents {
4444

4545
private PaperListbox pm = new PaperListbox(Arrays.asList(new Component[] {}));
46+
private Component header;
4647

4748
public AppDrawer(String title) {
49+
this(new H4(title));
50+
header.getElement().setAttribute("style", "text-align:center");
51+
}
52+
53+
public AppDrawer(Component headerComponent) {
54+
this.header = headerComponent;
4855
getElement().setAttribute("id", "drawer");
4956
getElement().setAttribute("swipe-open", true);
50-
H4 htitle = new H4(title);
51-
htitle.getElement().setAttribute("style", "text-align:center");
52-
this.add(htitle);
57+
this.add(headerComponent);
5358
this.add(pm);
5459
}
5560

src/main/java/com/flowingcode/addons/applayout/AppLayout.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Arrays;
2626

2727
import com.flowingcode.addons.applayout.menu.MenuItem;
28+
import com.vaadin.flow.component.Component;
2829
import com.vaadin.flow.component.dependency.HtmlImport;
2930
import com.vaadin.flow.component.html.Div;
3031
import com.vaadin.flow.server.InitialPageSettings;
@@ -49,13 +50,22 @@ public class AppLayout extends Div implements PageConfigurator {
4950

5051
public AppLayout(String title) {
5152
drawer = new AppDrawer(title);
53+
configureAppLayout(title);
54+
}
55+
56+
public AppLayout(Component header, String title) {
57+
drawer = new AppDrawer(header);
58+
configureAppLayout(title);
59+
}
60+
61+
private void configureAppLayout(String title) {
5262
header = new AppHeader(title, drawer);
5363
add(header);
5464
add(drawer);
5565
setWidth("100%");
5666
setHeight("64px");
5767
}
58-
68+
5969
public void setMenuItems(MenuItem... menuitems) {
6070
drawer.setMenuItems(Arrays.asList(menuitems));
6171
}

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
*/
2222

2323
import com.flowingcode.addons.applayout.menu.MenuItem;
24+
import com.vaadin.flow.component.Component;
25+
import com.vaadin.flow.component.html.Div;
2426
import com.vaadin.flow.component.html.H3;
27+
import com.vaadin.flow.component.html.H4;
28+
import com.vaadin.flow.component.html.Image;
2529
import com.vaadin.flow.component.notification.Notification;
2630
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
2731
import com.vaadin.flow.router.Route;
@@ -31,7 +35,7 @@
3135
public class DemoView extends VerticalLayout {
3236

3337
private VerticalLayout container = new VerticalLayout();
34-
private final AppLayout app = new AppLayout("AppLayout Addon for Vaadin 10 Demo");
38+
private final AppLayout app = new AppLayout(createAvatarComponent(), "AppLayout Addon for Vaadin 10 Demo");
3539

3640
public DemoView() {
3741
container.setDefaultHorizontalComponentAlignment(Alignment.CENTER);
@@ -51,6 +55,16 @@ public DemoView() {
5155
this.add(app, container);
5256
}
5357

58+
private Component createAvatarComponent() {
59+
Div container = new Div();
60+
container.getElement().setAttribute("style", "text-align: center;");
61+
Image i = new Image("/frontend/images/avatar.png","avatar");
62+
i.getElement().setAttribute("style", "width: 80px; margin-top:20px");
63+
H4 h4 = new H4("User");
64+
container.add(i,h4);
65+
return container;
66+
}
67+
5468
private MenuItem[] createMenuItems() {
5569
MenuItem mi = new MenuItem("Say hello", "star", () -> showContent("Hello!"));
5670
return new MenuItem[] {mi ,
27.2 KB
Loading

0 commit comments

Comments
 (0)