Flex
Flex lays out its children in a row or a column with an even gap between them. The named gaps come from the theme, so a toolbar or a form row keeps the same rhythm as the rest of the page. It is layout only: it draws nothing of its own.
Demos
Basic
A row that wraps when it runs out of room, with the medium gap.
Vertical and reverse
vertical stacks the items in a column; reverse flips their order in either direction.
Size
size takes a theme gap (small, medium, large), one number in px for both directions, or [horizontal, vertical] in px.
Justify and align
justify distributes the items along the row, align lines them up across it. Try the combinations on items of different heights.
Wrap
Items wrap onto new lines by default. With wrap={false} they stay on one line; here the items are allowed to shrink to fit. Vertical layouts never wrap.
Inline
inline makes the container inline-flex, so a small group can sit inside a line of text.
Props
| Name | Type | Default | Description | Version |
|---|---|---|---|---|
size | small | medium | large | number | [number, number] | medium | The gap between items: a theme gap, px for both directions, or [horizontal, vertical] in px. | Unreleased |
justify | start | end | center | flex-start | flex-end | space-between | space-around | space-evenly | start | How items are distributed along the main axis (justify-content). | Unreleased |
align | start | end | center | baseline | stretch | undefined | How items line up across the main axis (align-items). Unset keeps the CSS default, which stretches them. | Unreleased |
vertical | boolean | false | Stacks items in a column. | Unreleased |
reverse | boolean | false | Reverses the order of the items. | Unreleased |
wrap | boolean | true | Wraps items onto new lines when they run out of room. Ignored when vertical. | Unreleased |
inline | boolean | false | Uses inline-flex instead of flex. | Unreleased |
children | ReactNode | undefined | The items. With no children, Flex renders nothing. | Unreleased |
Flex renders a div and also accepts native div attributes and a ref. It adds no role; when the items form a group, such as a set of related actions, give it role="group" and an aria-label.
The named gaps are the --r-flex-gap-small, --r-flex-gap-medium and --r-flex-gap-large theme tokens, each a CSS gap value (row, then column).