Search in sources :

Example 1 with H5

use of com.vaadin.flow.component.html.H5 in project flow-components by vaadin.

the class ContextMenuView method addContextMenuWithComponents.

private void addContextMenuWithComponents() {
    Component target = createTargetComponent();
    ContextMenu contextMenu = new ContextMenu(target);
    Label message = new Label("-");
    // Components can be used also inside menu items
    contextMenu.addItem(new H5("First menu item"), e -> message.setText("Clicked on the first item"));
    Checkbox checkbox = new Checkbox("Checkbox");
    contextMenu.addItem(checkbox, e -> message.setText("Clicked on checkbox with value: " + checkbox.getValue()));
    // Components can also be added to the overlay
    // without creating menu items with add()
    Component separator = new Hr();
    contextMenu.add(separator, new Label("This is not a menu item"));
    addCard("ContextMenu With Components", target, message);
    target.setId("context-menu-with-components-target");
    contextMenu.setId("context-menu-with-components");
    message.setId("context-menu-with-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) Hr(com.vaadin.flow.component.html.Hr) Component(com.vaadin.flow.component.Component) H5(com.vaadin.flow.component.html.H5)

Example 2 with H5

use of com.vaadin.flow.component.html.H5 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)

Aggregations

Component (com.vaadin.flow.component.Component)2 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)2 ContextMenu (com.vaadin.flow.component.contextmenu.ContextMenu)2 H5 (com.vaadin.flow.component.html.H5)2 Hr (com.vaadin.flow.component.html.Hr)2 Label (com.vaadin.flow.component.html.Label)2 MenuItem (com.vaadin.flow.component.contextmenu.MenuItem)1 SubMenu (com.vaadin.flow.component.contextmenu.SubMenu)1