Repository navigation
chore(tools): split color tokens to separate layers - #42388
Conversation
98a08cf to
8ef3687
Compare
| @@ -0,0 +1,69 @@ | |||
| import React from 'react'; | |||
There was a problem hiding this comment.
This file is quite crazy. It is to create the color palettes as React components and then display on Storybook.
To render them, we first import the color list from colors.css, which comes in as an object:
{
'--gray00': '#ffffff'
'--gray05': '#f5f6f7',
...
}In order to access the list a bit easier, I map the object to an array of object via the transformedColorList function. The list is now
[
{ label: 'gray00', value: '#ffffff' },
{ label: 'gray05', value: '#f5f6f7' },
...
]Each object in the list will be rendered as a palette item. The object's value is the background color of the item, while the label is the text, which is handled by the getPaletteItemStyle function. To ensure the text is readable, I do the parseInt trick to check where the color is on the scale, and set the text color to white if the color shade is dark and vice versa.
The Palette component is a single palette for each color, which renders its available shades into each row. The AllPalettes component is the combination of all the palettes we have.
There was a problem hiding this comment.
Great trick.
I wonder if we should be pulling these colors directly from tailwind once we have the variables setup?
There was a problem hiding this comment.
The color names are fine for now but could introduce a naming convention down the road for the colors.css. Since the number next to the color is referred to the mix ratio of the colors in the gray white gradient instance, we might need to separate the colors that are pure from the colors that are mixed to be used for background and foreground.
Additionally a double digit for the alpha of the translucent colors.
There was a problem hiding this comment.
I wonder if we should be pulling these colors directly from tailwind once we have the variables setup?
Are you referring to the tokens in the Tailwind config? Yeah I think it would make more sense to display those tokens instead on Storybook, as we kind of want to hide the colors.css layer and try to communicate using semantic names.
Though I guess we can show both ¯\_(ツ)_/¯ . I would think it's convenient for you still, to be able to check how a color would fit when developing the new palette. I initially didn't plan to display these on Storybook yet, but had to eventually, as I needed to give the variables in colors.css a new name and I couldn't tell which should be which without the ramp 😛
| // ---------------------------------------------------------- // | ||
| const Palette = ({ colors }) => { | ||
| return ( | ||
| <div className='inline-flex flex-col m-4 w-3/12'> |
There was a problem hiding this comment.
I took this as an opportunity to learn Tailwind, but now that I got a taste of it, I'm not sure if I like it to be honest 😅 I find it quite annoying to have to look up for a class name for each CSS attribute, and our markup might get messy very quickly if the styling is intense. Though that's just an opinion of someone who has been so used to writing CSS in the abstraction way.
A note here is that Tailwind uses REM as the default unit, so we will need to have some pixel mapping in order to use utility classes.
There was a problem hiding this comment.
I agree with you, but the good thing is that you set the classes once and you forget about them.
We might be able to get away it if we keep REM first approach when migrating the components.
| const story = { | ||
| title: 'Design System/Color', | ||
| component: AllPalettes | ||
| }; | ||
|
|
||
| export const ColorSystem = () => <AllPalettes />; | ||
|
|
||
| export default story; |
There was a problem hiding this comment.
This is the way we write our story page.
We need to export default an object that has title, which is the path of the component on the sidebar, and a component, which Storybook will use to extract the props and description and display on the page.
ColorSystem is a component that wraps around the component we want to render (AllPalettes). It needs to be named-exported so that Storybook can display it as a story under the Design System/Color section.
| --yellow10: #ffc300; | ||
| --yellow20: #ffbf00; |
There was a problem hiding this comment.
I keep these two as the values are different but they are almost the same visually, so we might want to revisit and drop one.
| --red20: #f8577c; | ||
| --red80: #f82153; |
There was a problem hiding this comment.
These are is the love color used in light and dark themes respectively. Since this file is for the actual color names, I renamed them to red20 and red80 (not sure which number to give tbh, I just compared them to the other reds and assigned the number based on where they should be on the scale).
There was a problem hiding this comment.
This is fine for now. We will revisit colors and their "actual" naming down the line.
| // Colors in variables.css | ||
| blueMid: '#198eee', | ||
| blueTranslucent: 'rgba(0, 46, 173, 0.3)', | ||
| blueTranslucentDark: 'rgba(153, 201, 255, 0.3)', |
There was a problem hiding this comment.
This is the same as #99c9ff (line 18), so I merged it to blue30 in the colors.css file.
| darkYellow: '#4d3800', | ||
| // Colors in variables.css | ||
| blueMid: '#198eee', | ||
| blueTranslucent: 'rgba(0, 46, 173, 0.3)', |
There was a problem hiding this comment.
This is the same as #002ead (line 23), so I merged it to blue90 in the colors.css file.
| blueMid: '#198eee', | ||
| blueTranslucent: 'rgba(0, 46, 173, 0.3)', | ||
| blueTranslucentDark: 'rgba(153, 201, 255, 0.3)', | ||
| editorBackgroundDark: '#2a2b40', |
There was a problem hiding this comment.
Removed as this is basically gray80, and I don't believe the token belongs here. It is more appropriate as a /learn color token, I think.
| editorBackgroundDark: '#2a2b40', | ||
| loveDark: '#f82153', | ||
| darkRed: '#850000', | ||
| editorBackground: '#fffffe', |
There was a problem hiding this comment.
Removed as this is basically gray00, and same as above, it is a /learn color token rather than one in the component library.
| red: '#ffadad', | ||
| yellowGold: '#ffbf00', | ||
| yellowLight: '#ffc300' | ||
| fccSecondary: 'var(--green90)' |
There was a problem hiding this comment.
No idea how the token name should actually be. It was darkGreen before this change, but we don't use that name in this layer anymore.
There was a problem hiding this comment.
see the following regarding naming convention: #42186 (comment)
Checklist:
Update index.md)mainbranch of freeCodeCamp.In #42186 (comment), we decided to split the color variables into 2 layers: one keeps them with their actual color names (red, blue, green,...); and the other refers to the color by their usage (background, foreground,...). Furthermore, @ahmadabdolsaheb and I decided to use numbers in the color names (similar to
gray10,gray20) in place oflightGreen,darkGreen, etc. This will keep the naming consistent, as well as allowing us to add more shades to the colors in the future.This PR partially addresses that by:
colors.cssinui-componentsto store the color values, which is the first layer I mentioned abovetailwind.config.jstocolors.css. The config file will contain color tokens, which is the second layerWhat this PR does not address are:
tailwind.config.js. I might need some help with this part, as I haven't been working a lot with our design system. Though I think I could try to propose/add the tokens in as we move to the component development phaseScreenshot