This document aims to provide guidance for consumers on how best to compose Balance components, affording flexibility within the constraints of the system.
What is composition?
In React, composition is a natural pattern of the component model. It's how we
build components from other components, of varying complexity and specificity
through props. Depending on how adaptable these components are, they can be used
in building many other components.
How do I build this example for myself?
Designs like this are rarely built top-to-bottom in a single pass. Instead, they
typically start very simple, with further details and refinements added in
layers.
To give you a sense of what this looks like, the following tutorial will guide
you through the design process that you might go through when using Playroom.
At any stage you can click the “Open in Playroom” button under the examples to
view the design.
1. Create the basic content
Adding the basic content up front is a great place to start, allowing us to
consider the hierarchy of information as we iterate. We’ll apply some basic
formatting using Heading and Text.
<Text>Long description of pay summary providing more information.</Text>
<Text>2d ago</Text>
</>
2. Space out the content
You’ll notice that there is no space between components by default. This is
actually a good thing: we now get to decide exactly how spaced out we want the
content to be. To achieve this, we’ll use a Stack component
which applies space evenly between its child elements.
<Text>Long description of pay summary providing more information.</Text>
<Text>2d ago</Text>
</Stack>
3. Group content
Grouping the content into sections can help provide structure to the
information, and in turn, make it easier to digest. Let’s divide the information
into four descrete sections — the header, metadata, body and footer. For this,
we’ll start nesting new Stack components within our existing
Stack.
<Text>Long description of pay summary providing more information.</Text>
<Text>2d ago</Text>
</Stack>
</Stack>
4. Provide hierarchy
Not all the information presented has the same priority. To improve readability,
we can adjust the tone and/or the size of the
information. In this case, pushing some details back to “muted” and/or adjusting
their size can help focus the user’s attention.
Now let's put the header content back in, and place an IconButton beside it. Notice that we're using justify to influence the "space-between" elements.
<Text>Long description of pay summary providing more information.</Text>
<Textcolor="dim"size="small">
2d ago
</Text>
</Stack>
</Stack>
8. Polish
Now that we have all our elements in place we can polish until we are happy.
Adjusting white space between elements, or even responsively, to achieve the
desired goal.
In this case, we might loosen up the metadata section by increasing the gap to
“small”.