Skip to content

Commit 82e7063

Browse files
committed
Closes #10: Added support for placing a logo in the header of the application
1 parent 9517de1 commit 82e7063

File tree

5 files changed

+41
-15
lines changed

5 files changed

+41
-15
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.vaadin.flow.component.HasComponents;
2626
import com.vaadin.flow.component.Tag;
2727
import com.vaadin.flow.component.dependency.HtmlImport;
28+
import com.vaadin.flow.component.html.Image;
2829

2930
/**
3031
* Component that renders the app header
@@ -40,10 +41,14 @@ public class AppHeader extends Component implements HasComponents {
4041
private AppToolbar appToolbar;
4142

4243
public AppHeader(String title, AppDrawer drawer) {
44+
this(null,title,drawer);
45+
}
46+
47+
public AppHeader(Image logo, String title, AppDrawer drawer) {
4348
this.getElement().setAttribute("reveals", true);
4449
this.getElement().setAttribute("condenses", true);
4550
this.getElement().setAttribute("effects", true);
46-
appToolbar = new AppToolbar(title, drawer);
51+
appToolbar = new AppToolbar(logo, title, drawer);
4752
this.add(appToolbar);
4853
}
4954

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.vaadin.flow.component.Component;
2929
import com.vaadin.flow.component.dependency.HtmlImport;
3030
import com.vaadin.flow.component.html.Div;
31+
import com.vaadin.flow.component.html.Image;
3132
import com.vaadin.flow.server.InitialPageSettings;
3233
import com.vaadin.flow.server.PageConfigurator;
3334

@@ -50,16 +51,21 @@ public class AppLayout extends Div implements PageConfigurator {
5051

5152
public AppLayout(String title) {
5253
drawer = new AppDrawer(title);
53-
configureAppLayout(title);
54+
configureAppLayout(title, null);
5455
}
5556

56-
public AppLayout(Component header, String title) {
57-
drawer = new AppDrawer(header);
58-
configureAppLayout(title);
57+
public AppLayout(Component menuHeader, String title) {
58+
drawer = new AppDrawer(menuHeader);
59+
configureAppLayout(title, null);
5960
}
6061

61-
private void configureAppLayout(String title) {
62-
header = new AppHeader(title, drawer);
62+
public AppLayout(Image logo, Component menuHeader, String title) {
63+
drawer = new AppDrawer(menuHeader);
64+
configureAppLayout(title, logo);
65+
}
66+
67+
private void configureAppLayout(String title, Image logo) {
68+
header = new AppHeader(logo, title, drawer);
6369
add(header);
6470
add(drawer);
6571
setWidth("100%");

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.vaadin.flow.component.Tag;
3030
import com.vaadin.flow.component.dependency.HtmlImport;
3131
import com.vaadin.flow.component.html.Div;
32+
import com.vaadin.flow.component.html.Image;
3233

3334
/**
3435
* Component that renders the app toolbar
@@ -41,22 +42,36 @@
4142
@HtmlImport("bower_components/app-layout/app-toolbar/app-toolbar.html")
4243
public class AppToolbar extends Component implements HasComponents {
4344

44-
PaperIconButton menu;
45-
Div divTitle;
45+
private PaperIconButton menu;
46+
private Component ctitle;
47+
private Div divTitle;
4648

4749
public AppToolbar(String title, AppDrawer drawer) {
50+
this(null,title, drawer);
51+
}
52+
53+
public AppToolbar(Image logo, String title, AppDrawer drawer) {
4854
menu = new PaperIconButton("menu");
4955
menu.getElement().setAttribute("onclick", "" + drawer.getId().get() + ".toggle()");
50-
divTitle = new Div();
51-
divTitle.setText(title);
52-
divTitle.getElement().setAttribute("main-title", true);
53-
this.add(menu,divTitle);
56+
this.add(menu);
57+
if (logo!=null) {
58+
ctitle = logo;
59+
this.add(ctitle);
60+
}
61+
if (title!=null) {
62+
divTitle = new Div();
63+
divTitle.setText(title);
64+
divTitle.getElement().setAttribute("main-title", true);
65+
this.add(divTitle);
66+
}
5467
}
5568

5669
public void setToolbarIconButtons(MenuItem[] menuItems) {
5770
List<PaperIconButton> toolbarIconButtons = createToolbarIconButtons(menuItems);
5871
this.removeAll();
59-
this.add(menu,divTitle);
72+
this.add(menu);
73+
if (ctitle!=null) this.add(ctitle);
74+
if (divTitle!=null) this.add(divTitle);
6075
toolbarIconButtons.forEach(tib->this.add(tib));
6176
}
6277

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
public class DemoView extends VerticalLayout {
3636

3737
private VerticalLayout container = new VerticalLayout();
38-
private final AppLayout app = new AppLayout(createAvatarComponent(), "AppLayout Addon for Vaadin 10 Demo");
38+
private final AppLayout app = new AppLayout(new Image("/frontend/images/applogo.png","avatar"), createAvatarComponent(), "AppLayout Vaadin 10 Demo");
3939

4040
public DemoView() {
4141
container.setDefaultHorizontalComponentAlignment(Alignment.CENTER);
3.06 KB
Loading

0 commit comments

Comments
 (0)