Skip to content

Commit 870e973

Browse files
elPeirettipaodb
authored andcommitted
feat: initial implementation
1 parent 3525905 commit 870e973

File tree

16 files changed

+163
-71
lines changed

16 files changed

+163
-71
lines changed

.github/ISSUE_TEMPLATE/bug-report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Bug Report
2-
description: Please report issues related to TEMPLATE_ADDON here.
2+
description: Please report issues related to LocaleComboBox add-on here.
33
body:
44
- type: textarea
55
id: problem-description

.github/ISSUE_TEMPLATE/feature-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Feature Request
2-
description: Please add feature suggestions related to TEMPLATE_ADDON here.
2+
description: Please add feature suggestions related to LocaleComboBox add-on here.
33
body:
44
- type: textarea
55
id: feature-proposal

README.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
[![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0.svg)](https://vaadin.com/directory/component/template-addon)
2-
[![Stars on vaadin.com/directory](https://img.shields.io/vaadin-directory/star/template-addon.svg)](https://vaadin.com/directory/component/template-addon)
3-
[![Build Status](https://jenkins.flowingcode.com/job/template-addon/badge/icon)](https://jenkins.flowingcode.com/job/template-addon)
4-
[![Maven Central](https://img.shields.io/maven-central/v/com.flowingcode.vaadin.addons/template-addon)](https://mvnrepository.com/artifact/com.flowingcode.vaadin.addons/template-addon)
1+
[![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0.svg)](https://vaadin.com/directory/component/locale-combo-box-add-on)
2+
[![Stars on vaadin.com/directory](https://img.shields.io/vaadin-directory/star/locale-combo-box-add-on.svg)](https://vaadin.com/directory/component/locale-combo-box-add-on)
3+
[![Build Status](https://jenkins.flowingcode.com/job/LocaleComboBox-addon/badge/icon)](https://jenkins.flowingcode.com/job/LocaleComboBox-addon)
4+
[![Maven Central](https://img.shields.io/maven-central/v/com.flowingcode.vaadin.addons/locale-combo-box-addon)](https://mvnrepository.com/artifact/com.flowingcode.vaadin.addons/locale-combo-box-addon)
55

6-
# Template Add-on
6+
# LocaleComboBox Add-on
77

8-
This is a template project for building new Vaadin 24 add-ons
8+
[Vaadin ComboBox](https://vaadin.com/docs/latest/components/combo-box) extension that allows to choose between multiple locales.
99

1010
## Features
1111

12-
* List the features of your add-on in here
12+
* Displays the locale name alongside its corresponding country flag
13+
* Allows to specify which locales are available for selection
14+
* Provides an option to change the current session locale
1315

1416
## Online demo
1517

16-
[Online demo here](http://addonsv24.flowingcode.com/template)
18+
[Online demo here](http://addonsv24.flowingcode.com/locale-combo-box)
1719

1820
## Download release
1921

20-
[Available in Vaadin Directory](https://vaadin.com/directory/component/template-addon)
22+
[Available in Vaadin Directory](https://vaadin.com/directory/component/locale-combo-box-add-on)
2123

2224
### Maven install
2325

@@ -26,11 +28,10 @@ Add the following dependencies in your pom.xml file:
2628
```xml
2729
<dependency>
2830
<groupId>com.flowingcode.vaadin.addons</groupId>
29-
<artifactId>template-addon</artifactId>
31+
<artifactId>locale-combo-box-addon</artifactId>
3032
<version>X.Y.Z</version>
3133
</dependency>
3234
```
33-
<!-- the above dependency should be updated with latest released version information -->
3435

3536
```xml
3637
<repository>
@@ -50,7 +51,7 @@ To see the demo, navigate to http://localhost:8080/
5051

5152
## Release notes
5253

53-
See [here](https://github.com/FlowingCode/TemplateAddon/releases)
54+
See [here](https://github.com/FlowingCode/LocaleComboBox/releases)
5455

5556
## Issue tracking
5657

@@ -75,13 +76,11 @@ Then, follow these steps for creating a contribution:
7576

7677
This add-on is distributed under Apache License 2.0. For license terms, see LICENSE.txt.
7778

78-
TEMPLATE_ADDON is written by Flowing Code S.A.
79+
LocaleComboBox Add-on is written by Flowing Code S.A.
7980

8081
# Developer Guide
8182

82-
## Getting started
83-
84-
Add your code samples in this section
83+
<!-- TODO: ## Getting started -->
8584

8685
## Special configuration when using Spring
8786

pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
<modelVersion>4.0.0</modelVersion>
66

77
<groupId>com.flowingcode.vaadin.addons</groupId>
8-
<artifactId>template-addon</artifactId>
8+
<artifactId>locale-combo-box-addon</artifactId>
99
<version>1.0.0-SNAPSHOT</version>
10-
<name>Template Add-on</name>
11-
<description>Template Add-on for Vaadin Flow</description>
10+
<name>LocaleComboBox</name>
11+
<description>LocaleComboBox Add-on for Vaadin Flow</description>
1212
<url>https://www.flowingcode.com/en/open-source/</url>
1313

1414
<properties>
@@ -39,9 +39,9 @@
3939
</licenses>
4040

4141
<scm>
42-
<url>https://github.com/FlowingCode/AddonStarter24</url>
43-
<connection>scm:git:git://github.com/FlowingCode/AddonStarter24.git</connection>
44-
<developerConnection>scm:git:ssh://[email protected]:/FlowingCode/AddonStarter24.git</developerConnection>
42+
<url>https://github.com/FlowingCode/LocaleComboBox</url>
43+
<connection>scm:git:git://github.com/FlowingCode/LocaleComboBox.git</connection>
44+
<developerConnection>scm:git:ssh://[email protected]:/FlowingCode/LocaleComboBox.git</developerConnection>
4545
<tag>master</tag>
4646
</scm>
4747

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
21+
package com.flowingcode.vaadin.addons.localecombobox;
22+
23+
import com.vaadin.flow.component.combobox.ComboBox;
24+
import com.vaadin.flow.component.dependency.CssImport;
25+
import com.vaadin.flow.component.dependency.NpmPackage;
26+
import com.vaadin.flow.component.html.Span;
27+
import com.vaadin.flow.data.renderer.LitRenderer;
28+
import java.util.Arrays;
29+
import java.util.Locale;
30+
31+
/**
32+
* Vaadin ComboBox extension that allows to choose between multiple locales.
33+
*
34+
* @author Tomas Peiretti / Flowing Code
35+
*/
36+
@SuppressWarnings("serial")
37+
@NpmPackage(value = "flag-icons", version = "7.2.3")
38+
@CssImport("flag-icons/css/flag-icons.min.css")
39+
@CssImport("styles/locale-combo-box.css")
40+
public class LocaleComboBox extends ComboBox<Locale> {
41+
42+
private static final String ITEM_LAYOUT_CLASS_NAME = "fc-locale-combo-box-item-layout";
43+
private static final String ITEM_FLAG_CLASS_NAME = "fc-locale-combo-box-item-flag";
44+
45+
/**
46+
* Creates a new instance of LocaleComboBox with all the installed locales.
47+
*/
48+
public LocaleComboBox() {
49+
setItemLabelGenerator(Locale::getDisplayName);
50+
setRenderer(getLocaleRenderer());
51+
addValueChangeListener(this::onValueChange);
52+
setItems(
53+
Arrays.stream(Locale.getAvailableLocales()).filter(loc -> loc.getCountry().length() == 2)
54+
.sorted((l1, l2) -> l1.getDisplayName().compareTo(l2.getDisplayName())).toList());
55+
}
56+
57+
private LitRenderer<Locale> getLocaleRenderer() {
58+
return LitRenderer
59+
.<Locale>of("<vaadin-horizontal-layout class=\"" + ITEM_LAYOUT_CLASS_NAME + "\">"
60+
+ "<span class=\"fi fi-${item.countryCode} " + ITEM_FLAG_CLASS_NAME
61+
+ "\" alt=\"${item.countryName}\'s flag\"></span>" + "<span>${item.displayName}</span>"
62+
+ "</vaadin-horizontal-layout>")
63+
.withProperty("countryCode", loc -> loc.getCountry().toLowerCase())
64+
.withProperty("countryName", loc -> loc.getDisplayCountry())
65+
.withProperty("displayName", loc -> loc.getDisplayName());
66+
}
67+
68+
private void onValueChange(ComponentValueChangeEvent<ComboBox<Locale>, Locale> event) {
69+
Locale newValue = event.getValue();
70+
if (newValue == null) {
71+
setPrefixComponent(null);
72+
return;
73+
}
74+
Span flagIcon = new Span();
75+
flagIcon.addClassNames("fi", "fi-" + newValue.getCountry().toLowerCase());
76+
setPrefixComponent(flagIcon);
77+
}
78+
79+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
vaadin-horizontal-layout.fc-locale-combo-box-item-layout {
21+
align-items: center;
22+
justify-content: start;
23+
gap: 0.5em;
24+
}
25+
26+
span.fc-locale-combo-box-item-flag {
27+
flex-shrink: 0;
28+
}

src/main/resources/META-INF/frontend/styles/static_addon_styles

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/main/resources/META-INF/resources/static_addon_resources

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/test/java/com/flowingcode/vaadin/addons/DemoLayout.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*-
22
* #%L
3-
* Template Add-on
3+
* LocaleComboBox Add-on
44
* %%
55
* Copyright (C) 2024 Flowing Code
66
* %%

src/test/java/com/flowingcode/vaadin/addons/template/DemoView.java renamed to src/test/java/com/flowingcode/vaadin/addons/localecombobox/DemoView.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*-
22
* #%L
3-
* Template Add-on
3+
* LocaleComboBox Add-on
44
* %%
55
* Copyright (C) 2024 Flowing Code
66
* %%
@@ -18,7 +18,7 @@
1818
* #L%
1919
*/
2020

21-
package com.flowingcode.vaadin.addons.template;
21+
package com.flowingcode.vaadin.addons.localecombobox;
2222

2323
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
2424
import com.vaadin.flow.router.BeforeEnterEvent;
@@ -31,6 +31,6 @@ public class DemoView extends VerticalLayout implements BeforeEnterObserver {
3131

3232
@Override
3333
public void beforeEnter(BeforeEnterEvent event) {
34-
event.forwardTo(TemplateDemoView.class);
34+
event.forwardTo(LocaleComboBoxDemoView.class);
3535
}
3636
}

0 commit comments

Comments
 (0)