Responsive layout
Last updated
Last updated
Responsive is a crucial part of any layout implementation. That's why its concept lies in the core of Atomic Layout design, as responsive is integrated by default.
Implementation of responsive layout has two parts:
Conditional (responsive) areas;
Conditional props assignment (gap
, margin
, etc.);
In this section we are going to take a look at how to implement these fundamentals. Make sure to be familiar with the basics of the library before you continue reading.
Any grid area that is not present in all template declarations automatically becomes responsive.
We have two template declarations above: one for mobile and one for the desktop screen. Areas thumbnail
, heading
and subheading
are present in both template declarations. However, the meta
area is declared in templateDesktop
only. This makes meta
a conditional area automatically.
Note that template declaration alone has no effect over responsive area rendering. Make sure to supply the template declaration to the respective template prop(s).
To connect a template declaration with a breakpoint we need to pass the template string to the template prop.
Having different areas in different template declarations only signifies conditional areas. In order to control the breakpoints where those areas are rendered, we need to pass templates declarations to the template
props of the Composition
component:
The composition above will wrap Meta
grid area in a <MediaQuery/>
component from react-responsive. This area will render on lg
breakpoint and up, because there is no succeeding template declaration that would contradict that, and because "up" is the default responsive behavior.
Any prop name suffixed with a breakpoint name becomes responsive. This means that its value is applied at the given breakpoint.
We have already used a responsive prop in the example above. By suffixing template
with the Lg
, we stated that the given value must be applied on the lg
breakpoint and up. Following this example, let's create a different gutter between the grid areas on different breakpoints:
There are two props we have added: gutter
and gutterLg
.
gutter
adds a grid-gap
of 10px
on mobile screens, since xs
is the default breakpoint,
gutterLg
adds a grid-gap
of 20px
on large screens and up, since up
is the default behavior.
You can configure custom breakpoints, default breakpoint and default behavior. Responsive props will abide by your settings.