Skip to content

Instantly share code, notes, and snippets.

@mstahv
Created August 23, 2024 07:12

Revisions

  1. mstahv created this gist Aug 23, 2024.
    42 changes: 42 additions & 0 deletions NavigationView.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    package org.peimari.maastokanta.mobile;

    import com.vaadin.flow.component.Component;
    import com.vaadin.flow.component.html.H3;
    import com.vaadin.flow.component.orderedlayout.FlexComponent;
    import org.vaadin.firitin.components.orderedlayout.VHorizontalLayout;
    import org.vaadin.firitin.components.orderedlayout.VVerticalLayout;

    public class NavigationView extends VVerticalLayout {

    private final H3 titleEl = new H3();
    private final VHorizontalLayout navigationBar = new VHorizontalLayout()
    .withPadding(false)
    .space()
    .withComponent(titleEl)
    .space()
    .alignAll(FlexComponent.Alignment.CENTER);

    public NavigationView(String title) {
    setPadding(false);
    setSpacing(false);
    titleEl.setText(title);
    add(navigationBar);
    }

    public void setTitle(String title) {
    titleEl.setText(title);
    }

    public void setLeftComponent(Component component) {
    navigationBar.addComponentAsFirst(component);
    }

    public void setRightComponent(Component component) {
    navigationBar.add(component);
    }

    public void setContent(Component mainContent) {
    add(mainContent);
    }

    }