Search in sources :

Example 21 with MenuItem

use of com.vaadin.flow.component.contextmenu.MenuItem in project docs by vaadin.

the class MenuBarIcons method createIconItem.

private MenuItem createIconItem(HasMenuItems menu, VaadinIcon iconName, String label, String ariaLabel, boolean isChild) {
    Icon icon = new Icon(iconName);
    if (isChild) {
        icon.getStyle().set("width", "var(--lumo-icon-size-s)");
        icon.getStyle().set("height", "var(--lumo-icon-size-s)");
        icon.getStyle().set("marginRight", "var(--lumo-space-s)");
    }
    MenuItem item = menu.addItem(icon, e -> {
    });
    if (ariaLabel != null) {
        item.getElement().setAttribute("aria-label", ariaLabel);
    }
    if (label != null) {
        item.add(new Text(label));
    }
    return item;
}
Also used : MenuItem(com.vaadin.flow.component.contextmenu.MenuItem) Text(com.vaadin.flow.component.Text) VaadinIcon(com.vaadin.flow.component.icon.VaadinIcon) Icon(com.vaadin.flow.component.icon.Icon)

Example 22 with MenuItem

use of com.vaadin.flow.component.contextmenu.MenuItem in project docs by vaadin.

the class MenuBarOverflow method addItems.

private void addItems(MenuBar menuBar) {
    menuBar.addItem("View");
    menuBar.addItem("Edit");
    MenuItem share = menuBar.addItem("Share");
    SubMenu shareSubMenu = share.getSubMenu();
    MenuItem onSocialMedia = shareSubMenu.addItem("On social media");
    SubMenu socialMediaSubMenu = onSocialMedia.getSubMenu();
    socialMediaSubMenu.addItem("Facebook");
    socialMediaSubMenu.addItem("Twitter");
    socialMediaSubMenu.addItem("Instagram");
    shareSubMenu.addItem("By email");
    shareSubMenu.addItem("Get Link");
    MenuItem move = menuBar.addItem("Move");
    SubMenu moveSubMenu = move.getSubMenu();
    moveSubMenu.addItem("To folder");
    moveSubMenu.addItem("To trash");
    menuBar.addItem("Duplicate");
}
Also used : MenuItem(com.vaadin.flow.component.contextmenu.MenuItem) SubMenu(com.vaadin.flow.component.contextmenu.SubMenu)

Example 23 with MenuItem

use of com.vaadin.flow.component.contextmenu.MenuItem in project flow-components by vaadin.

the class ContextMenuPage method addContextMenuWithCheckableItem.

private void addContextMenuWithCheckableItem() {
    Paragraph target = new Paragraph("Target for context menu with checkable item");
    target.setId("context-menu-checkable-item-target");
    Paragraph message = new Paragraph();
    message.setId("checked-message");
    ContextMenu contextMenu = new ContextMenu();
    contextMenu.setTarget(target);
    MenuItem item = contextMenu.addItem("checkable", event -> message.setText("" + event.getSource().isChecked()));
    NativeButton toggleCheckable = new NativeButton("Toggle checkable", event -> item.setCheckable(!item.isCheckable()));
    toggleCheckable.setId("toggle-checkable");
    MenuItem initiallyChecked = contextMenu.addItem("initially checked");
    initiallyChecked.setCheckable(true);
    initiallyChecked.setChecked(true);
    add(target, message, toggleCheckable);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) ContextMenu(com.vaadin.flow.component.contextmenu.ContextMenu) MenuItem(com.vaadin.flow.component.contextmenu.MenuItem) Paragraph(com.vaadin.flow.component.html.Paragraph)

Example 24 with MenuItem

use of com.vaadin.flow.component.contextmenu.MenuItem in project flow-components by vaadin.

the class ContextMenuView method addContextMenuWithComponentsInSubMenu.

private void addContextMenuWithComponentsInSubMenu() {
    Component target = createTargetComponent();
    ContextMenu contextMenu = new ContextMenu(target);
    Label message = new Label("-");
    contextMenu.addItem(new H5("First menu item"), event -> message.setText("Clicked on the first item"));
    MenuItem subMenuItem = contextMenu.addItem("SubMenu Item");
    SubMenu subMenu = subMenuItem.getSubMenu();
    Checkbox checkbox = new Checkbox("Checkbox");
    subMenu.addItem(checkbox, event -> message.setText("Clicked on checkbox with value: " + checkbox.getValue()));
    subMenu.addItem("TextItem", event -> message.setText("Clicked on text item"));
    // Components can also be added to the submenu overlay
    // without creating menu items with add()
    subMenu.addComponentAtIndex(1, new Hr());
    subMenu.add(new Label("This is not a menu item"));
    addCard("ContextMenu With Components in Sub Menu", target, message);
    target.setId("context-menu-with-submenu-components-target");
    contextMenu.setId("context-menu-with-submenu-components");
    message.setId("context-menu-with-submenu-components-message");
}
Also used : Checkbox(com.vaadin.flow.component.checkbox.Checkbox) Label(com.vaadin.flow.component.html.Label) ContextMenu(com.vaadin.flow.component.contextmenu.ContextMenu) MenuItem(com.vaadin.flow.component.contextmenu.MenuItem) SubMenu(com.vaadin.flow.component.contextmenu.SubMenu) Hr(com.vaadin.flow.component.html.Hr) Component(com.vaadin.flow.component.Component) H5(com.vaadin.flow.component.html.H5)

Example 25 with MenuItem

use of com.vaadin.flow.component.contextmenu.MenuItem in project flow-components by vaadin.

the class ContextMenuView method addCheckableMenuItems.

private void addCheckableMenuItems() {
    ContextMenu contextMenu = new ContextMenu();
    Component target = createTargetComponent();
    contextMenu.setTarget(target);
    Label message = new Label("-");
    MenuItem item1 = contextMenu.addItem("Option 1", event -> {
        if (event.getSource().isChecked()) {
            message.setText("Selected option 1");
        } else {
            message.setText("Unselected option 1");
        }
    });
    item1.setCheckable(true);
    MenuItem item2 = contextMenu.addItem("Option 2", event -> {
        if (event.getSource().isChecked()) {
            message.setText("Selected option 2");
        } else {
            message.setText("Unselected option 2");
        }
    });
    item2.setCheckable(true);
    item2.setChecked(true);
    addCard("Checkable Menu Items", target, message);
    target.setId("checkable-menu-items-target");
    message.setId("checkable-menu-items-message");
}
Also used : Label(com.vaadin.flow.component.html.Label) ContextMenu(com.vaadin.flow.component.contextmenu.ContextMenu) MenuItem(com.vaadin.flow.component.contextmenu.MenuItem) Component(com.vaadin.flow.component.Component)

Aggregations

MenuItem (com.vaadin.flow.component.contextmenu.MenuItem)27 MenuBar (com.vaadin.flow.component.menubar.MenuBar)9 Test (org.junit.jupiter.api.Test)8 ContextMenu (com.vaadin.flow.component.contextmenu.ContextMenu)6 Label (com.vaadin.flow.component.html.Label)6 Component (com.vaadin.flow.component.Component)5 SubMenu (com.vaadin.flow.component.contextmenu.SubMenu)5 Text (com.vaadin.flow.component.Text)2 Button (com.vaadin.flow.component.button.Button)2 Hr (com.vaadin.flow.component.html.Hr)2 Span (com.vaadin.flow.component.html.Span)2 Icon (com.vaadin.flow.component.icon.Icon)2 VaadinIcon (com.vaadin.flow.component.icon.VaadinIcon)2 Registration (com.vaadin.flow.shared.Registration)2 Test (org.junit.Test)2 AttachEvent (com.vaadin.flow.component.AttachEvent)1 ComponentEvent (com.vaadin.flow.component.ComponentEvent)1 ComponentEventListener (com.vaadin.flow.component.ComponentEventListener)1 DetachEvent (com.vaadin.flow.component.DetachEvent)1 UI (com.vaadin.flow.component.UI)1