JarekToro / responsive-layout

The layout to beat them all!
https://vaadin.com/directory#!addon/responsive-layout
57 stars 24 forks source link

Set Visibility for Rows #21

Closed AVogler87 closed 7 years ago

AVogler87 commented 7 years ago

Hi,

at first i really like this addon and am using it at the moment for a project. While doing some experimenting with the best way to to use the addon i realised that I would really like to be able to define visibility rules for rows. At the moment I can simulate that by just setting visibility rules for every Column in that row but I think that this isn't really the smart thing to do, mainly because it just works when the row includes nothing but Columns.

At the moment i helped myself with the following extension:

`public ResponsiveRow withVisibilityRules(boolean xs, boolean sm, boolean md, boolean lg) {

    for (Iterator<Component> iterate = this.iterator(); iterate.hasNext(); ) {
        Component component = iterate.next();

        if (component instanceof ResponsiveColumn) {
            ((ResponsiveColumn) component).setVisibilityRules(xs, sm, md, lg);
        }
    }
    return this;
}`

So is there a possibility to add this feature?

JarekToro commented 7 years ago

Thank you!,

Yes and I think this is a great addition!

What I think I will do is abstract some methods from the ResponsiveColumn to a StyleAdapter (or something) that the Row and Column can inherit from. Because it all goes down to Css at the end so if the row has the Hidden and Visible Css Classes then it will hide itself and its children without having to give all the CSS classes to the columns (and it will work even if the children aren't Columns).

AVogler87 commented 7 years ago

yes, like I said what I coded was a fast "solution" for my problem, if you could change it to just make the row invisible it would be even better.

JarekToro commented 7 years ago

@AVogler87 Thanks again! I appreciate all the feedback and ideas. Im going to try and tackle this now while I have some free time. Ill keep you posted.

JarekToro commented 7 years ago

@AVogler87

Rows and Columns have the

public boolean isVisibleForDisplaySize(ResponsiveLayout.DisplaySize displaySize)
public void setVisibility(ResponsiveLayout.DisplaySize displaySize, boolean isVisible)

Methods

There are some semi major changes the biggest being ResponsiveColumn.DisplaySize has been moved to ResponsiveLayout.DisplaySize

Im attaching @BassMartin so your aware of the change incase your building straight from GitHub Master branch.

This won't be on the Vaadin Directory just yet, needs some more testing and refinement but @AVogler87 feel free to mess with it. Its fully functional.

AVogler87 commented 7 years ago

Thanks for the update, I will try it.

bassmartin commented 7 years ago

This is an excellent idea. I was getting around this limitation by setting the column visibility (I had only one use case so it was ok for me).

Thanks guys.

JarekToro commented 7 years ago

The Vaadin Directory is now updated with this code! Thanks for the feature requests and feedback!