Skip to content

Commit

Permalink
feat: create completely new Popup demostration
Browse files Browse the repository at this point in the history
  • Loading branch information
bwajtr committed Aug 6, 2023
1 parent db5a03d commit 57b9819
Show file tree
Hide file tree
Showing 10 changed files with 423 additions and 462 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@

<name>Popup Root</name>

<properties>
<vaadin.version>24.0.0</vaadin.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<inceptionYear>2019</inceptionYear>
<organization>
<name>Vaadin Ltd</name>
Expand Down
31 changes: 7 additions & 24 deletions popup-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
<vaadin.version>23.3.12</vaadin.version>
<flow.version>9.0.26</flow.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -49,15 +48,15 @@
<artifactId>popup</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-component-demo-helpers</artifactId>
<version>${flow.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>

<build>
Expand All @@ -79,7 +78,7 @@
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<scanIntervalSeconds>1</scanIntervalSeconds>
<!-- <scanIntervalSeconds>1</scanIntervalSeconds>-->
</configuration>
</plugin>
<plugin>
Expand All @@ -98,21 +97,6 @@
</execution>
</executions>
</plugin>
<!-- <plugin> -->
<!-- <groupId>com.github.eirslett</groupId> -->
<!-- <artifactId>frontend-maven-plugin</artifactId> -->
<!-- <version>1.7.6</version> -->
<!-- <executions> -->
<!-- <execution> -->
<!-- <goals> -->
<!-- <goal>install-node-and-npm</goal> -->
<!-- </goals> -->
<!-- </execution> -->
<!-- </executions> -->
<!-- <configuration> -->
<!-- <nodeVersion>v16.13.0</nodeVersion> -->
<!-- </configuration> -->
<!-- </plugin> -->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
Expand All @@ -133,7 +117,6 @@
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-server-production-mode</artifactId>
<version>${flow.version}</version>
</dependency>
</dependencies>

Expand All @@ -147,7 +130,7 @@
<execution>
<goals>
<goal>prepare-frontend</goal>
<goal>build-frontend</goal>
<goal>build-frontend</goal>
</goals>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.vaadin.componentfactory.popup.demo;

import com.vaadin.componentfactory.popup.demo.views.*;
import com.vaadin.flow.component.applayout.AppLayout;
import com.vaadin.flow.component.applayout.DrawerToggle;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.RouterLink;

public class MainLayout extends AppLayout {

public MainLayout() {
final DrawerToggle drawerToggle = new DrawerToggle();

final RouterLink basicUsages = new RouterLink("Popup basic usage", PopupBasicUsageView.class);
final RouterLink headerAndFooter = new RouterLink("Header and Footer", HeaderAndFooterView.class);
final RouterLink popupInGrid = new RouterLink("Popup in Grid", PopupGridView.class);
final RouterLink onboardingDemo = new RouterLink("Onboarding Demo", OnboardingView.class);

final VerticalLayout menuLayout = new VerticalLayout(basicUsages, headerAndFooter, popupInGrid, onboardingDemo);
addToDrawer(menuLayout);
addToNavbar(drawerToggle);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.vaadin.componentfactory.popup.demo.content;

import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;

public class LongPopupContent extends VerticalLayout {

public LongPopupContent() {
add(new Span("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam at arcu a est sollicitudin euismod. Nunc tincidunt ante vitae massa. Et harum quidem rerum facilis est et expedita distinctio. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."));
add(new HorizontalLayout(new Button("Action 1"), new Button("Action 2")));
add(new Span("Lorem ipsum dolor sit amet. Donec ipsum massa, ullamcorper in, auctor et, scelerisque sed, est. Duis viverra diam non justo. Nulla est. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus."));
setMaxWidth("25rem");
setMaxHeight("20rem");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.vaadin.componentfactory.popup.demo.views;

import com.vaadin.componentfactory.Popup;
import com.vaadin.componentfactory.popup.demo.MainLayout;
import com.vaadin.componentfactory.popup.demo.content.LongPopupContent;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.html.H3;
import com.vaadin.flow.component.html.Paragraph;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.theme.lumo.LumoIcon;

@Route(value = "header-footer", layout = MainLayout.class)
@CssImport(value = "./styles/custom-popup-style.css", themeFor = "vcf-popup-overlay")
public class HeaderAndFooterView extends VerticalLayout {

public HeaderAndFooterView() {
add(new H3("Add header and footer to Popup"));

addViewDescription();

VerticalLayout buttonLayout = new VerticalLayout();
buttonLayout.setSpacing(false);
buttonLayout.setPadding(false);
addSimpleTextInHeaderExample(buttonLayout);
addTextAndCloseButtonInHeaderExample(buttonLayout);
addHeaderAndFooterExample(buttonLayout);
addStyledHeaderAndFooterExample(buttonLayout);
add(buttonLayout);
}

private void addSimpleTextInHeaderExample(VerticalLayout layout) {
Button button = new Button("Show popup with simple textual header");
Popup popup = createDefaultPopup(button, layout);
popup.setHeaderTitle("This is title");
layout.add(button);
}

private void addTextAndCloseButtonInHeaderExample(VerticalLayout layout) {
Button button = new Button("Show popup with textual header and close button");
Popup popup = createDefaultPopup(button, layout);
popup.setHeaderTitle("This is title");
addCloseButtonToHeader(popup);
layout.add(button);
}

private void addHeaderAndFooterExample(VerticalLayout layout) {
Button button = new Button("Header and footer example");
Popup popup = createDefaultPopup(button, layout);
popup.setHeaderTitle("This is title");
addCloseButtonToHeader(popup);
addOkAndCancelToFooter(popup);
layout.add(button);
}

private void addStyledHeaderAndFooterExample(VerticalLayout layout) {
Button button = new Button("Header and footer with custom styling");
Popup popup = createDefaultPopup(button, layout);
popup.setThemeName("custom-popup-style");
popup.setHeaderTitle("This is title");
addOkAndCancelToFooter(popup);
layout.add(button);
}

private void addOkAndCancelToFooter(Popup popup) {
Button cancel = new Button("Cancel");
Button apply = new Button("Ok");
apply.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
popup.getFooter().add(cancel, apply);
}

private void addCloseButtonToHeader(Popup popup) {
Button closeBtn = new Button(LumoIcon.CROSS.create());
closeBtn.addClickListener(e -> popup.hide());
closeBtn.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
popup.getHeader().add(closeBtn);
}

private void addViewDescription() {
add(new Paragraph("This demo showcases a possibility to easily define a header and a footer for the Popup. " +
"You can use the `setHeaderTitle` method to quickly define the header title text. If you need more complicated header content " +
"you can use the `getHeader` method to get the header component and add your own content to it using `getHeader.add(Component)`. " +
"The same applies to the footer - add components (for example buttons) to the footer using `getFooter.add(Component)`."));
}

private Popup createDefaultPopup(Component forComponent, VerticalLayout layout) {
Popup popup = new Popup();
popup.add(new LongPopupContent());
popup.setTarget(forComponent.getElement());
layout.add(popup);
return popup;
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
package com.vaadin.componentfactory.vaadincom;
package com.vaadin.componentfactory.popup.demo.views;

import com.vaadin.componentfactory.PopupPosition;
import com.vaadin.componentfactory.onboarding.Onboarding;
import com.vaadin.componentfactory.onboarding.OnboardingStep;
import com.vaadin.componentfactory.popup.demo.MainLayout;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.html.H3;
import com.vaadin.flow.component.html.Image;
import com.vaadin.flow.component.html.Paragraph;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.Route;

@Route(value = "onboarding", layout = OnboardingLayout.class)
@Route(value = "onboarding", layout = MainLayout.class)
public class OnboardingView extends VerticalLayout {

public OnboardingView() {
final H3 header = new H3("Lorem Ipsum");
final H3 header = new H3("How to use Popup to create an onboarding experience");
add(header);

final Paragraph paragraph = new Paragraph("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publis");
final Paragraph paragraph = new Paragraph("The idea is to use the Popup component to create a simple" +
" Onboarding (also known as Walkthrough) experience for the user. A simple API was created as part of " +
"the component to make it easy to create such onboarding. There are two classes: Onboarding and OnboardingStep. " +
"To use it, create an instance of the Onboarding class and fill it with the OnboardingSteps. In the simplest form, " +
"you only have to provide three things for each OnboardingStep: a target element, a header text, and a content text.");
add(paragraph);

final Button makePurchase = new Button("Make purchase");
add(makePurchase);
final Button actionButton = new Button("Some Action");
add(actionButton);

Onboarding onboarding = createOnboarding(header, paragraph, makePurchase);
final Button startOnboarding = new Button("Start onboarding", event -> {
onboarding.start();
});
Onboarding onboarding = createOnboarding(header, paragraph, actionButton);
final Button startOnboarding = new Button("Start onboarding", event -> onboarding.start());
startOnboarding.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
add(startOnboarding);
}
Expand All @@ -52,9 +56,18 @@ private OnboardingStep createStep4() {

private OnboardingStep createStep3(Button makePurchase) {
final OnboardingStep onboardingStep3 = new OnboardingStep(makePurchase);
onboardingStep3.setHeader("Long text popup - having max-width");
onboardingStep3.setContent("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc at turpis nec nisl lobortis convallis. Curabitur nec ipsum mauris. Proin vitae consectetur justo, sit amet ultricies ex. Proin posuere sem vel nunc lobortis lacinia. Quisque est felis, gravida in hendrerit sagittis, egestas tempor ante. Etiam vulputate urna lorem, eget rutrum sem auctor eget. Aliquam fringilla ut lacus a consectetur. Ut congue vitae quam nec suscipit. Mauris lacinia libero ex, non porttitor nisi elementum sit amet.");
onboardingStep3.getContent().getElement().getStyle().set("max-width", "40rem");
onboardingStep3.setHeader("Popup with rich content");

VerticalLayout content = new VerticalLayout();
content.setWidthFull();
content.add(new Paragraph("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc at turpis nec nisl lobortis convallis. Curabitur nec ipsum mauris. Proin vitae consectetur justo, sit amet ultricies ex. Proin posuere sem vel nunc lobortis lacinia. Quisque est felis, gravida in hendrerit sagittis, egestas tempor ante. Etiam vulputate urna lorem, eget rutrum sem auctor eget. Aliquam fringilla ut lacus a consectetur. Ut congue vitae quam nec suscipit. Mauris lacinia libero ex, non porttitor nisi elementum sit amet."));
final Image vaadinLogo = new Image("https://vaadin.com/images/trademark/PNG/VaadinLogo_RGB_500x155.png", "Vaadin Logo");
vaadinLogo.setWidth("15rem");
content.add(vaadinLogo);
content.add(new Paragraph("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc at turpis nec nisl lobortis convallis. Curabitur nec ipsum mauris."));
onboardingStep3.setContent(content);
onboardingStep3.getContent().getElement().getStyle().set("max-width", "30rem");

return onboardingStep3;
}

Expand All @@ -69,15 +82,13 @@ private OnboardingStep createStep2(Paragraph paragraph) {
private OnboardingStep createStep1(H3 header) {
final OnboardingStep onboardingStep1 = new OnboardingStep(header);
onboardingStep1.setHeader("Start here");
onboardingStep1.setContent("This popup is customized using the addBeforePopupShown listener - 'More info' button is added to the footer.");
onboardingStep1.setContent("You can associate the Onboarding Step with any Component on the screen. Note: This popup is customized using the addBeforePopupShown listener - 'More info' button is added to the footer.");
onboardingStep1.addBeforePopupShownListener(popup -> {
final Button moreInfo = new Button("More info");
moreInfo.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
moreInfo.getElement().getStyle().set("position", "absolute");
moreInfo.getElement().getStyle().set("left", "var(--lumo-space-l)");
moreInfo.addClickListener(event -> {
Notification.show("Some action");
});
moreInfo.addClickListener(event -> Notification.show("Some action"));
popup.getFooter().add(moreInfo);
});
return onboardingStep1;
Expand Down
Loading

0 comments on commit 57b9819

Please sign in to comment.