jmix-projects / jmix-old

DEPRECATED. Use https://github.com/jmix-framework/jmix
16 stars 3 forks source link

Introduce flexbox-based responsive grid layout #424

Closed web-devel closed 4 years ago

glebfox commented 3 years ago

ResponsiveGridLayout - a layout where the components are laid out on a grid, based on the Bootstrap's 12 columns grid system (see Bootstrap doc).

Auto-layout columns

Columns can be defined without explicit values like xs="6".

Equal-width

If cols have no explicit values then every column will be the same width at every viewport, from xs to xl.

<responsiveGridLayout>
    <row>
        <col>
            <label value="1 of 2"/>
        </col>
        <col>
            <label value="2 of 2"/>
        </col>
    </row>
    <row>
        <col>
            <label value="1 of 3"/>
        </col>
        <col>
            <label value="2 of 3"/>
        </col>
        <col>
            <label value="3 of 3"/>
        </col>
    </row>
</responsiveGridLayout>
Screenshot 2020-12-07 at 13 15 43

Setting one column width

Auto-layout for flexbox grid columns also means you can set the width of one column and have the sibling columns automatically resize around it.

<responsiveGridLayout>
    <row>
        <col>
            <label value="1 of 3"/>
        </col>
        <col xs="6">
            <label value="1 of 3 (wider)"/>
        </col>
        <col>
            <label value="1 of 3"/>
        </col>
    </row>
    <row>
        <col>
            <label value="1 of 3"/>
        </col>
        <col xs="5">
            <label value="1 of 3 (wider)"/>
        </col>
        <col>
            <label value="1 of 3"/>
        </col>
    </row>
</responsiveGridLayout>
Screenshot 2020-12-07 at 13 16 40

Variable width content

Use {breakpoint}="AUTO" attributes to size columns based on the natural width of their content.

<responsiveGridLayout>
    <row justifyContentMd="CENTER">
        <col xs="DEFAULT" lg="2">
            <label value="1 of 3"/>
        </col>
        <col md="AUTO">
            <label value="Variable width content"/>
        </col>
        <col xs="DEFAULT" lg="2">
            <label value="1 of 3"/>
        </col>
    </row>
    <row>
        <col>
            <label value="1 of 3"/>
        </col>
        <col md="AUTO">
            <label value="Variable width content"/>
        </col>
        <col xs="DEFAULT" lg="2">
            <label value="1 of 3"/>
        </col>
    </row>
</responsiveGridLayout>
Screenshot 2020-12-07 at 13 16 53

Note: the DEFAULT breakpoint value represents the case when no explicit columns value is defined. This means that the equal-width columns will be created. In terms of Bootstrap it equivalent to :

Responsive classes

Bootstrap’s grid includes five tiers of predefined classes for building complex responsive layouts.

Breakpoints

Breakpoint representing minimum viewport widths used in media query ranges. When used, they apply to that one breakpoint and all those above it (e.g. SM applies to small, medium, large, and extra large devices, but not the first XS breakpoint).

<responsiveGridLayout>
    <row>
        <col sm="6" md="8">
            <label value="sm-6, md-8"/>
        </col>
        <col sm="6" md="4">
            <label value="sm-6, md-4"/>
        </col>
    </row>
    <row>
        <col sm="4" md="2">
            <label value="sm-4, md-2"/>
        </col>
        <col sm="4" md="8">
            <label value="sm-4, md-8"/>
        </col>
        <col sm="4" md="2">
            <label value="sm-4, md-2"/>
        </col>
    </row>
    <row>
        <col xs="6">
            <label value="xs-6"/>
        </col>
        <col xs="6">
            <label value="xs-6"/>
        </col>
    </row>
</responsiveGridLayout>
Screenshot 2020-12-07 at 13 18 20 Screenshot 2020-12-07 at 13 26 42 Screenshot 2020-12-07 at 13 26 51

Row columns

The cols attribute defines what number of columns in the row will be at a specific breakpoint

<responsiveGridLayout>
    <row cols="2">
        <col>
            <label value="Column"/>
        </col>
        <col>
            <label value="Column"/>
        </col>
        <col>
            <label value="Column"/>
        </col>
        <col>
            <label value="Column"/>
        </col>
    </row>
</responsiveGridLayout>
Screenshot 2020-12-07 at 13 18 26
<responsiveGridLayout stylename="demo">
    <row cols="3">
        <col>
            <label value="Column"/>
        </col>
        <col>
            <label value="Column"/>
        </col>
        <col>
            <label value="Column"/>
        </col>
        <col>
            <label value="Column"/>
        </col>
    </row>
</responsiveGridLayout>
Screenshot 2020-12-07 at 13 18 34

Alignment

Flexbox alignment is used to vertically and horizontally align columns.

Vertical alignment

<responsiveGridLayout>
    <row alignItems="START">
        <col>
            <label value="1 of 3"/>
        </col>
        <col>
            <label value="2 of 3"/>
        </col>
        <col>
            <label value="3 of 3"/>
        </col>
    </row>
    <row alignItems="CENTER">
        <col>
            <label value="1 of 3"/>
        </col>
        <col>
            <label value="2 of 3"/>
        </col>
        <col>
            <label value="3 of 3"/>
        </col>
    </row>
    <row alignItems="END">
        <col>
            <label value="1 of 3"/>
        </col>
        <col>
            <label value="2 of 3"/>
        </col>
        <col>
            <label value="3 of 3"/>
        </col>
    </row>
</responsiveGridLayout>
Screenshot 2020-12-07 at 13 20 52
<responsiveGridLayout>
    <row>
        <col alignSelf="START">
            <label value="1 of 3"/>
        </col>
        <col alignSelf="CENTER">
            <label value="2 of 3"/>
        </col>
        <col alignSelf="END">
            <label value="3 of 3"/>
        </col>
    </row>
</responsiveGridLayout>
Screenshot 2020-12-07 at 13 20 59

Horizontal alignment

<responsiveGridLayout stylename="demo">
    <row justifyContent="START">
        <col xs="4">
            <label value="1 of 2"/>
        </col>
        <col xs="4">
            <label value="2 of 2"/>
        </col>
    </row>
    <row justifyContent="CENTER">
        <col xs="4">
            <label value="1 of 2"/>
        </col>
        <col xs="4">
            <label value="2 of 2"/>
        </col>
    </row>
    <row justifyContent="END">
        <col xs="4">
            <label value="1 of 2"/>
        </col>
        <col xs="4">
            <label value="2 of 2"/>
        </col>
    </row>
    <row justifyContent="AROUND">
        <col xs="4">
            <label value="1 of 2"/>
        </col>
        <col xs="4">
            <label value="2 of 2"/>
        </col>
    </row>
    <row justifyContent="BETWEEN">
        <col xs="4">
            <label value="1 of 2"/>
        </col>
        <col xs="4">
            <label value="2 of 2"/>
        </col>
    </row>
</responsiveGridLayout>
Screenshot 2020-12-07 at 13 22 14

Reordering

Order classes

Use order attributes for controlling the visual order of your content. Can be either a number or the predefined value (FIRST, LAST).

<responsiveGridLayout>
    <row>
        <col>
            <label value="First in DOM, no order applied"/>
        </col>
        <col order="12">
            <label value="Second in DOM, with a larger order"/>
        </col>
        <col order="1">
            <label value="Third in DOM, with an order of 1"/>
        </col>
    </row>
</responsiveGridLayout>
Screenshot 2020-12-07 at 13 25 36
<responsiveGridLayout>
    <row>
        <col order="LAST">
            <label value="First in DOM, ordered last"/>
        </col>
        <col>
            <label value="Second in DOM, unordered"/>
        </col>
        <col order="FIRST">
            <label value="Third in DOM, ordered first"/>
        </col>
    </row>
</responsiveGridLayout>
Screenshot 2020-12-07 at 13 25 43

Offset classes

Use offset attributes for moving columns to the right.

<responsiveGridLayout>
    <row>
        <col md="4">
            <label value="md-4"/>
        </col>
        <col md="4" offsetMd="4">
            <label value="md-4, offset-md-4"/>
        </col>
    </row>
    <row>
        <col md="3" offsetMd="3">
            <label value="md-3, offset-md-3"/>
        </col>
        <col md="3" offsetMd="3">
            <label value="md-3, offset-md-3"/>
        </col>
    </row>
    <row>
        <col md="6" offsetMd="3">
            <label value="md-6, offset-md-3"/>
        </col>
    </row>
</responsiveGridLayout>
Screenshot 2020-12-07 at 13 22 54

Container types

ResponsiveGridLayout has two possible types:


See JavaDoc for the full description of attributes and their values.


Styles used for demo purpose:

.jmix-responsivegridlayout {
  &.demo {
    .row > .col, .row > [class^=col-] {
      padding-top: .75rem;
      padding-bottom: .75rem;
      background-color: #D2CCEC;
      border: 1px solid #F2F2F2;
    }
  }

  &.vertical-alignment-demo {
    .row {
      min-height: 10rem;
      background-color: #F2F2F2;
    }

    .row + .row {
      margin-top: 1rem;
    }
  }
}