Skip to content

Commit 827965a

Browse files
authored
Merge pull request #87 from FlowingCode/merge-4.x
Merge changes from 4.x
2 parents b02f316 + 357194e commit 827965a

File tree

6 files changed

+128
-118
lines changed

6 files changed

+128
-118
lines changed

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

Lines changed: 0 additions & 84 deletions
This file was deleted.

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

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.vaadin.flow.component.dependency.NpmPackage;
2727
import com.vaadin.flow.component.html.Div;
2828
import com.vaadin.flow.component.html.Image;
29+
import com.vaadin.flow.router.RouterLayout;
2930
import java.util.ArrayList;
3031
import java.util.Arrays;
3132
import java.util.List;
@@ -38,16 +39,20 @@
3839
@SuppressWarnings("serial")
3940
@Tag("fc-applayout")
4041
@JsModule("@flowingcode/fc-applayout/fc-applayout.js")
41-
@NpmPackage(value = "@flowingcode/fc-applayout", version = "0.9.3")
42+
@NpmPackage(value = "@flowingcode/fc-applayout", version = "0.9.6")
4243
@CssImport(value = "./styles/applayout-styles.css", themeFor = "fc-applayout")
43-
public class AppLayout extends Div {
44+
public class AppLayout extends Div implements RouterLayout {
4445

4546
private static final String PROFILE_SLOT_NAME = "profile";
4647
private static final String APP_LAYOUT_TITLE_SLOT_NAME = "title";
4748
private static final String TITLE_ATTRIBUTE_NAME = "title";
4849
private final List<Component> menuItems = new ArrayList<>();
4950
private final List<Component> toolbarComponents = new ArrayList<>();
5051

52+
public AppLayout() {
53+
this(null,"",null);
54+
}
55+
5156
public AppLayout(String title) {
5257
this(null, title, null);
5358
}
@@ -70,6 +75,7 @@ private AppLayout(Component menuHeader, String aTitle, Image aLogo) {
7075
Div title = new Div();
7176
title.setText(aTitle);
7277
addToTitleSection(title);
78+
setDrawerRightAlignment(false);
7379
}
7480

7581
public void addToTitleSection(Component component) {
@@ -88,18 +94,20 @@ public void setMenuHeader(Component menuHeader) {
8894
}
8995

9096
public void setMenuItems(Component... someMenuitems) {
91-
this.menuItems.addAll(Arrays.asList(someMenuitems));
92-
this.menuItems.forEach(item -> item.getElement().setAttribute("slot", "menu"));
97+
menuItems.addAll(Arrays.asList(someMenuitems));
98+
menuItems.forEach(item -> item.getElement().setAttribute("slot", "menu"));
9399
this.add(someMenuitems);
94100
}
95101

96102
public void clearMenuItems() {
97-
this.getChildren()
103+
getChildren()
98104
.forEach(
99105
item -> {
100-
if (this.menuItems.contains(item)) this.remove(item);
106+
if (menuItems.contains(item)) {
107+
remove(item);
108+
}
101109
});
102-
this.menuItems.clear();
110+
menuItems.clear();
103111
}
104112

105113
public void setToolbarIconButtons(Component... components) {
@@ -126,30 +134,72 @@ public void clearToolbarIconButtons() {
126134
}
127135

128136
public void setMenuVisible(boolean visible) {
129-
this.getElement().setProperty("drawerVisible", visible);
137+
getElement().setProperty("drawerVisible", visible);
130138
}
131139

132140
public boolean isMenuVisible() {
133-
return this.getElement().getProperty("drawerVisible", true);
141+
return getElement().getProperty("drawerVisible", true);
134142
}
135143

136-
/** Set the toolbar title */
144+
/**
145+
* Sets the toolbar title
146+
* @param caption
147+
*/
137148
public void setCaption(String caption) {
138-
this.getElement().setAttribute(TITLE_ATTRIBUTE_NAME, caption);
149+
getElement().setAttribute(TITLE_ATTRIBUTE_NAME, caption);
139150
}
140151

141-
/** Mantains the header fixed at the top so it never moves away. */
152+
/**
153+
* Sets the fixed attribute so it mantains the header fixed at the top
154+
* so it never moves away.
155+
* @param fixed
156+
*/
142157
public void setFixed(boolean fixed) {
143-
this.getElement().setAttribute("fixed", fixed);
158+
getElement().setAttribute("fixed", fixed);
144159
}
145160

146-
/** Slides back the header when scrolling back up. */
161+
/**
162+
* Sets the reveals attribute so it slides back the header when scrolling
163+
* back up.
164+
* @param reveals
165+
*/
147166
public void setReveals(boolean reveals) {
148-
this.getElement().setAttribute("reveals", reveals);
167+
getElement().setAttribute("reveals", reveals);
149168
}
150169

151-
/** Create an area at the edge of the screen to swipe open the app-drawer */
170+
/**
171+
* Sets the swipeOpen attribute so it creates an area at the edge of the
172+
* screen to swipe open the app-drawer
173+
* @param swipeOpen
174+
*/
152175
public void setSwipeOpen(boolean swipeOpen) {
153-
this.getElement().setAttribute("swipeOpen", swipeOpen);
176+
getElement().setAttribute("swipeOpen", swipeOpen);
177+
}
178+
179+
/**
180+
* Sets the persistent attribute so it will make the drawer to be always
181+
* opened in a non-modal way
182+
* @param drawerPersistent
183+
*/
184+
public void setDrawerPersistent(boolean drawerPersistent) {
185+
getElement().setAttribute("drawerPersistent", drawerPersistent);
186+
}
187+
188+
/**
189+
* Sets the drawerBelowHeader attribute so the drawer will be show below
190+
* the header of the applayout
191+
* @param drawerBelowHeader
192+
*/
193+
public void setDrawerBelowHeader(boolean drawerBelowHeader) {
194+
getElement().setAttribute("drawerBelowHeader", drawerBelowHeader);
195+
}
196+
197+
/**
198+
* Sets the drawerBelowHeader attribute so the drawer will be show below
199+
* the header of the applayout
200+
* @param drawerBelowHeader
201+
*/
202+
public void setDrawerRightAlignment(boolean drawerRightAlignment) {
203+
getElement().setAttribute("drawerAlign", drawerRightAlignment?"right":"left");
154204
}
155205
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
@NpmPackage(value = "@polymer/paper-item", version = "3.0.1")
4040
@Tag("fc-menuitem")
4141
@JsModule("@flowingcode/fc-menuitem/fc-menuitem.js")
42-
@NpmPackage(value = "@flowingcode/fc-menuitem", version = "~0.9.6")
42+
@NpmPackage(value = "@flowingcode/fc-menuitem", version = "~0.9.8")
4343
public class MenuItem extends SlottedMenuItem
4444
implements HasOrderedComponents, HasMenuItemCommands<MenuItem>, HasMenuItemIcon<MenuItem> {
4545

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@
1919
*/
2020
package com.flowingcode.addons.applayout;
2121

22-
import com.vaadin.flow.component.HasElement;
2322
import com.vaadin.flow.component.html.Div;
2423
import com.vaadin.flow.component.html.H4;
2524
import com.vaadin.flow.component.html.Image;
2625
import com.vaadin.flow.component.html.Span;
2726

28-
public class AbstractLayoutDemo extends AbstractFcAppRouterLayout {
27+
public class AbstractLayoutDemo extends AppLayout {
2928

30-
@Override
31-
protected void configure(AppLayout app) {
32-
app.setMenuItems(new MenuItem("Item 1"), new MenuItem("Item 2"));
29+
public AbstractLayoutDemo() {
30+
setMenuItems(new MenuItem("Item 1"), new MenuItem("Item 2"));
3331

3432
// menu header
3533
Div container = new Div();
@@ -39,19 +37,15 @@ protected void configure(AppLayout app) {
3937
img.getStyle().set("margin-top", "20px");
4038
H4 h4 = new H4("User");
4139
container.add(img, h4);
42-
app.setMenuHeader(container);
40+
setMenuHeader(container);
4341

4442
// logo
4543
Image imglogo = new Image("frontend/images/applogo.png", "applogo");
4644
imglogo.setWidth("25px");
47-
app.addToTitleSection(imglogo);
45+
addToTitleSection(imglogo);
4846

4947
// title
50-
app.addToTitleSection(new Div(new Span("Test Application")));
48+
addToTitleSection(new Div(new Span("Test Application")));
5149
}
5250

53-
@Override
54-
public void showRouterLayoutContent(AppLayout app, HasElement content) {
55-
super.showRouterLayoutContent(app, content);
56-
}
5751
}

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public ApplayoutDemoView() {
6969
app.setMenuItems(createMenuItems());
7070

7171
app.setToolbarIconButtons(miSettings);
72-
this.add(app, container);
72+
app.add(container);
73+
this.add(app);
7374

7475
settings.setSwipeOpen(true);
7576
settings.setMenuVisible(true);
@@ -85,7 +86,10 @@ private void applySettings() {
8586
app.setSwipeOpen(settings.isSwipeOpen());
8687
app.setFixed(settings.isFixed());
8788
app.setReveals(settings.isReveals());
88-
89+
app.setDrawerPersistent(settings.isDrawerPersistent());
90+
app.setDrawerBelowHeader(settings.isDrawerBelowHeader());
91+
app.setDrawerRightAlignment(settings.isDrawerRightAlignment());
92+
8993
if (settings.isCompact()) {
9094
app.addClassName("compact");
9195
} else {
@@ -104,7 +108,10 @@ private void openSettings() {
104108
Checkbox cbFixed = new Checkbox("Fixed");
105109
Checkbox cbReveals = new Checkbox("Reveals");
106110
Checkbox cbCompact = new Checkbox("Compact");
107-
111+
Checkbox cbPersistent = new Checkbox("Drawer Persistent");
112+
Checkbox cbBelowHeader = new Checkbox("Drawer Below Header");
113+
Checkbox cbRightAlignment = new Checkbox("Drawer Aligned to Right");
114+
108115
cbMenuVisible.getElement().setAttribute("title", "Toggle visibility of the hamburguer icon.");
109116
cbSwipeOpen
110117
.getElement()
@@ -121,17 +128,29 @@ private void openSettings() {
121128
cbCompact
122129
.getElement()
123130
.setAttribute("title", "When enabled, the height of the header is set to 32px.");
131+
cbPersistent
132+
.getElement()
133+
.setAttribute("title", "When enabled, the drawer will be opened in a non-modal way");
134+
cbBelowHeader
135+
.getElement()
136+
.setAttribute("title", "When enabled, the drawer will be placed below the header");
137+
cbRightAlignment
138+
.getElement()
139+
.setAttribute("title", "When enabled, the drawer will be right aligned");
124140

125141
Binder<DemoSettings> binder = new Binder<>();
126142
binder.forField(cbMenuVisible).bind(DemoSettings::isMenuVisible, DemoSettings::setMenuVisible);
127143
binder.forField(cbSwipeOpen).bind(DemoSettings::isSwipeOpen, DemoSettings::setSwipeOpen);
128144
binder.forField(cbFixed).bind(DemoSettings::isFixed, DemoSettings::setFixed);
129145
binder.forField(cbReveals).bind(DemoSettings::isReveals, DemoSettings::setReveals);
130146
binder.forField(cbCompact).bind(DemoSettings::isCompact, DemoSettings::setCompact);
147+
binder.forField(cbPersistent).bind(DemoSettings::isDrawerPersistent, DemoSettings::setDrawerPersistent);
148+
binder.forField(cbBelowHeader).bind(DemoSettings::isDrawerBelowHeader, DemoSettings::setDrawerBelowHeader);
149+
binder.forField(cbRightAlignment).bind(DemoSettings::isDrawerRightAlignment, DemoSettings::setDrawerRightAlignment);
131150
binder.setBean(this.settings);
132151

133152
VerticalLayout content =
134-
new VerticalLayout(cbMenuVisible, cbSwipeOpen, cbFixed, cbReveals, cbCompact);
153+
new VerticalLayout(cbMenuVisible, cbSwipeOpen, cbFixed, cbReveals, cbCompact, cbPersistent, cbBelowHeader, cbRightAlignment);
135154
content.setSpacing(false);
136155

137156
HorizontalLayout buttons = new HorizontalLayout();

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ public class DemoSettings {
3333

3434
private boolean compact;
3535

36+
private boolean drawerPersistent;
37+
38+
private boolean drawerBelowHeader;
39+
40+
private boolean drawerRightAlignment;
41+
3642
public boolean isEnabled() {
3743
return enabled;
3844
}
@@ -80,4 +86,29 @@ public boolean isCompact() {
8086
public void setCompact(boolean compact) {
8187
this.compact = compact;
8288
}
89+
90+
public boolean isDrawerPersistent() {
91+
return drawerPersistent;
92+
}
93+
94+
public void setDrawerPersistent(boolean drawerPersistent) {
95+
this.drawerPersistent = drawerPersistent;
96+
}
97+
98+
public boolean isDrawerBelowHeader() {
99+
return drawerBelowHeader;
100+
}
101+
102+
public void setDrawerBelowHeader(boolean drawerBelowHeader) {
103+
this.drawerBelowHeader = drawerBelowHeader;
104+
}
105+
106+
public boolean isDrawerRightAlignment() {
107+
return drawerRightAlignment;
108+
}
109+
110+
public void setDrawerRightAlignment(boolean drawerRightAlignment) {
111+
this.drawerRightAlignment = drawerRightAlignment;
112+
}
113+
83114
}

0 commit comments

Comments
 (0)