Skip to the content

Flex

Flex is the default layout container: a <div> with display: flex that arranges its children with token spacing, direction and alignment. It is layout only — no background, border, shadow or typography. When a block needs a visible surface, use Paper.
Layout & Surfaces@apollion-dsi/core/containers/flex19.1 kB gzip

When to use

Use when
  • You arrange children in a row or column with token spacing (gap).
  • You align, wrap or reorder children without writing a styled component.
  • You decide how each child grows or shrinks (flex).
Avoid when
  • The block needs a background, border or shadow — use Paper or Card.
  • The layout is two-dimensional or has named areas — use Grid.
  • You only need a neutral block, or to hide content per slot — use Box.

Usage

flexDirection defaults to column. gap takes a spacing token.

loading

Sizing children (flex)

Set flex on a child to choose how it shares the free space:

  • fluid — 1 1 0%: grows and shrinks, ignoring its content size.
  • auto — 1 1 auto: grows and shrinks from its content size.
  • initial — 0 1 auto: never grows, shrinks when needed.
  • none — neither grows nor shrinks; pins a child between fluid siblings.
fluid
none — fixed
fluid
<Flex flexDirection="row" wrap="wrap" gap="small">
  <Paper flex="fluid">…</Paper>
  <Paper flex="none">…</Paper>
  <Paper flex="fluid">…</Paper>
</Flex>

Inline flex (display)

A Flex is always a flex container. display picks the variant: flex (default, block-level) or inline-flex (flows inside text). To hide a Flex in a slot, use a responsive channel: cq={{ md: { display: 'none' } }}.

Status:
●online
— the badge sits in the sentence.
<Text>
  Status:{' '}
  <Flex display="inline-flex" flexDirection="row" gap="micro">
    …
  </Flex>
</Text>

Responsive layout

Base props are the mobile style. cq reacts to the width of the container's own slot (see Container Queries); viewportMedias reacts to the viewport and suits page shells. Both take one object per size and carry layout props only.

<Flex gap="small" cq={{ md: { flexDirection: 'row', gap: 'large' } }} />

<Flex viewportMedias={{ md: { flexDirection: 'row' }, xl: { p: 'small' } }} />

To type a layout object that also sets as, annotate it as FlexProps:

import type { FlexProps } from '@apollion-dsi/core/containers/flex';

const shell: FlexProps = { as: 'section', gap: 'large', viewportMedias: { md: { flexDirection: 'row' } } };

Accessibility

  • Flex renders a plain <div> with no role. Use as (section, nav, ul) when the group has meaning.
  • row-reverse, column-reverse and order change the visual order only. Focus and screen-reader order follow the DOM, so keep the source order logical.

Properties

Flex takes the layout props — spacing, size, position, the flex props and the cq / viewportMedias channels — plus display and the native <div> attributes.

See also