There's a faster version of egghead. Click here to try it.
1×
Become a member
to unlock all features

Create an egghead account to access 5000+ tutorials and resources from expert developers.

Create account
Autoplay

    Creating the Flex Layout Primitive Component Using Styled System

    reactReact

    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:

    jsx<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: