Create a Generic Text Component Using Styled System Variants

Artem Sapegin
InstructorArtem Sapegin
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

In this lesson we’ll create a generic text primitive component, that we could use to render any text in our app. We’ll use Styled System and its variants feature to create this component.

Styled System variants allow us to change multiple style attributes with a single component prop. We’re going to use variants to switch between different text styles.

There are two ways to define variants in Styled System: in the theme file, and in the component file. The first method is good when you want to later redefine styles for a part of your app using nested theme providers, or want to reuse the same component on several apps. The second method is a bit simpler, so we’re going to use it in this lesson.

The number of variants depends on your app. You’ll need to find the minimum number of text styles to cover most use cases. Talk to your designer, they may already have what you need. In this lesson we’ll implement a few basic styles that are often used in web applications.

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:

egghead
egghead
~ an hour 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