io.imunity.vaadin.elements.LocaleButtonsBar Maven / Gradle / Ivy
/*
* Copyright (c) 2021 Bixbit - Krzysztof Benedyczak. All rights reserved.
* See LICENCE.txt file for licensing information.
*/
package io.imunity.vaadin.elements;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import java.util.Collection;
import java.util.Locale;
import java.util.function.Function;
import static io.imunity.vaadin.elements.CSSVars.BASE_MARGIN;
public class LocaleButtonsBar extends HorizontalLayout
{
public LocaleButtonsBar(Collection enabledLocales, String label, Function valueGenerator)
{
getStyle().set("margin-left", BASE_MARGIN.value());
enabledLocales.stream().map(locale ->
{
Button button = new Button(label, e -> valueGenerator.apply(locale).run());
button.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
button.setIcon(new FlagIcon(locale.getLanguage()));
return button;
}).forEach(this::add);
}
}