Styled JSX
Styled JSX is a CSS-in-JS library that allows you to write encapsulated and scoped CSS to style your components. The styles you introduce for one component won't affect other components, allowing you to add, change and delete styles without worrying about unintended side effects.
Creating a site theme
Inside colors.js add your color palette. The color tokens will be an object containing the values in increments of 100 which will allow us to access them using the syntax blue[100].
// utils/colors.js
export const blue = {
100: "#3a36e0",
200: "#0804b8",
300: "#030086",
400: "#5f25a4",
500: "#050449"
};
export const green = {
100: "#529e66",
200: "#367b48",
300: "#276738"
};
export const yellow = {
100: "#e1c542",
200: "#cab23f",
300: "#b49e35"
};
export const red = {
100: "#d0454c",
200: "#b54248",
300: "#95353a"
};
export const neutral = {
100: "#ffffff",
200: "#f4f5f7",
300: "#e1e1e1",
400: "#737581",
500: "#4a4b53",
600: "#000000"
};typography.js
theme.js
Add an index.js file inside of utils/ which exports each utility.
This will allow us to import utilities from the utils folder instead of the individual folder.
Finally let's use our theme inside of our Buttons.js file
You can then use those styles in your component:
Adding global styles
To apply global styles to all pages in our app, a good approach is to first create a layout component with the global styles, then wrap all pages with it.
Using a layout component provides the flexibility to apply a certain set of styles to some pages while still allowing a different style for others.
Last updated
Was this helpful?