⚠️ This lesson is retired and might contain outdated information.

Creating the Flex Layout Primitive Component Using Styled System

Artem Sapegin
InstructorArtem Sapegin
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 2 years ago

In this lesson we’ll create the Flex layout primitive component, that will allow us (together with other layout primitives) to create almost any complex layout without writing custom CSS. We’ll use Styled System to create this component.

Flex is a shortcut to create Flexbox layouts: it’s based on the Box component but defines display: flex. We can use it like this:

<Flex justifyContent="space-between">
  <Box mr={3}>Foo</Box>
  <Box>Bar</Box>
</Flex>

This will create two <div>s aligned at the left and right sides of the Flexbox container with a minimum gap of 8 pixels (third step in our spacing scale).

We’ll use following libraries:

You can either use this lesson’s Git repository or install them manually in your project:

npm install styled-components styled-system

Useful links and documentation:

Artem Sapegin: [0:00] Create a new markdown file, Flex.md. Add some examples. Create a JavaScript file, Flex.js. Import styled-components and our Box component.

[0:11] We're creating a new styled-component. This time, it's not a div, but it is based on the Box component. The only thing we need to change is define display: 'flex' and export it. We can reuse the propTypes of the Box component because they are the same.

egghead
egghead
~ just now

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today