From cb415925426b58e7c7945d40bbf9e2ecff326ccb Mon Sep 17 00:00:00 2001 From: Javier Godoy <11554739+javier-godoy@users.noreply.github.com> Date: Mon, 15 Jul 2024 11:28:37 -0300 Subject: [PATCH] feat: hide tabs if there is only one demo --- .../vaadin/addons/demo/TabbedDemo.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java b/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java index f091e2b..da1bd00 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java +++ b/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java @@ -53,6 +53,7 @@ public class TabbedDemo extends VerticalLayout implements RouterLayout { private static final Logger logger = LoggerFactory.getLogger(TabbedDemo.class); private static final int MOBILE_DEVICE_BREAKPOINT_WIDTH = 768; + private boolean autoVisibility; private EnhancedRouteTabs tabs; private HorizontalLayout footer; private SplitLayoutDemo currentLayout; @@ -138,6 +139,7 @@ public void addDemo(Component demo) { @Deprecated public void addDemo(Component demo, String label, String sourceCodeUrl) { tabs.addLegacyTab(label, demo); + updateVisibility(); } /** @@ -151,6 +153,22 @@ public void addDemo(Class clazz, String label) { throw new IllegalArgumentException(clazz + " must be annotated as Route"); } tabs.add(label, clazz); + updateVisibility(); + } + + private void updateVisibility() { + if (autoVisibility) { + tabs.setVisible(tabs.getContent().getTabCount() > 1); + } + } + + /** + * Sets the autovisibility mode. When autovisibility is enabled, the tabs component is hidden + * unless it contains two or more tabs. + */ + public void setAutoVisibility(boolean autoVisibility) { + this.autoVisibility = autoVisibility; + updateVisibility(); } /**