Skip to content

Commit 3462b91

Browse files
ngonzalezpazFCjavier-godoy
authored andcommitted
feat(demo): add demo footer with show/hide code and layout checkboxes
1 parent 21c479d commit 3462b91

File tree

6 files changed

+82
-32
lines changed

6 files changed

+82
-32
lines changed

src/test/java/com/flowingcode/vaadin/addons/chipfield/BinderDemo.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ public class BinderDemo extends VerticalLayout {
1313

1414
public BinderDemo() {
1515
Planet p = new Planet("A new planet");
16-
ChipField<String> chf5 = new ChipField<>(
16+
ChipField<String> chf = new ChipField<>(
1717
"Choose planet features (Binder demo, try with: 'Rings', 'Moons', 'Water', etc.)");
18-
chf5.setWidth("500px");
19-
chf5.setItems(Arrays.asList("Rings", "Moons", "Water", "Rocks", "Lava", "Ice", "Cold", "Heat", "Atmosphere"));
18+
chf.setWidthFull();
19+
chf.setItems(Arrays.asList("Rings", "Moons", "Water", "Rocks", "Lava", "Ice", "Cold", "Heat", "Atmosphere"));
2020
Binder<Planet> binder = new Binder<>();
21-
binder.bind(chf5, Planet::getConfiguration, Planet::setConfiguration);
21+
binder.bind(chf, Planet::getConfiguration, Planet::setConfiguration);
2222
binder.setBean(p);
2323
Button show = new Button("Show planet configuration");
2424
show.addClickListener(
2525
event -> Notification.show(
2626
"Planet: " + p.getName() + ", features: "
2727
+ p.getConfiguration().stream().collect(Collectors.joining(",")),
2828
5000, Position.BOTTOM_START));
29-
chf5.addValueChangeListener(
29+
chf.addValueChangeListener(
3030
newItem -> Notification.show("Items: " + newItem.getValue(), 5000, Position.BOTTOM_START));
3131

32-
add(chf5, show);
32+
add(chf, show);
3333
}
3434
}

src/test/java/com/flowingcode/vaadin/addons/chipfield/ChipfieldDemoView.java

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import com.flowingcode.vaadin.addons.DemoLayout;
44
import com.vaadin.flow.component.checkbox.Checkbox;
5+
import com.vaadin.flow.component.dependency.StyleSheet;
56
import com.vaadin.flow.component.html.IFrame;
7+
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
68
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
79
import com.vaadin.flow.component.splitlayout.SplitLayout;
810
import com.vaadin.flow.component.splitlayout.SplitLayout.Orientation;
@@ -11,6 +13,7 @@
1113
import com.vaadin.flow.router.Route;
1214

1315
@SuppressWarnings("serial")
16+
@StyleSheet("context://frontend/styles/demo-styles.css")
1417
@Route(value = "chipfield", layout = DemoLayout.class)
1518
public class ChipfieldDemoView extends VerticalLayout {
1619

@@ -34,24 +37,45 @@ public ChipfieldDemoView() {
3437
iframe.setSizeFull();
3538
layout.addToSecondary(iframe);
3639

40+
Tabs tabs = new Tabs();
41+
Tab demo1 = new Tab(DATAPROVIDER_DEMO);
42+
Tab demo2 = new Tab(RESTRICTED_DEMO);
43+
Tab demo3 = new Tab(DISABLED_DEMO);
44+
Tab demo4 = new Tab(BINDER_DEMO);
45+
tabs.setWidthFull();
46+
tabs.add(demo1, demo2, demo3, demo4);
47+
48+
Checkbox orientationCB = new Checkbox("Toggle Orientation");
49+
orientationCB.setValue(true);
50+
orientationCB.addClassName("smallcheckbox");
51+
orientationCB.addValueChangeListener(cb -> {
52+
if (cb.getValue()) {
53+
layout.setOrientation(Orientation.HORIZONTAL);
54+
} else {
55+
layout.setOrientation(Orientation.VERTICAL);
56+
}
57+
layout.setSplitterPosition(50);
58+
layout.getPrimaryComponent().getElement().setAttribute("style", "width: 100%; height: 100%");
59+
iframe.setSizeFull();
60+
});
3761
Checkbox codeCB = new Checkbox("Show Source Code");
3862
codeCB.setValue(true);
63+
codeCB.addClassName("smallcheckbox");
3964
codeCB.addValueChangeListener(cb -> {
4065
if (cb.getValue()) {
4166
layout.setSplitterPosition(50);
67+
orientationCB.setEnabled(true);
4268
} else {
4369
layout.setSplitterPosition(100);
70+
orientationCB.setEnabled(false);
4471
}
4572
});
46-
Tabs tabs = new Tabs();
47-
Tab demo1 = new Tab(DATAPROVIDER_DEMO);
48-
Tab demo2 = new Tab(RESTRICTED_DEMO);
49-
Tab demo3 = new Tab(DISABLED_DEMO);
50-
Tab demo4 = new Tab(BINDER_DEMO);
51-
tabs.setWidthFull();
52-
tabs.add(demo1, demo2, demo3, demo4, codeCB);
53-
add(tabs, layout);
54-
73+
HorizontalLayout footer = new HorizontalLayout();
74+
footer.setWidthFull();
75+
footer.setJustifyContentMode(JustifyContentMode.END);
76+
footer.add(codeCB, orientationCB);
77+
add(tabs, layout, footer);
78+
5579
setSizeFull();
5680

5781
tabs.addSelectedChangeListener(e -> {
@@ -61,28 +85,31 @@ public ChipfieldDemoView() {
6185
iframe.getElement().setAttribute("srcdoc", getSrcdoc(DATAPROVIDER_SOURCE));
6286
layout.addToPrimary(new DataProviderDemo());
6387
layout.addToSecondary(iframe);
64-
add(tabs, layout);
88+
add(tabs, layout, footer);
6589
break;
6690
case RESTRICTED_DEMO:
6791
iframe.getElement().setAttribute("srcdoc", getSrcdoc(RESTRICTED_SOURCE));
6892
layout.addToPrimary(new RestrictedDemo());
6993
layout.addToSecondary(iframe);
70-
add(tabs, layout);
94+
add(tabs, layout, footer);
7195
break;
7296
case DISABLED_DEMO:
7397
iframe.getElement().setAttribute("srcdoc", getSrcdoc(DISABLED_SOURCE));
7498
layout.addToPrimary(new DisabledDemo());
7599
layout.addToSecondary(iframe);
76-
add(tabs, layout);
100+
add(tabs, layout, footer);
77101
break;
78102
case BINDER_DEMO:
79103
iframe.getElement().setAttribute("srcdoc", getSrcdoc(BINDER_SOURCE));
80104
layout.addToPrimary(new BinderDemo());
81105
layout.addToSecondary(iframe);
82-
add(tabs, layout);
106+
add(tabs, layout, footer);
83107
break;
84108
default:
85-
add(tabs, new DataProviderDemo());
109+
iframe.getElement().setAttribute("srcdoc", getSrcdoc(DATAPROVIDER_SOURCE));
110+
layout.addToPrimary(new DataProviderDemo());
111+
layout.addToSecondary(iframe);
112+
add(tabs, layout, footer);
86113
break;
87114
}
88115
});

src/test/java/com/flowingcode/vaadin/addons/chipfield/DataProviderDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public DataProviderDemo() {
2222

2323
ChipField<Planet> chf = new ChipField<>("Select some planets (Mercury, Venus, Earth, etc.)",
2424
planet -> planet.getName());
25-
chf.setWidth("100%");
25+
chf.setWidthFull();
2626
chf.setDataProvider(ldp);
2727
chf.setClosable(true);
2828
chf.setNewItemHandler(label -> new Planet(label));

src/test/java/com/flowingcode/vaadin/addons/chipfield/DisabledDemo.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
@SuppressWarnings("serial")
66
public class DisabledDemo extends VerticalLayout {
77
public DisabledDemo() {
8-
ChipField<String> chf4 = new ChipField<>("Disabled", "Mercury", "Venus", "Earth");
9-
chf4.addSelectedItem("Mercury");
10-
chf4.addSelectedItem("Venus");
11-
chf4.setDisabled(true);
8+
ChipField<String> chf = new ChipField<>("Disabled", "Mercury", "Venus", "Earth");
9+
chf.setWidthFull();
10+
chf.addSelectedItem("Mercury");
11+
chf.addSelectedItem("Venus");
12+
chf.setDisabled(true);
1213

13-
add(chf4);
14+
add(chf);
1415
}
1516
}

src/test/java/com/flowingcode/vaadin/addons/chipfield/RestrictedDemo.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
@SuppressWarnings("serial")
77
public class RestrictedDemo extends VerticalLayout {
88
public RestrictedDemo() {
9-
ChipField<String> chf3 = new ChipField<>("Select some planets (Restricted input, allowed pattern [a-zA-Z])");
10-
chf3.setWidth("500px");
11-
chf3.setAvailableItems(
9+
ChipField<String> chf = new ChipField<>("Select some planets (Restricted input, allowed pattern [a-zA-Z])");
10+
chf.setWidthFull();
11+
chf.setAvailableItems(
1212
Arrays.asList("Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"));
13-
chf3.setAllowedPattern("[a-zA-Z]");
14-
chf3.setClosable(true);
13+
chf.setAllowedPattern("[a-zA-Z]");
14+
chf.setClosable(true);
1515

16-
add(chf3);
16+
add(chf);
1717
}
1818
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*-
2+
* #%L
3+
* ChipField Addon
4+
* %%
5+
* Copyright (C) 2018 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-checkbox.smallcheckbox {
21+
font-size: small;
22+
}

0 commit comments

Comments
 (0)