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

Creating a Generic Text Input Component Using Styled System CSS

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 a generic text input primitive component, that we could use to render headings of different levels in our app. We’ll use Styled System to create this component.

We’re going to use Styled System’s CSS package to define styles using our design tokens — values from our theme file.

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 @styled-system/css

Useful links and documentation:

Artem Sapegin: [0:00] First let's create a Markdown file with some examples, Input.md, inactive and disabled input states. Now create a component file, Input.js, and start styleguidist. Import styled-components. Import styled-system/css. Create a new styled component based on the input element, called css function from styled-system. Define some basic styles.

[0:39] The component will occupy all the available width. This makes it easier to use with the layout primitive, border of primary color with the base borderRadius, medium body font with the standard color and background. All these values are coming from our ZIM file.

[0:54] Define focus styles so our component could be used with the keyboard and define disabled styles. Now export our component and we have an input component with normal and disabled states.

egghead
egghead

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