Skip to content

Commit 07bb7a1

Browse files
mlopezFCjavier-godoy
authored andcommitted
feat: use fc-applayout webcomponent
1 parent c2e17a9 commit 07bb7a1

File tree

4 files changed

+53
-359
lines changed

4 files changed

+53
-359
lines changed

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

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

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

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

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

Lines changed: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,101 +19,110 @@
1919
*/
2020
package com.flowingcode.addons.applayout;
2121

22+
import java.util.ArrayList;
23+
import java.util.Arrays;
24+
import java.util.List;
25+
2226
import com.vaadin.flow.component.Component;
27+
import com.vaadin.flow.component.Tag;
2328
import com.vaadin.flow.component.dependency.CssImport;
2429
import com.vaadin.flow.component.dependency.JsModule;
2530
import com.vaadin.flow.component.dependency.NpmPackage;
2631
import com.vaadin.flow.component.html.Div;
2732
import com.vaadin.flow.component.html.Image;
2833
import com.vaadin.flow.server.InitialPageSettings;
2934
import com.vaadin.flow.server.PageConfigurator;
30-
import java.util.ArrayList;
31-
import java.util.Arrays;
3235

3336
/**
3437
* Component that renders the div that contains the entire layout.
3538
*
3639
* @author mlopez
3740
*/
3841
@SuppressWarnings("serial")
39-
@NpmPackage(value = "@polymer/app-layout", version = AppLayout.NPM_VERSION)
40-
@NpmPackage(value = "@polymer/font-roboto", version = "^3.0")
41-
@JsModule("@polymer/app-layout/app-scroll-effects/app-scroll-effects.js")
42-
@JsModule("@polymer/font-roboto/roboto.js")
43-
@CssImport("./styles/applayout-styles.css")
42+
@Tag("fc-applayout")
43+
@JsModule("@flowingcode/fc-applayout/fc-applayout.js")
44+
@NpmPackage(value = "@flowingcode/fc-applayout", version = "~0.9.3")
45+
@CssImport(value="./styles/applayout-styles.css", themeFor = "fc-applayout")
4446
public class AppLayout extends Div implements PageConfigurator {
4547

4648
static final String NPM_VERSION = "3.0.2";
47-
48-
private AppDrawer drawer;
49-
private AppHeader header;
49+
private List<Component> menuItems = new ArrayList<>();
50+
private List<Component> toolbarComponents = new ArrayList<>();
5051

5152
public AppLayout(String title) {
52-
drawer = new AppDrawer(title);
53-
configureAppLayout(title, null);
53+
configureAppLayout(null, title, null);
5454
}
5555

5656
public AppLayout(Component menuHeader, String title) {
57-
drawer = new AppDrawer(menuHeader);
58-
configureAppLayout(title, null);
57+
configureAppLayout(menuHeader, title, null);
5958
}
6059

6160
public AppLayout(Image logo, Component menuHeader, String title) {
62-
drawer = new AppDrawer(menuHeader);
63-
configureAppLayout(title, logo);
61+
configureAppLayout(menuHeader, title, logo);
6462
}
6563

66-
private void configureAppLayout(String title, Image logo) {
67-
header = new AppHeader(logo, title, drawer);
68-
add(header);
69-
add(drawer);
70-
setWidth("100%");
71-
setHeight("64px");
64+
private void configureAppLayout(Component menuHeader, String aTitle, Image aLogo) {
65+
if (aLogo!=null) {
66+
aLogo.getElement().setAttribute("slot", "title");
67+
add(aLogo);
68+
}
69+
if (menuHeader!=null) {
70+
menuHeader.getElement().setAttribute("slot", "profile");
71+
add(menuHeader);
72+
}
73+
Div title = new Div();
74+
title.setText(aTitle);
75+
title.getElement().setAttribute("slot", "title");
76+
add(title);
7277
}
7378

74-
@Override
75-
public void setHeight(String height) {
76-
super.setHeight(height);
77-
header.setHeight(height);
78-
}
79-
80-
public void setMenuItems(Component... menuitems) {
81-
drawer.setMenuItems(Arrays.asList(menuitems));
79+
public void setMenuItems(Component... someMenuitems) {
80+
this.menuItems.addAll(Arrays.asList(someMenuitems));
81+
this.menuItems.forEach(item->item.getElement().setAttribute("slot", "menu"));
82+
this.add(someMenuitems);
8283
}
8384

8485
public void clearMenuItems() {
85-
drawer.setMenuItems(new ArrayList<>());
86+
this.getChildren().forEach(item->{
87+
if(this.menuItems.contains(item)) this.remove(item);
88+
});
89+
this.menuItems.clear();
8690
}
8791

8892
public void setToolbarIconButtons(Component... components) {
89-
header.getAppToolbar().clearToolbarIconButtons();
90-
header.getAppToolbar().addToolbarIconButtons(components);
93+
toolbarComponents.forEach(this::remove);
94+
addToolbarIconButtons(components);
9195
}
9296

9397
public void addToolbarIconButtons(Component... components) {
94-
header.getAppToolbar().addToolbarIconButtons(components);
98+
List<Component> componentsToAdd = Arrays.asList(components);
99+
componentsToAdd.forEach(comp->comp.getElement().setAttribute("slot", "toolbar"));
100+
toolbarComponents.addAll(componentsToAdd);
101+
this.add(components);
95102
}
96103

97104
public void addToolbarIconButtonAsFirst(Component component) {
98-
header.getAppToolbar().addToolbarIconButtonAsFirst(component);
105+
toolbarComponents.add(0, component);
106+
toolbarComponents.forEach(this::remove);
107+
addToolbarIconButtons(toolbarComponents.toArray(new Component[toolbarComponents.size()]));
99108
}
100109

101110
public void clearToolbarIconButtons() {
102-
header.getAppToolbar().clearToolbarIconButtons();
111+
toolbarComponents.forEach(this::remove);
112+
toolbarComponents.clear();
103113
}
104114

105115
public void setMenuVisible(boolean visible) {
106-
drawer.setVisible(visible);
107-
header.getAppToolbar().setMenuIconVisible(visible);
116+
this.getElement().setProperty("drawer-visible", visible);
108117
}
109118

110119
public boolean isMenuVisible() {
111-
return drawer.isVisible();
120+
return this.getElement().getProperty("drawer-visible", true);
112121
}
113122

114123
/** Set the toolbar title */
115124
public void setCaption(String caption) {
116-
header.getAppToolbar().setTitle(caption);
125+
this.getElement().setAttribute("title", caption);
117126
}
118127

119128
@Override
@@ -123,16 +132,17 @@ public void configurePage(InitialPageSettings settings) {
123132

124133
/** Mantains the header fixed at the top so it never moves away. */
125134
public void setFixed(boolean fixed) {
126-
header.setFixed(fixed);
135+
this.getElement().setAttribute("fixed", fixed);
127136
}
128137

129138
/** Slides back the header when scrolling back up. */
130139
public void setReveals(boolean reveals) {
131-
header.setReveals(reveals);
140+
this.getElement().setAttribute("reveals", reveals);
132141
}
133142

134143
/** Create an area at the edge of the screen to swipe open the app-drawer */
135144
public void setSwipeOpen(boolean swipeOpen) {
136-
drawer.setSwipeOpen(swipeOpen);
145+
this.getElement().setAttribute("swipeOpen", swipeOpen);
137146
}
147+
138148
}

0 commit comments

Comments
 (0)