General purpose layout component with consistent spacing and positioning
Stack is a layout component that acts as an abstraction over flexbox that has all of our spacing tokens baked into it. It allows you to easily add spacing, padding, alignment and positioning to a set of elements.
Default
By default, Stack will set up a flexbox container with elements flowing in a column (i.e.flex-direction: column) with no spacing, padding or other positioning logic.
Padding and gap props all allow setting values to apply at specific responsive breakpoints. This allows you to customise gap and padding to fit different screen sizes better.
Here's an example that changes the gap spacing between the ExampleContent elements based on viewport, and the padding inside each ExampleContent:
<Text>Resize viewport width to see spacing change</Text>
</ExampleContent>
</Stack>
Usage with Figma designs
Stack also works really well with auto-layout in Figma, you can directly plug in the spacing tokens as padding/gap values from dev mode.
Note you’ll only get the nice s, m, l values if the design is using auto-layout (and the designer has selected a spacing var for all the gaps/padding), which we don’t always use for everything. If you see raw pixel values you’ll still need to translate them to use the .