Layout

The guiding principle for layout in Braid is that components should not provide surrounding white space. Instead, spacing between elements is owned entirely by layout components. This approach ensures that the system is as composable as possible while keeping white space completely predictable.All of the components referenced below can be infinitely nested within each other to create a wide variety of standard layouts. Getting a firm grasp of these components is an essential part of working effectively with Braid.Braid provides a standard white space scale that is available across the entire component suite. As much as possible, Braid tries to make use of this scale rather than generating custom spacing rules.
none
xxsmall
xsmall
small
medium
large
xlarge
xxlarge
xxxlarge
In addition to the scale, Braid has a semantic value gutter — used to maintain consistent insets across components, e.g. Card, Alert, Button, etc. This value should only be used for aligning to this concept.
gutter
Box is the most low-level layout component provided by Braid. Its job is to render an individual element on the screen.In terms of page layout, Box most notably provides a set of padding options which can be used to create container elements with internal spacing.
  • padding
  • paddingX
  • paddingY
  • paddingTop
  • paddingBottom
  • paddingLeft
  • paddingRight
These options accept a value from our white space scale.For example, if you wanted to create a container element with small spacing on all sides:These also support the ‘responsive props’ format which allows you to specify a set of values for different screen sizes.For example, if you wanted small spacing on mobile but medium spacing from tablet upwards:If required, you’re also able to specify different values for larger screens.For example, if you wanted to set the previous example’s spacing to large on desktop and xlarge on wide:The most common white space on screen is between elements stacked vertically. For this use case, Braid provides a Stack component that accepts a ‘space’ prop.For example, if you wanted to render a stack of Heading and Text elements with large spacing between them:Just like Box, you can also specify different spacing values for different screen sizes:Multiple Stack components can be nested to create more complex white space rules. For example, if you wanted to create multiple grouped blocks of text like you might see in a Card:Stack also supports horizontal alignment. For example, if you wanted to centre align all of its content:Individual stack items can be hidden on different screen sizes by wrapping them with the Hidden component. For example, if you wanted to hide the second item in a stack on mobile:If you’d like to render a set of components in a row with equal spacing around them, wrapping onto multiple lines when necessary, Braid provides an Inline component:Similar to Stack, Inline also supports horizontal alignment of its children:If you’d like the items to stack vertically on smaller screens, you can provide the collapseBelow prop.For example, if you wanted buttons to be rendered vertically on mobile but horizontally from tablet upwards:If you need to lay out content horizontally, Braid provides the Columns and Column components:Similar to Inline, if you’d like the columns to stack vertically on smaller screens, you can provide the collapseBelow prop.For example, if you wanted cards to be rendered vertically on mobile but horizontally from tablet upwards:All columns are of equal width by default, but you can also customise the width of each column individually.For example, if you wanted to render a main content area and a sidebar, collapsing to a single column on mobile:If you want a column to be as small as possible, you can also set its width to content which ensures that it’s only as wide as the content within it.For example, if you wanted a column to be as large as its illustration followed by a second column that filled the space:By default, columns are rendered in document order, which also doubles as the screen reader order. If you need the columns to be visually reversed on larger screens, you can provide the reverse option:If you have columns that are of varying height, you can center them vertically with the alignY prop:If you’d like to spread components to opposite ends of a container while maintaining a minimum amount of space in between them, Braid provides the Spread component.An example might be a card with a left-aligned Heading and a right-aligned OverflowMenu:By default, components will be spread horizontally but you can change the direction to vertical by providing the direction prop.This is useful when aligning content vertically across containers while maintaining predicatable spacing — particularly when wrapping text comes into play.
Open in Playroom
If you’d like to render a grid of components with equal spacing between them, Braid provides a Tiles component:If you need to customise the spacing and number of columns per screen size, the columns prop is responsive. For example, if you wanted a single column on mobile and three columns from tablet upwards:By default, all layout components will render full width. However, most applications will want to limit the width of content on the screen. In order to address this, Braid provides the ContentBlock component that sets a maximum width and horizontally center-aligns the block by default.If you’d like to increase or decrease the width of the block, you can optionally provide the width prop:To manage line length or form field sizes you may choose to left-align the block. This can be done via the align prop:For top-level sections, in addition to limiting the width of content on the screen, it is also important to standardise the gutter between content and the edge of the screen. For this Braid provides the PageBlock component, which defines responsive gutters around a ContentBlock.To standardise our page-level block widths, the width prop accepts either small, medium or large.Additionally, a PageBlock can also choose a width of full. This allows content to extend to the full available width while still maintaining the standard responsive gutters.For establishing consistent page-level layout, Braid provides the Page component — responsible for managing the relationship between the footer and the main content. This ensures at a minimum the footer is always positioned at the bottom of the screen, pushed beyond as the page content grows.For pages with dynamic content it is recommended to place the footer out of view by setting the footerPosition prop to belowFold. This prevents the footer from popping in and out of view when the page content changes, e.g. toggling between a loading indicator and content.Sometimes it is necessary for a component to extend out into it’s surrounding layout. We can achieve this using the Bleed component.Consider the following example where we have a Card containing a header image, a Heading and some Text. The Card applies internal spacing, indenting the content from the edges of the container.If we want the image to run to the edges of the container, we can wrap it in a Bleed and define which direction and how far we want the image to bleed into the surrounding layout.In this case, let’s bleed horizontally and also out the top:Given this is achieved using negative margins, it is important to ensure that size and direction of the bleed is accommodated by the parent layout. In this case, ensure we do not choose bleed values that exceed the indent of the parent Card component.