New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add background color based on the OS mode #7117
add background color based on the OS mode #7117
Conversation
🪼 branch checks and previews
|
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
Hey @aileenvl! Thanks for this PR; this is a great idea! I have just tweaked it a little so instead of using JS to set the color, we use static CSS instead. This way we can guarantee we never have any flashes by putting it right at the top of the head. This did require some changes to the build config but seems to be working now. I also added a default font until our custom fonts load in. There is no flashing now and the font switch is pretty subtle. Thanks again! |
body { | ||
background: white; | ||
color: black; | ||
font-family: Arial, Helvetica, sans-serif; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prevents the janky switch from a default serif to our sans-serif.
@@ -115,6 +115,7 @@ export default defineConfig(({ mode }) => { | |||
} else if ( | |||
selector.indexOf(":root") > -1 || | |||
selector.indexOf("dark") > -1 || | |||
selector.indexOf("body") > -1 || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to add a prefix to body
selectors, that breaks them.
Is there any we we can use the theme variables, |
We can but we would have to define it right alongside the definition (which seems pointless to me at least) because the styles where we define those things haven't loaded yet, they get loaded in by the gradio app and this flash happens because of that delay. |
but now there will be a flash if those colors differ, correct? |
e.g.
|
Yes, if they get out of sync.
No, i think that makes perfect sense, would be ideal. Will take a look! |
I can take a crack at it if its late and you can review in the morning? |
@aliabid94 Sounds good! Thansk! |
Feel free to merge if you get it working and want to get the release out. The best way to test is just to add some network throttling with the network tab open and there should be no color changes. You'll know where the color flash should come in because you'll see the font change (it is subtle in this branch), it tends to happen around the same time. |
I couldn't figure out how to pass the config values to the CSS, because:
would cause the compiler to fail parsing the CSS. Can't figure out how to embed the tempate tags in CSS since they're not quote enclosed |
@aliabid94 which compiler? The vite build or the templating compiler? |
vite
|
ready for review |
@@ -93,6 +94,30 @@ def repl_func(match): | |||
|
|||
return f"{css_code}\n{dark_css_code}" | |||
|
|||
def _get_computed_value(self, property: str, depth=0) -> str: | |||
MAX_DEPTH = 100 | |||
if depth > MAX_DEPTH: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't want to raise an exception in case there were "broken" themes with circular references before. They didn't error out before and don't want a breaking change.
Tested locally and works great! Thanks everyone ❤️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks (and works) great! Thanks @aileenvl @aliabid94!
@aliabid94 re: the tests, I ran them all locally and they passed, so I'll go ahead and merge this in. cc @gary149 |
Yup seeing it too -- will reopen the issue |
Description
There is no background applied to the body and it defaults to white with a function to detect the users os mode we can change that background before gradio loads. there might be a better way to implement but just a draft idea.
Closes: #5392
🎯 PRs Should Target Issues
Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.
Not adhering to this guideline will result in the PR being closed.
Tests
PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests:
bash scripts/run_all_tests.sh
You may need to run the linters:
bash scripts/format_backend.sh
andbash scripts/format_frontend.sh