Skip to content

Commit

Permalink
feat: initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
elPeiretti committed Jul 31, 2024
1 parent 3525905 commit 87a6fb8
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 71 deletions.
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
31 changes: 15 additions & 16 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,11 +28,10 @@ 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>
Expand All @@ -50,7 +51,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,13 +76,11 @@ 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

Expand Down
12 changes: 6 additions & 6 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://[email protected]:/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://[email protected]:/FlowingCode/LocaleComboBox.git</developerConnection>
<tag>master</tag>
</scm>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*-
* #%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_LAYOUT_CLASS_NAME + "\">"
+ "<span class=\"fi fi-${item.countryCode} " + ITEM_FLAG_CLASS_NAME
+ "\" alt=\"${item.countryName}\'s flag\"></span>" + "<span>${item.displayName}</span>"
+ "</vaadin-horizontal-layout>")
.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
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 static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
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 @@ -17,9 +17,9 @@
* limitations under the License.
* #L%
*/
package com.flowingcode.vaadin.addons.template.test;
package com.flowingcode.vaadin.addons.localecombobox.test;

import com.flowingcode.vaadin.addons.template.TemplateAddon;
import com.flowingcode.vaadin.addons.localecombobox.LocaleComboBox;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -44,7 +44,7 @@ private void testSerializationOf(Object obj) throws IOException, ClassNotFoundEx
@Test
public void testSerialization() throws ClassNotFoundException, IOException {
try {
testSerializationOf(new TemplateAddon());
testSerializationOf(new LocaleComboBox());
} catch (Exception e) {
Assert.fail("Problem while testing serialization: " + e.getMessage());
}
Expand Down
Loading

0 comments on commit 87a6fb8

Please sign in to comment.