Lowdefy
v3.17.2/Concepts/Layout/

Layout

Containers blocks are used to arrange blocks on a page. Blocks of category container, context and list all function as container blocks. Container blocks have content areas into which a list of blocks are rendered. List category blocks can render container areas for each element in the data array.

Blocks on a page can be arranged using a span or flex layout. Blocks in span layout are placed in a 24 column grid system, whereas flex blocks dynamically grows or shrink to fit content into a row depending on content size and screen size.

Under the hood, Lowdefy layouts are based on the Ant Design Grid System. The content areas are implemented as a row, and blocks are implemented as a column.

Content areas

Each container has content areas - these are areas where nested blocks can be placed. All container blocks have a primary content area. This area is called content. Container blocks might have other content areas, like header, footer, or title. These content areas are implemented specifically by the block.

To place blocks in the primary content area of a container, the block definitions for those blocks can be placed inside the blocks array of the container block.

In the following examples, blocks of type Container will represent a generic container block, and blocks of type Block will represent a generic block. The Container block might be a Box, a Card, a PageHeaderMenu or any other container or context block. The Block blocks could be any type of block, including other container blocks.

Two blocks in the primary content area (content) of a container:
- id: container
  type: Container
  blocks:
    - id: block1
      type: Block
    - id: block2
      type: Block
Block 1
Block 2

To place blocks in other content areas, the block definitions can be placed in the blocks array of the specific area in the areas object:

Note the blocks are placed under areas.[areaName].blocks

Blocks in the header, content and footer areas:
- id: container
  type: Container
  areas:
    header:
      blocks:
        - id: block1
          type: Block
    content:
      blocks:
        - id: block2
          type: Block
    footer:
      blocks:
        - id: block3
          type: Block
Block 1
Block 2
Block 3

Placing blocks both in the blocks array, as well as under the areas.content.blocks array is an anti-pattern, and in this case the blocks under blocks will overwrite those under areas.content.blocks.

Anti-pattern: Blocks in the blocks and areas.content.blocks:
- id: container
  type: Container
  blocks:
    - id: block1
      type: Block
  areas:
    content:
      blocks:
        - id: block2
          type: Block
Block 1

Layouts using span

Each content area has 24 columns. Blocks have a span property, which determines how many columns the block occupies. Blocks are laid out horizontally, until the sum of the spans is more than 24, then the last block block is wrapped to the next row.

By default a block is given a span of 24. This is what makes blocks lay out vertically below each other.

Blocks are also given a default span of 24 for mobile layouts, even if another span is given, to provide a good default mobile experience. Read more about responsive layouts below.

Block spans example:
- id: container
  type: Container
  blocks:
    - id: block1
      type: Block # Default span of 24
    - id: block2
      type: Block
      layout:
        span: 16 # Two thirds of the area
    - id: block3
      type: Block
      layout:
        span: 8 # Remaining one third of the area
    - id: block4
      type: Block
      layout:
        span: 12
    - id: block5
      type: Block
      layout:
        span: 18 # Sum would be over 24, so wraps to the next row
Block 1
Block 2
Block 3
Block 4
Block 5

Layouts using flex

Blocks can also be laid out using CSS flexbox properties. These properties are grow (flex-grow), shrink (flex-shrink), size (flex-basis) and flex (flex). If any of these properties are set, the default span of 24 or any span set in the configuration is not applied. If one of grow, shrink, or size are set, the other properties take their default values. The flex property overwrites the grow, shrink, and size properties.

Block layout properties

The layout object on blocks can be used to control how a block is placed in the layout. The layout properties that can be defined are:

  • align: Enum - Align block vertically in the area. Options are top, middle, and bottom. Default top.
  • flex: String - Set the flex CSS property. This overwrites the grow, shrink, and size properties.
  • grow: Number - Set the flex-grow CSS property. Default 0.
  • order: Number - Change the order blocks are rendered in. By default blocks are rendered in the order they appear in the blocks array.
  • offset: Number - Number of grid cells to shift the block to the right.
  • pull: Number - Shift the block this number of cells to the left. This will make it overlap above with previous blocks.
  • push: Number - Shift the block this number of cells to the right. This will make it overlap under with the following blocks.
  • shrink: Number - Set the flex-shrink CSS property. Default 1.
  • size: String | Number - Set the flex-basis CSS property. Default auto.
  • span: Number - Number of grid cells the block should occupy.

Block layout properties usage examples:

Align example
- id: container
  type: Container
  blocks:
    - id: block1
      type: Block
      layout:
        span: 6
    - id: block2
      type: Block
      layout:
        align: top
        span: 6
    - id: block3
      type: Block
      layout:
        align: middle
        span: 6
    - id: block4
      type: Block
      layout:
        align: bottom
        span: 6
Block 1
Block 2
Block 3
Block 4

Area layout properties

Properties can be set on each area to control how blocks are layed out inside that area. These properties are set under the areaName key:

The properties that can be set are:

  • align: Enum - Align blocks vertically in the area. Options are top, middle, and bottom. Default top.
  • direction: Enum - Set the flex-direction CSS property for the area. Options are row, row-reverse, column, and and column-reverse. Default row.
  • gutter: Number | Array - Create gutter (space) between blocks placed in the area. If an array, the first element is the horizontal gutter, and the second is the vertical gutter.
  • justify: Enum - Justify blocks horizontally inside the area. Options are start, end, center, space-around, and space-between. Default start.
  • overflow: Enum - Set the overflow CSS property for the area. Options are visible, hidden, scroll, and space-between. Default visible.
  • wrap: Enum - Set the flex-wrap CSS property for the area. Options are wrap, nowrap, and wrap-reverse. Default wrap.

Area layout properties examples:

Align example
- id: container
  type: Container
  areas:
    area1:
      align: top
      blocks:
        - id: block1
          type: Block
          layout:
            span: 12
        - id: block2
          type: Block
          layout:
            span: 12
    area2:
      align: middle
      blocks:
        - id: block3
          type: Block
          layout:
            span: 12
        - id: block4
          type: Block
          layout:
            span: 12
    area3:
      align: bottom
      blocks:
        - id: block5
          type: Block
          layout:
            span: 12
        - id: block6
          type: Block
          layout:
            span: 12
Area 1 - align: top
Block 1
Block 2
Area 2 - align: middle
Block 3
Block 4
Area 3 - align: bottom
Block 5
Block 6