Skip to content

Commit

Permalink
feat(demo): add flag-rendering demo
Browse files Browse the repository at this point in the history
  • Loading branch information
elPeiretti authored and javier-godoy committed Sep 5, 2024
1 parent 8b586ea commit 354ec35
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package com.flowingcode.vaadin.addons.localecombobox;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.Text;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Span;
Expand All @@ -40,5 +41,15 @@ protected HorizontalLayout createHorizontalContainer(String title, LocaleComboBo
container.expand(combo);
return container;
}

protected HorizontalLayout createHorizontalContainer(Component component, LocaleComboBox combo) {
HorizontalLayout container = new HorizontalLayout();
container.setWidthFull();
container.setAlignItems(Alignment.CENTER);
container.setJustifyContentMode(JustifyContentMode.BETWEEN);
container.add(component, combo);
container.expand(combo);
return container;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@DemoSource
@PageTitle("Display modes")
@SuppressWarnings("serial")
@Route(value = "demo", layout = LocaleComboBoxDemoView.class)
@Route(value = "locale-combo-box/display", layout = LocaleComboBoxDemoView.class)
public class DisplayModeDemo extends BaseLocaleComboBoxDemo {

public DisplayModeDemo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class LocaleComboBoxDemoView extends TabbedDemo {

public LocaleComboBoxDemoView() {
addDemo(DisplayModeDemo.class);
addDemo(RenderingDemo.class);
setSizeFull();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*-
* #%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.flowingcode.vaadin.addons.demo.DemoSource;
import com.vaadin.flow.component.checkbox.Checkbox;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import java.util.Locale;

@DemoSource
@PageTitle("Flag rendering")
@SuppressWarnings("serial")
@Route(value = "locale-combo-box/rendering", layout = LocaleComboBoxDemoView.class)
public class RenderingDemo extends BaseLocaleComboBoxDemo {
public RenderingDemo() {

LocaleComboBox defaultLocaleCombo = new LocaleComboBox();
LocaleComboBox flagsLocaleCombo = new LocaleComboBox();
Checkbox checkbox = new Checkbox("Render flags");

defaultLocaleCombo.setValue(Locale.ITALY);
flagsLocaleCombo.setValue(Locale.ITALY);
checkbox.setValue(true);

/*
* You can choose whether the flags should be displayed alongside the locale names by using the
* setHasFlag method
*/
checkbox.addValueChangeListener(event -> flagsLocaleCombo.setHasFlags(event.getValue()));

// #if vaadin eq 0
add(createHorizontalContainer("Flags are rendered by default:", defaultLocaleCombo));
add(createHorizontalContainer(checkbox, flagsLocaleCombo));
// #endif
// show-source add(defaultLocaleCombo);
// show-source add(checkbox, flagsLocaleCombo);

}
}

0 comments on commit 354ec35

Please sign in to comment.