Skip to content

feat: add tailwind theme support - #43616

Merged
ahmaxed merged 2 commits into
freeCodeCamp:mainfrom
ahmaxed:feat/add-tailwind-theme-support
Oct 11, 2021
Merged

ahmaxed merged 2 commits into
freeCodeCamp:mainfrom
ahmaxed:feat/add-tailwind-theme-support

Conversation

@ahmaxed

@ahmaxed ahmaxed commented Sep 29, 2021

Copy link
Copy Markdown
Member

Checklist:

  • I have read freeCodeCamp's contribution guidelines.
  • My pull request has a descriptive title (not a vague title like Update index.md)
  • My pull request targets the main branch of freeCodeCamp.
  • I have tested these changes either locally on my machine, or GitPod.

Closes #42186

This pull request adds theme support as described in #42186 by setting a list of colors variables that change based on the class of the html element.

Screen Shot 2021-09-29 at 3 42 15 PM

Note: Since color variables change based on the class of the HTML, I added a small hack and wrapped components in a div whose classes changes based on the theme argument. Once we find a better way to add theme controls, we could remove the wrapper.

@ahmaxed
ahmaxed requested a review from a team September 29, 2021 13:44
@gitpod-io

gitpod-io Bot commented Sep 29, 2021

Copy link
Copy Markdown

display: inline-block;
line-height: 1;
}
.storybook-button--primary {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aim is to completely get rid of custom css as much as possible. Here I cleaned what was relevant to the theme support for now.

Comment on lines +20 to +28
<div
className={`flex h-screen justify-center items-center ${
args.theme === 'dark'
? 'dark bg-dark-theme-background'
: 'light bg-light-theme-background'
}`}
>
<Button {...args} />
</div>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the hack that is mentioned in the pr description.

export interface ButtonProps {
primary?: boolean;
size?: ButtonSize;
backgroundColor?: string;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed since the color change logic will depend inside the button and will depend on the other props.

label: string;
customKey?: string;
onClick: () => void;
theme?: 'light' | 'dark';

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theme was added to accommodate the component wrapper in button story.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick question - our database uses "default" and "night" for the theme settings on the user profile. Does this need to match those values?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not be an issue since when we receive the user info, we can conditionally attach the relevant class to the html element.

Although it pays off to be consistent with naming all across, 'light'/'dark' seem to be the convention.

--green10: var(--green10);
--green90: var(--green90);
html,
div.light {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

div.light and div.dark selectors are added so we could change the wrapper's class conditionally and have the color variable change based on the selected theme.

Comment on lines +38 to +45
--default-foreground-primary: var(--gray90);
--default-foreground-secondary: var(--gray85);
--default-foreground-tertiary: var(--gray80);
--default-foreground-quaternary: var(--gray75);
--default-background-primary: var(--gray00);
--default-background-secondary: var(--gray05);
--default-background-tertiary: var(--gray10);
--default-background-quaternary: var(--gray15);

@ahmaxed ahmaxed Sep 29, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the default variables are added. The rest will be added upon use.

@github-actions github-actions Bot added the scope: tools/scripts Scripts for supporting dev work, generating config and build artifacts, etc. label Sep 29, 2021
@gikf gikf added the status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. label Oct 1, 2021
@ahmaxed ahmaxed mentioned this pull request Oct 6, 2021
7 of 43 tasks

@huyenltnguyen huyenltnguyen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahmadabdolsaheb Thanks for taking this over!

@huyenltnguyen huyenltnguyen removed the status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. label Oct 10, 2021
@ahmaxed
ahmaxed merged commit f56a561 into freeCodeCamp:main Oct 11, 2021
@ahmaxed ahmaxed mentioned this pull request Jan 4, 2022
37 of 49 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: tools/scripts Scripts for supporting dev work, generating config and build artifacts, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add color tokens to tailwind config file

5 participants