From 009197b1efcd4467d86142432d7a8389e218d37a Mon Sep 17 00:00:00 2001 From: Tomas Peiretti Date: Wed, 21 Aug 2024 15:13:35 -0300 Subject: [PATCH] feat(demo): add flag-rendering demo --- .../BaseLocaleComboBoxDemo.java | 11 ++++ .../localecombobox/DisplayModeDemo.java | 2 +- .../LocaleComboBoxDemoView.java | 1 + .../addons/localecombobox/RenderingDemo.java | 57 +++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/flowingcode/vaadin/addons/localecombobox/RenderingDemo.java diff --git a/src/test/java/com/flowingcode/vaadin/addons/localecombobox/BaseLocaleComboBoxDemo.java b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/BaseLocaleComboBoxDemo.java index 1f3db62..5e6ccbb 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/localecombobox/BaseLocaleComboBoxDemo.java +++ b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/BaseLocaleComboBoxDemo.java @@ -19,6 +19,7 @@ */ package com.flowingcode.vaadin.addons.localecombobox; +import com.vaadin.flow.component.Component; import com.vaadin.flow.component.Text; import com.vaadin.flow.component.html.Div; import com.vaadin.flow.component.html.Span; @@ -40,5 +41,15 @@ protected HorizontalLayout createHorizontalContainer(String title, LocaleComboBo container.expand(combo); return container; } + + protected HorizontalLayout createHorizontalContainer(Component component, LocaleComboBox combo) { + HorizontalLayout container = new HorizontalLayout(); + container.setWidthFull(); + container.setAlignItems(Alignment.CENTER); + container.setJustifyContentMode(JustifyContentMode.BETWEEN); + container.add(component, combo); + container.expand(combo); + return container; + } } diff --git a/src/test/java/com/flowingcode/vaadin/addons/localecombobox/DisplayModeDemo.java b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/DisplayModeDemo.java index 1bd4676..18d2534 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/localecombobox/DisplayModeDemo.java +++ b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/DisplayModeDemo.java @@ -28,7 +28,7 @@ @DemoSource @PageTitle("Display modes") @SuppressWarnings("serial") -@Route(value = "demo", layout = LocaleComboBoxDemoView.class) +@Route(value = "locale-combo-box/display", layout = LocaleComboBoxDemoView.class) public class DisplayModeDemo extends BaseLocaleComboBoxDemo { public DisplayModeDemo() { diff --git a/src/test/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBoxDemoView.java b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBoxDemoView.java index 60f7f01..d76ba70 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBoxDemoView.java +++ b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBoxDemoView.java @@ -33,6 +33,7 @@ public class LocaleComboBoxDemoView extends TabbedDemo { public LocaleComboBoxDemoView() { addDemo(DisplayModeDemo.class); + addDemo(RenderingDemo.class); setSizeFull(); } } diff --git a/src/test/java/com/flowingcode/vaadin/addons/localecombobox/RenderingDemo.java b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/RenderingDemo.java new file mode 100644 index 0000000..76a4405 --- /dev/null +++ b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/RenderingDemo.java @@ -0,0 +1,57 @@ +/*- + * #%L + * LocaleComboBox Add-on + * %% + * Copyright (C) 2024 Flowing Code + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +package com.flowingcode.vaadin.addons.localecombobox; + +import com.flowingcode.vaadin.addons.demo.DemoSource; +import com.vaadin.flow.component.checkbox.Checkbox; +import com.vaadin.flow.router.PageTitle; +import com.vaadin.flow.router.Route; +import java.util.Locale; + +@DemoSource +@PageTitle("Flag rendering") +@SuppressWarnings("serial") +@Route(value = "locale-combo-box/rendering", layout = LocaleComboBoxDemoView.class) +public class RenderingDemo extends BaseLocaleComboBoxDemo { + public RenderingDemo() { + + LocaleComboBox defaultLocaleCombo = new LocaleComboBox(); + LocaleComboBox flagsLocaleCombo = new LocaleComboBox(); + Checkbox checkbox = new Checkbox("Render flags"); + + defaultLocaleCombo.setValue(Locale.ITALY); + flagsLocaleCombo.setValue(Locale.ITALY); + checkbox.setValue(true); + + /* + * You can choose whether the flags should be displayed alongside the locale names by using the + * setHasFlag method + */ + checkbox.addValueChangeListener(event -> flagsLocaleCombo.setHasFlags(event.getValue())); + + // #if vaadin eq 0 + add(createHorizontalContainer("Flags are rendered by default:", defaultLocaleCombo)); + add(createHorizontalContainer(checkbox, flagsLocaleCombo)); + // #endif + // show-source add(defaultLocaleCombo); + // show-source add(checkbox, flagsLocaleCombo); + + } +}