org.dominokit.domino.ui.menu.MenuItem Maven / Gradle / Ivy
/*
* 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.menu;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
import static org.dominokit.domino.ui.utils.Domino.*;
import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Collectors;
import org.dominokit.domino.ui.elements.AnchorElement;
import org.dominokit.domino.ui.elements.SmallElement;
import org.dominokit.domino.ui.elements.SpanElement;
import org.dominokit.domino.ui.utils.ChildHandler;
/**
* Represents a menu item that can be added to a menu. Each menu item can have a text and an
* optional description.
*
* @param the type of value associated with this menu item
*/
public class MenuItem extends AbstractMenuItem {
private SmallElement descriptionElement;
private SpanElement textElement;
/**
* Creates a menu item with the specified text.
*
* @param text the text for the menu item
* @return the created menu item
*/
public static MenuItem create(String text) {
return new MenuItem<>(text);
}
/**
* Creates a menu item with the specified text and description.
*
* @param text the text for the menu item
* @param description the description for the menu item
* @return the created menu item
*/
public static MenuItem create(String text, String description) {
return new MenuItem<>(text, description);
}
/**
* Constructs a menu item with the specified text.
*
* @param text the text for the menu item
*/
public MenuItem(String text) {
if (nonNull(text) && !text.isEmpty()) {
textElement = span().addCss(dui_menu_item_content).setTextContent(text);
appendChild(textElement);
}
this.searchFilter = this::containsToken;
}
/**
* Applies a custom child handler to the link element of this menu item
*
* @param handler The child handler to apply.
* @return This menu item instance.
*/
public MenuItem withClickableElement(ChildHandler
© 2015 - 2025 Weber Informatics LLC | Privacy Policy