Flex is a layout component with a very limited subset of the props available to Box and a few special props of its own.
Use this component for flex layouts, especially when even spacing between elements is desired (see the 'gap' property!).
Props
Subcomponents
Flex.Item Props
Variants
Flex Layout
Flex is strictly for flex layouts. If you're new to flex layout, please read the excellent CSS-Tricks guide to flexbox.
Menu
With a limited set of props that only relate to flex layouts, Flex is useful for separating layout from other concerns to prevent overloaded Box usage.
Applying flex properties to children
When using the 'gap' property, Flex wraps each child in a Flex.Item sub-component. If one of more of those children need custom flex properties, you can use Flex.Item directly.
Initial item width using flexBasis
If an item needs a different width in the flex layout than the content would otherwise indicate, flexBasis
can be used.
Overflowing children and minWidth
Extra-wide children can sometimes overflow the Flex parent container, breaking the layout (and skipping truncation, if applicable).
To fix this, simply wrap the wide child in Flex.Item with minWidth={0}
. Voila!
For more info, check out this very helpful blog post.