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