Flex
Examples
Basic example
A basic Jutro flex container consists of a Flex component with a number of children components. If these children are FlexItem components, you can use the additional FlexItem props to have further control of the item within the layout.
By default, the Jutro Flex component has the wrap property set to true. That means your items try to fit in the available horizontal space, but if they cannot, they appear in subsequent lines.
<Flex>
<FlexItem>
<strong>First item</strong>
</FlexItem>
<FlexItem>
<strong>Second item</strong>
</FlexItem>
<FlexItem>
<strong>Third item</strong>
</FlexItem>
</Flex>
gap example
The gap property is used to set the distance between the columns in a flex container.
<h3>Small</h3>
<Flex gap="small">
<FlexItem>
<strong>First item</strong>
</FlexItem>
<FlexItem>
<strong>Second item</strong>
</FlexItem>
<FlexItem>
<strong>Third item</strong>
</FlexItem>
</Flex>
<h3>Medium</h3>
<Flex gap="medium">
<FlexItem>
<strong>First item</strong>
</FlexItem>
<FlexItem>
<strong>Second item</strong>
</FlexItem>
<FlexItem>
<strong>Third item</strong>
</FlexItem>
</Flex>
<h3>Large</h3>
<Flex gap="large">
<FlexItem>
<strong>First item</strong>
</FlexItem>
<FlexItem>
<strong>Second item</strong>
</FlexItem>
<FlexItem>
<strong>Third item</strong>
</FlexItem>
</Flex>
<h3>None</h3>
<Flex gap="none">
<FlexItem>
<strong>First item</strong>
</FlexItem>
<FlexItem>
<strong>Second item</strong>
</FlexItem>
<FlexItem>
<strong>Third item</strong>
</FlexItem>
</Flex>
direction example
The direction property sets the initial arrangement of items in a flex container. Its default value is row which means items are put on the same row if there is space, starting from the left side of the screen as seen in the previous examples.
If you set direction to rowReverse, the items will be put on the same row starting from the right hand side of the screen.
<Flex direction='rowReverse'>
<FlexItem>
<strong>First item</strong>
</FlexItem>
<FlexItem>
<strong>Second item</strong>
</FlexItem>
<FlexItem>
<strong>Third item</strong>
</FlexItem>
</Flex>
If you set direction to column or columnReverse, the items will be vertically arranged from top to bottom or from bottom to top respectively.
<Flex direction='column'>
<FlexItem>
<strong>First item</strong>
</FlexItem>
<FlexItem>
<strong>Second item</strong>
</FlexItem>
<FlexItem>
<strong>Third item</strong>
</FlexItem>
</Flex>
<Flex direction='columnReverse'>
<FlexItem>
<strong>Fourth item</strong>
</FlexItem>
<FlexItem>
<strong>Fifth item</strong>
</FlexItem>
<FlexItem>
<strong>Sixth item</strong>
</FlexItem>
</Flex>
Usage
The Flex component is a technical component that facilitates the use of Flex CSS styling. For usage recommendations, see the official flexbox documentation.
Code
<Flex>
<FlexItem>
<strong>First item</strong>
</FlexItem>
<FlexItem>
<strong>Second item</strong>
</FlexItem>
<FlexItem>
<strong>Third item</strong>
</FlexItem>
</Flex>
Import statement
import { Flex, FlexItem } from '@jutro/layout';
Component contract
Make sure to understand the Design System components API surface, and the implications and trade-offs. Learn more in our introduction to the component API.
Properties
Flex properties
alignContent- Type
'center' | 'baseline' | 'stretch' | 'start' | 'end'DescriptionAligns the flex within its container in the axis opposite to its direction.
alignItems- Type
'center' | 'baseline' | 'stretch' | 'start' | 'end'DescriptionAligns all items within the grid in the axis opposite to its direction.
direction- Type
'row' | 'rowReverse' | 'column' | 'columnReverse'DescriptionSets the flex direction.
Default value'row' gap- Type
'none' | 'small' | 'medium' | 'large'DescriptionThe size of the gaps between rows and columns.
justifyContent- Type
'center' | 'baseline' | 'stretch' | 'start' | 'end'DescriptionJustifies the content in the flex direction: horizontally if direction is 'row' (default) or vertically if direction is 'column'.
tag- Type
stringDescriptionOptional DOM tag to render.
Default value'div' wrap- Type
boolean | 'true' | 'false' | 'reverse'DescriptionWrap (true), don't wrap (false), reverse wrap (reverse) flex items in the container.
phonedeprecated- Type
stringDescriptionFlex properties that are used at the
phonebreakpoint. phoneWidedeprecated- Type
stringDescriptionFlex properties that are used at the
phoneWidebreakpoint. tabletdeprecated- Type
FlexDescriptionFlex properties that are used at the
tabletbreakpoint. themedeprecated- Type
anyDescriptionProp 'theme' is unused in the component and has no effect.
FlexItem properties
alignSelf- Type
'center' | 'baseline' | 'stretch' | 'start' | 'end'DescriptionAligns the flex item according to the cross axis of the flex direction.
basis- Type
number | stringDescriptionSpecifies the initial length of a flex item.
grow- Type
number | stringDescriptionThe standard flex grow property.
shrink- Type
number | stringDescriptionThe standard flex shrink property.
tag- Type
stringDescriptionOptional DOM tag to render.
Default value'div' textAligndeprecated- Type
'left' | 'center' | 'right'DescriptionAligns the contents of the column horizontally.
visibledeprecated- Type
booleanDescriptionIf set to
false, theFlexItemis hidden. In any other case, theFlexItemis displayed.
Hooks
No hooks are available for Flex.
Translation keys
There are no translations for Flex.
For information on how to manage translations, see our section about Internationalization.
Escape hatches
For more information, see our documentation about escape hatches.
Changelog
10.9.0
Flex changes in 10.9.0
The following Flex properties have been deprecated:
tabletphoneWidephone
The following options for Flex properties have been deprecated:
alignItems-'top','middle','bottom','right', and'left'alignContent-'top','middle','bottom','right', and'left'justifyContent-'top','middle','bottom','right', and'left'
FlexItem changes in 10.9.0
The following FlexItem properties have been deprecated:
tabletphoneWidephonevisibletextAlign
The following options for FlexItem properties have been deprecated:
alignSelf-'top','middle','bottom','right', and'left'