2424import com .vaadin .flow .component .Component ;
2525import com .vaadin .flow .component .HasElement ;
2626import com .vaadin .flow .component .checkbox .Checkbox ;
27+ import com .vaadin .flow .component .dependency .JsModule ;
2728import com .vaadin .flow .component .dependency .StyleSheet ;
2829import com .vaadin .flow .component .html .Div ;
2930import com .vaadin .flow .component .orderedlayout .HorizontalLayout ;
3536import com .vaadin .flow .router .RouterLink ;
3637
3738@ StyleSheet ("context://frontend/styles/commons-demo/shared-styles.css" )
39+ @ JsModule ("./toggle-theme.js" )
3840@ SuppressWarnings ("serial" )
3941public class TabbedDemo extends VerticalLayout implements RouterLayout {
4042
@@ -43,6 +45,7 @@ public class TabbedDemo extends VerticalLayout implements RouterLayout {
4345 private SplitLayoutDemo currentLayout ;
4446 private Checkbox orientationCB ;
4547 private Checkbox codeCB ;
48+ private Checkbox themeCB ;
4649
4750 public TabbedDemo () {
4851 tabs = new RouteTabs ();
@@ -63,10 +66,17 @@ public TabbedDemo() {
6366 cb -> {
6467 updateSplitterPosition ();
6568 });
69+ themeCB = new Checkbox ("Dark Theme" );
70+ themeCB .setValue (false );
71+ themeCB .addClassName ("smallcheckbox" );
72+ themeCB .addValueChangeListener (
73+ cb -> {
74+ updateDemoTheme ();
75+ });
6676 footer = new HorizontalLayout ();
6777 footer .setWidthFull ();
6878 footer .setJustifyContentMode (JustifyContentMode .END );
69- footer .add (codeCB , orientationCB );
79+ footer .add (codeCB , orientationCB , themeCB );
7080
7181 this .add (tabs );
7282 this .add (new Div ());
@@ -156,12 +166,12 @@ public void showRouterLayoutContent(HasElement content) {
156166 content = new SplitLayoutDemo (demo , sourceCodeUrl );
157167 currentLayout = (SplitLayoutDemo ) content ;
158168 updateSplitterPosition ();
159- updateSplitterOrientation ();
160- this .footer .setVisible (true );
169+ updateSplitterOrientation ();
161170 } else {
162- currentLayout = null ;
163- this . footer . setVisible ( false );
171+ currentLayout = null ;
172+ demo . getElement (). getStyle (). set ( "height" , "100%" );
164173 }
174+ updateFooterButtonsVisibility ();
165175 this .getElement ().insertChild (1 , content .getElement ());
166176 }
167177
@@ -190,4 +200,13 @@ private void updateSplitterOrientation() {
190200 }
191201 }
192202
203+ private void updateDemoTheme () {
204+ this .getElement ().executeJs ("toggleTheme.applyTheme($0)" , themeCB .getValue ());
205+ }
206+
207+ private void updateFooterButtonsVisibility () {
208+ orientationCB .setVisible (currentLayout != null );
209+ codeCB .setVisible (currentLayout != null );
210+ }
211+
193212}
0 commit comments