Skip to content

Commit 354ec35

Browse files
elPeirettijavier-godoy
authored andcommitted
feat(demo): add flag-rendering demo
1 parent 8b586ea commit 354ec35

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

src/test/java/com/flowingcode/vaadin/addons/localecombobox/BaseLocaleComboBoxDemo.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
package com.flowingcode.vaadin.addons.localecombobox;
2121

22+
import com.vaadin.flow.component.Component;
2223
import com.vaadin.flow.component.Text;
2324
import com.vaadin.flow.component.html.Div;
2425
import com.vaadin.flow.component.html.Span;
@@ -40,5 +41,15 @@ protected HorizontalLayout createHorizontalContainer(String title, LocaleComboBo
4041
container.expand(combo);
4142
return container;
4243
}
44+
45+
protected HorizontalLayout createHorizontalContainer(Component component, LocaleComboBox combo) {
46+
HorizontalLayout container = new HorizontalLayout();
47+
container.setWidthFull();
48+
container.setAlignItems(Alignment.CENTER);
49+
container.setJustifyContentMode(JustifyContentMode.BETWEEN);
50+
container.add(component, combo);
51+
container.expand(combo);
52+
return container;
53+
}
4354

4455
}

src/test/java/com/flowingcode/vaadin/addons/localecombobox/DisplayModeDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
@DemoSource
3131
@PageTitle("Display modes")
3232
@SuppressWarnings("serial")
33-
@Route(value = "demo", layout = LocaleComboBoxDemoView.class)
33+
@Route(value = "locale-combo-box/display", layout = LocaleComboBoxDemoView.class)
3434
public class DisplayModeDemo extends BaseLocaleComboBoxDemo {
3535

3636
public DisplayModeDemo() {

src/test/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBoxDemoView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class LocaleComboBoxDemoView extends TabbedDemo {
3333

3434
public LocaleComboBoxDemoView() {
3535
addDemo(DisplayModeDemo.class);
36+
addDemo(RenderingDemo.class);
3637
setSizeFull();
3738
}
3839
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*-
2+
* #%L
3+
* LocaleComboBox Add-on
4+
* %%
5+
* Copyright (C) 2024 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.localecombobox;
21+
22+
import com.flowingcode.vaadin.addons.demo.DemoSource;
23+
import com.vaadin.flow.component.checkbox.Checkbox;
24+
import com.vaadin.flow.router.PageTitle;
25+
import com.vaadin.flow.router.Route;
26+
import java.util.Locale;
27+
28+
@DemoSource
29+
@PageTitle("Flag rendering")
30+
@SuppressWarnings("serial")
31+
@Route(value = "locale-combo-box/rendering", layout = LocaleComboBoxDemoView.class)
32+
public class RenderingDemo extends BaseLocaleComboBoxDemo {
33+
public RenderingDemo() {
34+
35+
LocaleComboBox defaultLocaleCombo = new LocaleComboBox();
36+
LocaleComboBox flagsLocaleCombo = new LocaleComboBox();
37+
Checkbox checkbox = new Checkbox("Render flags");
38+
39+
defaultLocaleCombo.setValue(Locale.ITALY);
40+
flagsLocaleCombo.setValue(Locale.ITALY);
41+
checkbox.setValue(true);
42+
43+
/*
44+
* You can choose whether the flags should be displayed alongside the locale names by using the
45+
* setHasFlag method
46+
*/
47+
checkbox.addValueChangeListener(event -> flagsLocaleCombo.setHasFlags(event.getValue()));
48+
49+
// #if vaadin eq 0
50+
add(createHorizontalContainer("Flags are rendered by default:", defaultLocaleCombo));
51+
add(createHorizontalContainer(checkbox, flagsLocaleCombo));
52+
// #endif
53+
// show-source add(defaultLocaleCombo);
54+
// show-source add(checkbox, flagsLocaleCombo);
55+
56+
}
57+
}

0 commit comments

Comments
 (0)