Repository navigation
feat: use system theme if default - #48568
Conversation
|
👀 Review this PR in a CodeSee Review Map |
|
I have turn this to draft because of Draft PR mention. About the code itself, it works but if someone has the system default to dark, they can't access light mode Just wondering is it better to wrap the values in @media (prefers-color-scheme: dark) {
.dark-palette {
--primary-color: var(--gray-00);
--secondary-color: var(--gray-05);
--tertiary-color: var(--gray-10);
--quaternary-color: var(--gray-15);
--quaternary-background: var(--gray-75);
--tertiary-background: var(--gray-80);
--secondary-background: var(--gray-85);
--primary-background: var(--gray-90);
--highlight-color: var(--blue-light);
--highlight-background: var(--blue-dark);
--selection-color: var(--blue-light-translucent);
--success-color: var(--green-light);
--success-background: var(--green-dark);
--danger-color: var(--red-light);
--danger-background: var(--red-dark);
--love-color: var(--love-light);
--editor-background: var(--editor-background-dark);
}
}
@media (prefers-color-scheme: light) {
.light-palette {
--primary-color: var(--gray-90);
--secondary-color: var(--gray-85);
--tertiary-color: var(--gray-80);
--quaternary-color: var(--gray-75);
--quaternary-background: var(--gray-15);
--tertiary-background: var(--gray-10);
--secondary-background: var(--gray-05);
--primary-background: var(--gray-00);
--highlight-color: var(--blue-dark);
--highlight-background: var(--blue-light);
--selection-color: var(--blue-dark-translucent);
--success-color: var(--green-dark);
--success-background: var(--green-light);
--danger-color: var(--red-dark);
--danger-background: var(--red-light);
--love-color: var(--love-dark);
--editor-background: var(--editor-background-light);
}
}I know there confusion of what is needed, so here are the requirements
|
|
I have tested the suggestion below and it breaks the website, in weird ways. need to investigate deeply why later.
|
|
I have updated the pull request with the new code, and read the ideas in the Discord server. When a camper is logged out, they will be using their system settings for the theme. When the camper is logged in, their theme settings will be based off of the Night Mode toggle in the drop down or user settings, this way they can toggle between dark and light mode still. |
Sboonny
left a comment
There was a problem hiding this comment.
Thank you for the awesome work, this should solve what Naomi asked in #47299 (comment)
Although, there is a point for convenient, I think this is an improvement and the point can be handled in 2nd PR. I am okay with this being merged, if no one else have issue with it being merged.
I have tested this, here is my tests:
- While signed out
- if I set the browser appearance in the setting to system, it is respected
- if I set the browser appearance in the setting to light, it is respected
- if I set the browser appearance in the setting to dark, it is respected
- While signned in
- if I set the browser appearance to dark, it is respected. (although this is inconvenient, it isn't something that I would worry about currently, as the user has the ability to change it, and we save this in the database for future usage)
- if I opt into night mode, my preference is updated
- if I opt into light mode, my preference is updated
Co-authored-by: Muhammed Mustafa <[email protected]>
Co-authored-by: Muhammed Mustafa <[email protected]>
Sboonny
left a comment
There was a problem hiding this comment.
LGTM 🎉, thank you for your contribution to the page! 👍.
Sembauke
left a comment
There was a problem hiding this comment.
Shown in the video above I can still not change my theme to light if I want to.
@Sembauke thanks for letting me know. I wonder if it has anything to do with Safari. Did you test it on another browser by any chance? I'll look into this. |
I wish but unfortunately, I didn't do my due diligence. The setting is using component that use theme.tsx, in theme.tsx there is this logic that stops the theme from changing in the setting page toggleFlag={() => {
toggleNightMode(
currentTheme === Themes.Night ? Themes.Default : Themes.Night
);
}}Applying similar changes there should fix this, here is the link https://github.com/bryanleemoore/freeCodeCamp/blob/a4c459365cf63763c38ed96538b3f2a18d482a6d/client/src/components/settings/theme.tsx#L34-L38 |
I figured it out. It had to do with the previous change from Because Changing |
|
Thanks it works great! |
* feat: use system theme if default * feat: add system to theme * feat: detect if system theme should be used * fix: remove system from Themes * fix: change 'system' to 'default' Co-authored-by: Muhammed Mustafa <[email protected]> * fix: change 'system' to 'default' Co-authored-by: Muhammed Mustafa <[email protected]> * fix: check if user is logged in for system theme Co-authored-by: Muhammed Mustafa <[email protected]>



Checklist:
Update index.md)mainbranch of freeCodeCamp.Closes #47299
Draft PR. Currently, it solves issue #47299 by checking if the user has night mode toggled on or theme set to
night(must be logged in). If the user is either not logged in or the user has night mode toggled off, the theme is considered to be set todefault. If the theme is set todefault, then the user's system theme settings are used instead.While it seems to resolve the short term issue, probably more will need to be added. Whether have it so this setting only applies to logged out users, or rework the setting button so users can choose between system settings or custom settings for theme (as discussed in the Discord server).