Composition
Layout props say how to declare spacing and alignment; this page says where
they belong. Screens often grow a staircase of
Flex wrappers that each push a single child. Every step is
one more DOM node to render and hydrate, and one more place where layout can be overridden.Guides
The rule
An Apollion leaf is already a flex container. Create a Flex or Grid only when it has two or more
children on one axis or changes direction. A single child's spacing and alignment go on the child.
Keep the wrapper when it carries meaning: as="li" or as="nav" for semantics, clipping around an Image
(borderRadius with overflow), a surface with its own background (a Paper), or a one-dimensional page
shell. Use Grid for two-dimensional regions instead of nested Flex.
A single-child wrapper, and the same result without it
How it works
Check what the leaf accepts before you wrap it:
Component | Flex container | Spacing props | Note |
|---|---|---|---|
Flex, Grid | yes | yes | layout only — no background or border |
Paper, Card | yes | yes | surfaces: background, border, elevation |
Button | yes | yes | icon and text alignment are internal |
Text, Label | Text yes | yes | full typography and spacing set |
Link | no | no | display, position, typography and color only |
Image, inputs | no | no | grid placement only ( area, alignSelf) |
Scrolls sideways inside the table. The page does not.
When the leaf accepts the prop, put it there. When it does not, the wrapper is justified.
// Wrong: the Flex exists only to carry the margin <Flex mb="medium"> <Button text="Save" /> </Flex> // Right: the spacing lives on the Button <Button text="Save" mb="medium" />
Pitfalls
- Layout props on a
Link(flexDirection,gap,p) → they are dropped silently. Give the link a single child, or wrap the content in aFlexinside the link. - A caption stacked next to a logo inside a link → if the caption describes the image, make it the image's
alt; it then also names the link, and the axis disappears. - A leftover
style={{…}}→ mark it in code and report it as a missing prop rather than keeping silent debt.