Added NavPath component

This commit is contained in:
Andrey Terentev 2023-11-17 00:07:51 +07:00
parent 82ba4e83bb
commit f4c32dff24
2 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,59 @@
package ru.dragonestia.loadbalancer.web.component;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.icon.Icon;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
public class NavPath extends HorizontalLayout{
public NavPath(Point root, Point... points) {
setWidth("100%");
setAlignItems(Alignment.CENTER);
getStyle().set("background-color", "#F3F3F3")
.set("padding-left", "1rem")
.set("padding-right", "1rem");
{
var button = createPointButton(root);
button.getStyle().set("font-weight", "bold");
add(button);
}
if (points.length != 0) {
add(createDelimiterComponent());
for (int i = 0, n = points.length; i < n; i++) {
var button = createPointButton(points[i]);
add(button);
if (i + 1 != n) {
add(createDelimiterComponent());
}
}
}
}
private Component createDelimiterComponent() {
return new Icon(VaadinIcon.ANGLE_RIGHT);
}
private Button createPointButton(Point point) {
var text = new Span(point.name());
var button = new Button(text, event -> {
getUI().ifPresent(ui -> ui.navigate(point.uri()));
});
button.getStyle()
.setPadding("0")
.setBorder("0");
button.addThemeVariants(ButtonVariant.LUMO_TERTIARY, ButtonVariant.LUMO_LARGE);
return button;
}
public record Point(String name, String uri) {}
}

View File

@ -1,9 +1,11 @@
package ru.dragonestia.loadbalancer.web.page;
import com.vaadin.flow.component.html.Hr;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import lombok.Getter;
import ru.dragonestia.loadbalancer.web.component.NavPath;
import ru.dragonestia.loadbalancer.web.component.NodeList;
import ru.dragonestia.loadbalancer.web.component.RegisterNode;
@ -20,7 +22,9 @@ public class NodesPage extends VerticalLayout {
public NodesPage() {
super();
add(new NavPath(new NavPath.Point("Nodes", "/nodes")));
add(registerNode = createRegisterNodeElement());
add(new Hr());
add(nodeList = createNodeListElement());
}