Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Bug Report
description: Please report issues related to TEMPLATE_ADDON here.
description: Please report issues related to LocaleComboBox add-on here.
body:
- type: textarea
id: problem-description
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature-request.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Feature Request
description: Please add feature suggestions related to TEMPLATE_ADDON here.
description: Please add feature suggestions related to LocaleComboBox add-on here.
body:
- type: textarea
id: feature-proposal
Expand Down
4 changes: 0 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
All parts are licensed under Apache License v2.0. See the license text below.

-----------------------------------------------------------------------------

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down
48 changes: 20 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
[![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0.svg)](https://vaadin.com/directory/component/template-addon)
[![Stars on vaadin.com/directory](https://img.shields.io/vaadin-directory/star/template-addon.svg)](https://vaadin.com/directory/component/template-addon)
[![Build Status](https://jenkins.flowingcode.com/job/template-addon/badge/icon)](https://jenkins.flowingcode.com/job/template-addon)
[![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)
[![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0.svg)](https://vaadin.com/directory/component/locale-combo-box-add-on)
[![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)
[![Build Status](https://jenkins.flowingcode.com/job/LocaleComboBox-addon/badge/icon)](https://jenkins.flowingcode.com/job/LocaleComboBox-addon)
[![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)

# Template Add-on
# LocaleComboBox Add-on

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

## Features

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

## Online demo

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

## Download release

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

### Maven install

Expand All @@ -26,20 +28,12 @@ Add the following dependencies in your pom.xml file:
```xml
<dependency>
<groupId>com.flowingcode.vaadin.addons</groupId>
<artifactId>template-addon</artifactId>
<artifactId>locale-combo-box-addon</artifactId>
<version>X.Y.Z</version>
</dependency>
```
<!-- the above dependency should be updated with latest released version information -->

```xml
<repository>
<id>vaadin-addons</id>
<url>https://maven.vaadin.com/vaadin-addons</url>
</repository>
```

For SNAPSHOT versions see [here](https://maven.flowingcode.com/snapshots/).
Release versions are available from Maven Central repository. For SNAPSHOT versions see [here](https://maven.flowingcode.com/snapshots/).

## Building and running demo

Expand All @@ -50,7 +44,7 @@ To see the demo, navigate to http://localhost:8080/

## Release notes

See [here](https://github.com/FlowingCode/TemplateAddon/releases)
See [here](https://github.com/FlowingCode/LocaleComboBox/releases)

## Issue tracking

Expand All @@ -75,20 +69,18 @@ Then, follow these steps for creating a contribution:

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

TEMPLATE_ADDON is written by Flowing Code S.A.
LocaleComboBox Add-on is written by Flowing Code S.A.

# Developer Guide

## Getting started

Add your code samples in this section
<!-- TODO: ## Getting started -->

## Special configuration when using Spring

By default, Vaadin Flow only includes ```com/vaadin/flow/component``` to be always scanned for UI components and views. For this reason, the add-on might need to be whitelisted in order to display correctly.
By default, Vaadin Flow only includes ```com/vaadin/flow/component``` to be always scanned for UI components and views. For this reason, the add-on might need to be allowed in order to display correctly.

To do so, just add ```com.flowingcode``` to the ```vaadin.whitelisted-packages``` property in ```src/main/resources/application.properties```, like:
To do so, just add ```com.flowingcode``` to the ```vaadin.allowed-packages``` property in ```src/main/resources/application.properties```, like:

```vaadin.whitelisted-packages = com.vaadin,org.vaadin,dev.hilla,com.flowingcode```
```vaadin.allowed-packages = com.vaadin,org.vaadin,dev.hilla,com.flowingcode```

More information on Spring whitelisted configuration [here](https://vaadin.com/docs/latest/integrations/spring/configuration/#configure-the-scanning-of-packages).
More information on Spring scanning configuration [here](https://vaadin.com/docs/latest/integrations/spring/configuration/#configure-the-scanning-of-packages).
13 changes: 6 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<modelVersion>4.0.0</modelVersion>

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

<properties>
Expand Down Expand Up @@ -39,9 +39,9 @@
</licenses>

<scm>
<url>https://github.com/FlowingCode/AddonStarter24</url>
<connection>scm:git:git://github.com/FlowingCode/AddonStarter24.git</connection>
<developerConnection>scm:git:ssh://git@github.com:/FlowingCode/AddonStarter24.git</developerConnection>
<url>https://github.com/FlowingCode/LocaleComboBox</url>
<connection>scm:git:git://github.com/FlowingCode/LocaleComboBox.git</connection>
<developerConnection>scm:git:ssh://git@github.com:/FlowingCode/LocaleComboBox.git</developerConnection>
<tag>master</tag>
</scm>

Expand Down Expand Up @@ -260,7 +260,6 @@
<webApp>
<resourceBases>
<resourceBase>src/test/resources/META-INF/resources</resourceBase>
<resourceBase>src/main/resources/META-INF/resources</resourceBase>
</resourceBases>
</webApp>
<supportedPackagings>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*-
* #%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.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.dependency.NpmPackage;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.data.renderer.LitRenderer;
import java.util.Arrays;
import java.util.Locale;

/**
* Vaadin ComboBox extension that allows to choose between multiple locales.
*
* @author Tomas Peiretti / Flowing Code
*/
@SuppressWarnings("serial")
@NpmPackage(value = "flag-icons", version = "7.2.3")
@CssImport("flag-icons/css/flag-icons.min.css")
@CssImport("styles/locale-combo-box.css")
public class LocaleComboBox extends ComboBox<Locale> {

private static final String ITEM_LAYOUT_CLASS_NAME = "fc-locale-combo-box-item-layout";
private static final String ITEM_FLAG_CLASS_NAME = "fc-locale-combo-box-item-flag";

/**
* Creates a new instance of LocaleComboBox with all the installed locales.
*/
public LocaleComboBox() {
setItemLabelGenerator(Locale::getDisplayName);
setRenderer(getLocaleRenderer());
addValueChangeListener(this::onValueChange);
setItems(
Arrays.stream(Locale.getAvailableLocales()).filter(loc -> loc.getCountry().length() == 2)
.sorted((l1, l2) -> l1.getDisplayName().compareTo(l2.getDisplayName())).toList());
}

private LitRenderer<Locale> getLocaleRenderer() {
return LitRenderer
.<Locale>of(
"""
<vaadin-horizontal-layout class="${item.layoutClass}">
<span class="fi fi-${item.countryCode} ${item.flagClass} alt="${item.countryName}'s flag"></span>
<span>${item.displayName}</span>
</vaadin-horizontal-layout>""")
.withProperty("layoutClass", loc -> ITEM_LAYOUT_CLASS_NAME)
.withProperty("flagClass", loc -> ITEM_FLAG_CLASS_NAME)
.withProperty("countryCode", loc -> loc.getCountry().toLowerCase())
.withProperty("countryName", loc -> loc.getDisplayCountry())
.withProperty("displayName", loc -> loc.getDisplayName());
}

private void onValueChange(ComponentValueChangeEvent<ComboBox<Locale>, Locale> event) {
Locale newValue = event.getValue();
if (newValue == null) {
setPrefixComponent(null);
return;
}
Span flagIcon = new Span();
flagIcon.addClassNames("fi", "fi-" + newValue.getCountry().toLowerCase());
setPrefixComponent(flagIcon);
}

}
28 changes: 28 additions & 0 deletions src/main/resources/META-INF/frontend/styles/locale-combo-box.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*-
* #%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%
*/
vaadin-horizontal-layout.fc-locale-combo-box-item-layout {
align-items: center;
justify-content: start;
gap: 0.5em;
}

span.fc-locale-combo-box-item-flag {
flex-shrink: 0;
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-
* #%L
* Template Add-on
* LocaleComboBox Add-on
* %%
* Copyright (C) 2024 Flowing Code
* %%
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-
* #%L
* Template Add-on
* LocaleComboBox Add-on
* %%
* Copyright (C) 2024 Flowing Code
* %%
Expand All @@ -18,7 +18,7 @@
* #L%
*/

package com.flowingcode.vaadin.addons.template;
package com.flowingcode.vaadin.addons.localecombobox;

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

@Override
public void beforeEnter(BeforeEnterEvent event) {
event.forwardTo(TemplateDemoView.class);
event.forwardTo(LocaleComboBoxDemoView.class);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-
* #%L
* Template Add-on
* LocaleComboBox Add-on
* %%
* Copyright (C) 2024 Flowing Code
* %%
Expand All @@ -18,15 +18,20 @@
* #L%
*/

package com.flowingcode.vaadin.addons.template;
package com.flowingcode.vaadin.addons.localecombobox;

import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.dependency.NpmPackage;
import com.flowingcode.vaadin.addons.demo.DemoSource;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;

@DemoSource
@PageTitle("LocaleComboBox Add-on Demo")
@SuppressWarnings("serial")
@NpmPackage(value = "@polymer/paper-input", version = "3.2.1")
@JsModule("@polymer/paper-input/paper-input.js")
@Tag("paper-input")
public class TemplateAddon extends Div {}
@Route(value = "demo", layout = LocaleComboBoxDemoView.class)
public class LocaleComboBoxDemo extends Div {

public LocaleComboBoxDemo() {
add(new LocaleComboBox());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-
* #%L
* Template Add-on
* LocaleComboBox Add-on
* %%
* Copyright (C) 2024 Flowing Code
* %%
Expand All @@ -17,7 +17,7 @@
* limitations under the License.
* #L%
*/
package com.flowingcode.vaadin.addons.template;
package com.flowingcode.vaadin.addons.localecombobox;

import com.flowingcode.vaadin.addons.DemoLayout;
import com.flowingcode.vaadin.addons.GithubLink;
Expand All @@ -27,12 +27,12 @@

@SuppressWarnings("serial")
@ParentLayout(DemoLayout.class)
@Route("template")
@GithubLink("https://github.com/FlowingCode/AddonStarter24")
public class TemplateDemoView extends TabbedDemo {
@Route("locale-combo-box")
@GithubLink("https://github.com/FlowingCode/LocaleComboBox")
public class LocaleComboBoxDemoView extends TabbedDemo {

public TemplateDemoView() {
addDemo(TemplateDemo.class);
public LocaleComboBoxDemoView() {
addDemo(LocaleComboBoxDemo.class);
setSizeFull();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-
* #%L
* Template Add-on
* LocaleComboBox Add-on
* %%
* Copyright (C) 2024 Flowing Code
* %%
Expand All @@ -18,7 +18,7 @@
* #L%
*/

package com.flowingcode.vaadin.addons.template.it;
package com.flowingcode.vaadin.addons.localecombobox.it;

import com.vaadin.testbench.ScreenshotOnFailureRule;
import com.vaadin.testbench.TestBench;
Expand Down
Loading