From f230dbb7453960758c5e269714f1ce12b4f3d673 Mon Sep 17 00:00:00 2001 From: Felipe Lang Date: Mon, 22 Jan 2024 12:16:38 -0300 Subject: [PATCH] feat(demo): add responsive step demo Example demonstrates how to use responsive step feature and how to hide the grid when all columns are hidden Close #95 --- .../gridhelpers/GridHelpersDemoView.java | 1 + .../gridhelpers/ResponsiveStepDemo.java | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/test/java/com/flowingcode/vaadin/addons/gridhelpers/ResponsiveStepDemo.java diff --git a/src/test/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelpersDemoView.java b/src/test/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelpersDemoView.java index d230a1b..becf202 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelpersDemoView.java +++ b/src/test/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelpersDemoView.java @@ -52,5 +52,6 @@ public GridHelpersDemoView() { addDemo(CheckboxColumnDemo.class); addDemo(EmptyGridLabelDemo.class); addDemo(HeightByRowsDemo.class); + addDemo(ResponsiveStepDemo.class); } } diff --git a/src/test/java/com/flowingcode/vaadin/addons/gridhelpers/ResponsiveStepDemo.java b/src/test/java/com/flowingcode/vaadin/addons/gridhelpers/ResponsiveStepDemo.java new file mode 100644 index 0000000..f5dee0d --- /dev/null +++ b/src/test/java/com/flowingcode/vaadin/addons/gridhelpers/ResponsiveStepDemo.java @@ -0,0 +1,57 @@ +/*- + * #%L + * Grid Helpers Add-on + * %% + * Copyright (C) 2022 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.gridhelpers; + +import com.flowingcode.vaadin.addons.demo.DemoSource; +import com.vaadin.flow.component.grid.Grid; +import com.vaadin.flow.component.grid.Grid.Column; +import com.vaadin.flow.component.html.Div; +import com.vaadin.flow.router.PageTitle; +import com.vaadin.flow.router.Route; + +@PageTitle("Responsive Step") +@DemoSource +@Route(value = "grid-helpers/respoonsive-step", layout = GridHelpersDemoView.class) +public class ResponsiveStepDemo extends Div { + + public ResponsiveStepDemo() { + setSizeFull(); + + Grid grid = new Grid<>(); + grid.setItems(TestData.initializeData()); + + Column firstNameColumn = grid.addColumn(Person::getFirstName).setHeader("First name"); + Column lastNameColumn = grid.addColumn(Person::getLastName).setHeader("Last name"); + Column countryColumn = grid.addColumn(Person::getCountry).setHeader("Country"); + grid.getStyle().set("visibility", "hidden"); + + GridHelper.responsiveStep(grid, 0).hideAll() + .addListener(e -> grid.getStyle().set("visibility", "hidden")); + + GridHelper.responsiveStep(grid, 850).show(firstNameColumn, lastNameColumn).hide(countryColumn) + .addListener(e -> grid.getStyle().set("visibility", "visible")); + + GridHelper.responsiveStep(grid, 1000).show(firstNameColumn, lastNameColumn, countryColumn) + .addListener(e -> grid.getStyle().set("visibility", "visible")); + + add(grid); + } +}