Skip to content

Commit d926fc6

Browse files
committed
feat(demo): add read-only demo view covering all variants
1 parent f590748 commit d926fc6

2 files changed

Lines changed: 122 additions & 0 deletions

File tree

src/test/java/com/flowingcode/vaadin/addons/togglebutton/ToggleButtonDemoView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class ToggleButtonDemoView extends TabbedDemo {
3434
public ToggleButtonDemoView() {
3535
addDemo(ToggleButtonDemo.class);
3636
addDemo(ToggleButtonVariantsDemo.class);
37+
addDemo(ToggleButtonReadOnlyDemo.class);
3738
addDemo(ToggleButtonEventsDemo.class);
3839
setSizeFull();
3940
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*-
2+
* #%L
3+
* Toggle Button Add-On
4+
* %%
5+
* Copyright (C) 2026 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+
package com.flowingcode.vaadin.addons.togglebutton;
21+
22+
import com.flowingcode.vaadin.addons.demo.DemoSource;
23+
import com.vaadin.flow.component.html.Div;
24+
import com.vaadin.flow.component.html.H3;
25+
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
26+
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
27+
import com.vaadin.flow.router.PageTitle;
28+
import com.vaadin.flow.router.Route;
29+
30+
@DemoSource
31+
@PageTitle("Read-only")
32+
@SuppressWarnings("serial")
33+
@Route(value = "togglebutton/readonly", layout = ToggleButtonDemoView.class)
34+
public class ToggleButtonReadOnlyDemo extends Div {
35+
36+
public ToggleButtonReadOnlyDemo() {
37+
38+
// Sizes — unchecked
39+
ToggleButton smallOff = readOnly(new ToggleButton().setRightLabel("Small"),
40+
ToggleButtonVariant.SMALL);
41+
ToggleButton mediumOff = readOnly(new ToggleButton().setRightLabel("Medium"),
42+
ToggleButtonVariant.MEDIUM);
43+
ToggleButton largeOff = readOnly(new ToggleButton().setRightLabel("Large"),
44+
ToggleButtonVariant.LARGE);
45+
46+
// Sizes — checked
47+
ToggleButton smallOn = readOnly(new ToggleButton(true).setRightLabel("Small"),
48+
ToggleButtonVariant.SMALL);
49+
ToggleButton mediumOn = readOnly(new ToggleButton(true).setRightLabel("Medium"),
50+
ToggleButtonVariant.MEDIUM);
51+
ToggleButton largeOn = readOnly(new ToggleButton(true).setRightLabel("Large"),
52+
ToggleButtonVariant.LARGE);
53+
54+
// Long swipe — unchecked
55+
ToggleButton lsSmallOff = readOnly(new ToggleButton().setRightLabel("Small"),
56+
ToggleButtonVariant.LONGSWIPE, ToggleButtonVariant.SMALL);
57+
ToggleButton lsMediumOff = readOnly(new ToggleButton().setRightLabel("Medium"),
58+
ToggleButtonVariant.LONGSWIPE, ToggleButtonVariant.MEDIUM);
59+
ToggleButton lsLargeOff = readOnly(new ToggleButton().setRightLabel("Large"),
60+
ToggleButtonVariant.LONGSWIPE, ToggleButtonVariant.LARGE);
61+
62+
// Long swipe — checked
63+
ToggleButton lsSmallOn = readOnly(new ToggleButton(true).setRightLabel("Small"),
64+
ToggleButtonVariant.LONGSWIPE, ToggleButtonVariant.SMALL);
65+
ToggleButton lsMediumOn = readOnly(new ToggleButton(true).setRightLabel("Medium"),
66+
ToggleButtonVariant.LONGSWIPE, ToggleButtonVariant.MEDIUM);
67+
ToggleButton lsLargeOn = readOnly(new ToggleButton(true).setRightLabel("Large"),
68+
ToggleButtonVariant.LONGSWIPE, ToggleButtonVariant.LARGE);
69+
70+
// Colors — unchecked
71+
ToggleButton primaryOff = readOnly(new ToggleButton().setLeftLabel("Primary"),
72+
ToggleButtonVariant.PRIMARY);
73+
ToggleButton successOff = readOnly(new ToggleButton().setLeftLabel("Success"),
74+
ToggleButtonVariant.SUCCESS);
75+
ToggleButton errorOff = readOnly(new ToggleButton().setLeftLabel("Error"),
76+
ToggleButtonVariant.ERROR);
77+
ToggleButton warningOff = readOnly(new ToggleButton().setLeftLabel("Warning"),
78+
ToggleButtonVariant.WARNING);
79+
ToggleButton contrastOff = readOnly(new ToggleButton().setLeftLabel("Contrast"),
80+
ToggleButtonVariant.CONTRAST);
81+
82+
// Colors — checked (border tint visible)
83+
ToggleButton primaryOn = readOnly(new ToggleButton(true).setLeftLabel("Primary"),
84+
ToggleButtonVariant.PRIMARY);
85+
ToggleButton successOn = readOnly(new ToggleButton(true).setLeftLabel("Success"),
86+
ToggleButtonVariant.SUCCESS);
87+
ToggleButton errorOn = readOnly(new ToggleButton(true).setLeftLabel("Error"),
88+
ToggleButtonVariant.ERROR);
89+
ToggleButton warningOn = readOnly(new ToggleButton(true).setLeftLabel("Warning"),
90+
ToggleButtonVariant.WARNING);
91+
ToggleButton contrastOn = readOnly(new ToggleButton(true).setLeftLabel("Contrast"),
92+
ToggleButtonVariant.CONTRAST);
93+
94+
HorizontalLayout sizesOff = row(smallOff, mediumOff, largeOff);
95+
HorizontalLayout sizesOn = row(smallOn, mediumOn, largeOn);
96+
HorizontalLayout longswipeOff = row(lsSmallOff, lsMediumOff, lsLargeOff);
97+
HorizontalLayout longswipeOn = row(lsSmallOn, lsMediumOn, lsLargeOn);
98+
HorizontalLayout colorsOff = row(primaryOff, successOff, errorOff, warningOff, contrastOff);
99+
HorizontalLayout colorsOn = row(primaryOn, successOn, errorOn, warningOn, contrastOn);
100+
101+
add(new VerticalLayout(
102+
new H3("Sizes - unchecked"), sizesOff,
103+
new H3("Sizes - checked"), sizesOn,
104+
new H3("Long swipe - unchecked"), longswipeOff,
105+
new H3("Long swipe - checked"), longswipeOn,
106+
new H3("Colors - unchecked"), colorsOff,
107+
new H3("Colors - checked"), colorsOn));
108+
}
109+
110+
private static ToggleButton readOnly(ToggleButton tb, ToggleButtonVariant... variants) {
111+
tb.addThemeVariants(variants);
112+
tb.setReadOnly(true);
113+
return tb;
114+
}
115+
116+
private static HorizontalLayout row(ToggleButton... buttons) {
117+
HorizontalLayout row = new HorizontalLayout(buttons);
118+
row.getStyle().set("gap", "var(--lumo-space-l, var(--vaadin-gap-l))");
119+
return row;
120+
}
121+
}

0 commit comments

Comments
 (0)