Search in sources :

Example 16 with MenuItem

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

the class ThemeVariantToggleMenuItemDefinition method createItem.

@Override
public MenuItem createItem(SubMenu subMenu) {
    MenuItem createdItem = super.createItem(subMenu);
    createdItem.setCheckable(true);
    createdItem.setChecked(UI.getCurrent().getElement().getThemeList().contains(variantName));
    return toggleThemeOnClick(createdItem);
}
Also used : MenuItem(com.vaadin.flow.component.contextmenu.MenuItem)

Example 17 with MenuItem

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

the class ApplicationHeader method addHelpMenu.

/**
 * Creates a help menu item in the given parent.
 *
 * @implNote Override {@link #addHelpMenuItems(MenuItem)} to add sub menu items to the created
 *           {@link #addHelpMenu(MenuBar) help menu item}.
 */
protected MenuItem addHelpMenu(MenuBar parent) {
    MenuItem helpMenu = parent.addItem(VaadinIcon.QUESTION_CIRCLE.create());
    helpMenu.setId(APPMENU_HELP_ID);
    addHelpMenuItems(helpMenu);
    return helpMenu;
}
Also used : MenuItem(com.vaadin.flow.component.contextmenu.MenuItem)

Example 18 with MenuItem

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

the class PlaygroundApplicationHeader method createRightMenuBar.

// tag::applicationheader-createRightMenuBar[]
@Override
protected MenuBar createRightMenuBar() {
    MenuBar rightMenuBar = super.createRightMenuBar();
    MenuItem settings = rightMenuBar.addItem(VaadinIcon.COG.create());
    settings.setId("appmenu-settings");
    addThemeVariantToggles(settings, ThemeVariantToggleMenuItemDefinition.LUMO_DARK, ThemeVariantToggleMenuItemDefinition.LINKKI_CARD, ThemeVariantToggleMenuItemDefinition.LINKKI_COMPACT);
    // end::applicationheader-createRightMenuBar[]
    new ApplicationMenuItemDefinition("Locale", "appmenu-locale", () -> new PmoBasedDialogFactory().newOkDialog("Browser Locale", new LocaleInfoPmo()).open()).createItem(settings.getSubMenu());
    return rightMenuBar;
}
Also used : PmoBasedDialogFactory(org.linkki.framework.ui.dialogs.PmoBasedDialogFactory) MenuBar(com.vaadin.flow.component.menubar.MenuBar) MenuItem(com.vaadin.flow.component.contextmenu.MenuItem) ApplicationMenuItemDefinition(org.linkki.framework.ui.application.menu.ApplicationMenuItemDefinition)

Example 19 with MenuItem

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

the class ThemeVariantToggleMenuItemDefinitionTest method testCreateItem_SubMenu_ReflectsVariantCheckedInitially.

@Test
void testCreateItem_SubMenu_ReflectsVariantCheckedInitially() {
    MenuItem item = new ApplicationMenu().addItem("item");
    UI.getCurrent().getElement().getThemeList().add("variant");
    new ThemeVariantToggleMenuItemDefinition("name", "id", "variant").createItem(item.getSubMenu());
    assertThat(item.getSubMenu().getItems()).hasSize(1);
    MenuItem createdItem = item.getSubMenu().getItems().get(0);
    assertThat(createdItem.getText()).isEqualTo("name");
    assertThat(createdItem.getId()).hasValue("id");
    assertThat(createdItem.isCheckable()).isTrue();
    assertThat(createdItem.isChecked()).isTrue();
}
Also used : MenuItem(com.vaadin.flow.component.contextmenu.MenuItem) Test(org.junit.jupiter.api.Test)

Example 20 with MenuItem

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

the class MenuBarIconOnly method createIconItem.

// tag::createIcon[]
private MenuItem createIconItem(MenuBar menu, VaadinIcon iconName, String ariaLabel) {
    Icon icon = new Icon(iconName);
    MenuItem item = menu.addItem(icon);
    item.getElement().setAttribute("aria-label", ariaLabel);
    return item;
}
Also used : MenuItem(com.vaadin.flow.component.contextmenu.MenuItem) VaadinIcon(com.vaadin.flow.component.icon.VaadinIcon) Icon(com.vaadin.flow.component.icon.Icon)

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