Add color tokens to tailwind config file
See original GitHub issueWe are in the progress of building a component library, and TailwindCSS is what we use for component theming.
The config file has been created, and further configurations will be added in the future. For now, we need to add color tokens to the file, in the colors
object.
Link to the config file: https://github.com/freeCodeCamp/freeCodeCamp/blob/main/tools/ui-components/tailwind.config.js#L5
Colors to be added:
- Layout colors: https://design-style-guide.freecodecamp.org/#layout-colors
- Accent colors: https://design-style-guide.freecodecamp.org/#accent-colors
- Any colors in here that the design style guide does not have: https://github.com/freeCodeCamp/freeCodeCamp/blob/main/client/src/components/layouts/variables.css
Convention:
- Token names are in camelCase
- Tokens for dark theme colors are suffixed with the word
dark
. Tokens for light theme can stay as is. For example:primaryColor
andprimaryColorDark
,secondaryColor
andsecondaryColorDark
, etc. - Tokens are sorted alphabetically
Issue Analytics
- State:
- Created 2 years ago
- Comments:24 (24 by maintainers)
Top Results From Across the Web
Customizing Colors - Tailwind CSS
Using custom colors. If you'd like to completely replace the default color palette with your own custom colors, add your colors directly under...
Read more >Integrating Design Tokens With Tailwind - Michael Mangialardi
For our tutorial, we are going to override the default colors that come with Tailwind with the tokens that are in the tokens.js...
Read more >How to use the Color Tokens from your Design System directly ...
Find out how to use your design system's color tokens directly in Tailwind CSS, and how to keep those token colors updated in...
Read more >Using Style Dictionary to transform Tailwind config into SCSS ...
Using Style Dictionary to transform Tailwind config into SCSS variables, CSS custom properties, and JavaScript via design tokens · Installation.
Read more >How to sync your design tokens from Figma to Tailwind - Specify
Our configuration is almost done but we still need to change a couple of things: We must set the Specify repository we're pulling...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Do you see
gray-foreground-primary
,gray-background-primary
,… as names for color variables (those incolors.css
), or for the semantic colors (those in the config file)?My take on this is that, semantic colors won’t have anything that refers to the actual color they use. An example can be the Alert component. Bootstrap and Material UI call the variants
success
,info
,warning
, … instead ofgreen
,blue
,yellow
.So I guess
gray-foreground-primary
would be a color in the variable file, and it is mapped to, say,default-foreground-primary
in the config file. Thenred-foreground-primary
would be something likedanger-foreground-primary
, etc.With the colors are already added to
colors.css
, our next step is to map them to semantic tokens in the config file. Since the naming of colors in both layers will need to be adjusted again once the design style guide gets new updates, are you okay with me coming up with some temporary tokens for now?Though I think I should do it incrementally as I build the components, rather than assuming what each color means right now and add their tokens in bulk.
@ahmadabdolsaheb hope you could weigh in on this. To sum up the entire discussion, there are two approaches we can take regarding dark theme support:
.night
selector for dark mode.dark
class as Tailwind uses it as the theme identifierbg-colorA
,focus:bg-colorB
,hover:bg-colorC
,dark:bg-colorD
,dark:focus:bg-colorE
,… )I think approach (1) is more viable. This is not saying that we shouldn’t use Tailwind classes at all, as I reckon it will be very useful and convenient when it comes to handling layout. But for dark theme styling specifically, I think we are better off with our current way of writing CSS.