All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.dominokit.domino.ui.layout.NavigationBar Maven / Gradle / Ivy

There is a newer version: 2.0.3
Show newest version
/*
 * Copyright © 2019 Dominokit
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.dominokit.domino.ui.layout;

import static org.jboss.elemento.Elements.*;

import elemental2.dom.HTMLAnchorElement;
import elemental2.dom.HTMLDivElement;
import elemental2.dom.HTMLElement;
import elemental2.dom.HTMLUListElement;
import org.dominokit.domino.ui.grid.flex.FlexItem;
import org.dominokit.domino.ui.grid.flex.FlexLayout;
import org.dominokit.domino.ui.utils.BaseDominoElement;
import org.dominokit.domino.ui.utils.DominoElement;

/** A component that is part of the {@link Layout} header */
public class NavigationBar extends BaseDominoElement {
  private final FlexItem menuToggleItem;
  private final FlexItem titleItem;
  private final FlexItem logoItem;
  private final FlexItem actionBarItem;

  private DominoElement navBar =
      DominoElement.of(nav()).css("navbar").css("ls-closed");
  private FlexLayout container = FlexLayout.create().css("container-fluid");

  DominoElement title = DominoElement.of(a()).css("navbar-brand");
  DominoElement menu = DominoElement.of(a()).css("bars");
  DominoElement topBar =
      DominoElement.of(ul()).css("nav").css("navbar-nav").css("navbar-right");
  DominoElement topBarContainer = DominoElement.div().appendChild(topBar);
  DominoElement navBarHeader = DominoElement.div().css("navbar-header");

  /** */
  public NavigationBar() {
    menuToggleItem = FlexItem.create().css("menu-toggle");
    logoItem = FlexItem.create();
    titleItem = FlexItem.create();
    actionBarItem = FlexItem.create();
    container
        .appendChild(menuToggleItem.appendChild(menu))
        .appendChild(logoItem)
        .appendChild(titleItem.setFlexGrow(1).appendChild(title))
        .appendChild(actionBarItem.appendChild(topBarContainer));

    navBar.appendChild(navBarHeader.appendChild(container));
    init();
  }

  void init() {
    init(this);
  }

  /** @return new NavigationBar instance */
  public static NavigationBar create() {
    return new NavigationBar();
  }

  /** {@inheritDoc} */
  @Override
  public HTMLElement element() {
    return navBar.element();
  }

  /** @return the {@link HTMLElement} of this component wrapped as {@link DominoElement} */
  public DominoElement getNavBar() {
    return navBar;
  }

  /** @return the title {@link HTMLAnchorElement} wrapped as {@link DominoElement} */
  public DominoElement getTitle() {
    return title;
  }

  /** @return the Menu icon {@link HTMLAnchorElement} wrapped as {@link DominoElement} */
  public DominoElement getMenu() {
    return menu;
  }

  public DominoElement getTopBar() {
    return topBar;
  }

  /**
   * @return the action container {@link HTMLDivElement} at the right side wrapped as {@link
   *     DominoElement}
   */
  public DominoElement getTopBarContainer() {
    return topBarContainer;
  }

  /** @return the main container {@link HTMLDivElement} wrapped as {@link DominoElement} */
  public DominoElement getNavBarHeader() {
    return navBarHeader;
  }

  /** @return the {@link FlexItem} that contains the menu toggle icon */
  public FlexItem getMenuToggleItem() {
    return menuToggleItem;
  }

  /** @return the {@link FlexItem} that contains the logoItem */
  public FlexItem getLogoItem() {
    return logoItem;
  }

  /** @return The {@link FlexItem} contains the actions bar */
  public FlexItem getActionBarItem() {
    return actionBarItem;
  }

  /** @return the {@link FlexItem} contains the title */
  public FlexItem getTitleItem() {
    return titleItem;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy