vaadin / web-components

A set of high-quality standards based web components for enterprise web applications. Part of Vaadin 20+
https://vaadin.com/docs/latest/components
470 stars 83 forks source link

[notification] Utility method for creating notification with action button #891

Open manolo opened 6 years ago

manolo commented 6 years ago

Something like: Vaadin.Notification.createAction('Foo Bar Baz', callback)

Related with vaadin/vaadin-notification#18

rolandoisidoro commented 4 years ago

Any news on this? A dismissible notification is a very common use case. Here's a workaround code snippet:

Code

Notification notification = new Notification();      
notification.addThemeVariants(NotificationVariant.LUMO_PRIMARY);
notification.setPosition(Notification.Position.TOP_CENTER);

HorizontalLayout notificationContent = new HorizontalLayout(
    new Label("Horizontal layout with a label with some misc text and "
        + "a Vaadin icon with a click listener to close the notification."),
    new Button(VaadinIcon.CLOSE_SMALL.create(), e -> notification.close())
);
notificationContent.setAlignItems(Alignment.CENTER);

notification.add(notificationContent);
notification.open();

Result

image

jouni commented 3 years ago

The special case for dismiss button is cover in vaadin/web-components#438

But we might still want another convenience API for adding an action button, for example, an “Undo” button, in addition to the dismiss button.