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

Create Design Tokens for Colors, Font Sizes, and Whitespace Using styled-components

Artem Sapegin
InstructorArtem Sapegin
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 2 years ago

The first thing we need to do when we start a new project is to define all fonts, font sizes, colors, and spacing values, we’re going to use; because we want to make sure that our user interface is consistent across the project. These values are called design tokens or a theme, and they are the single source of truth for our “design decisions”.

In this lesson we’ll create a theme file (theme.js) with constants for colors, fonts, font sizes, spacing, border radii, etc., so these values are available to our components.

In a real project, we’ll need to talk to our designer, and probably do a design audit first, but for simplicity, we’ll pretend that we’ve done that before, and already know all the values.

There are many ways to define design tokens, like Sass or CSS variables, JSON file or a plain JavaScript object. We’re going to use a JavaScript object following a so-called Theme Spec, which defines the shape of the theme. Theme Spec is used by tools like styled-system, which we’re going to use to create primitive components in the following lessons.

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

Useful links and documentation:

egghead
egghead
~ 26 minutes 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