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

Building User Interfaces by Composing Primitive React Components

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 compose a basic login form using all primitive components, we’ve created in the previous lessons. We’ll create a complete layout without writing any custom styles, just by composing primitive components: Box, Flex, Grid, Stack, Text, Heading, Link, Button, and Input.

We’ll create a login page as an example. It has a heading, a form with two text fields — login and password, a password reset link, a submit button, and a disclaimer text with a link.

Checkout this lesson’s Git repository for all the components we’re going to use.

Artem Sapegin: [0:00] First, let's create the Markdown file Login.md to be able to see our interface in styleguidist. Here, we only render a component without any props.

[0:09] Now, create a component file Login.js, and start styleguidist. Import React, and all our primitive components. Create a new component Login.

[0:22] Use the Flex component to center the content horizontally and vertically.

[0:31] Use the Stack component to add whitespace between the heading and the form. Then use the Stack again to add whitespace between form elements.

[0:42] Nesting stacks is a pattern I often use to create layouts. Usually, we need large spacing between main page sections, then smaller spacing between their subsections, and so on.

[0:52] Also, know that we're changing the default HTML element in primitives to main here and form here. This allows us to reduce the number of DOM nodes and make the markup lighter and more readable.

[1:04] The username field is straightforward. We're using the Stack again and change the HTML element to label. The password field is a bit more complex because we want to position the password reset link on the right side of the label.

[1:34] Remember that we need to wrap our link component and the text component with appropriate styles. Also, we're using an id to connect the label to the input. We can't wrap it in the label like the username field, because it could break the link.

[1:48] Create a submit button and a disclaimer text below the form.

egghead
egghead
~ a minute ago

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