Skip to content
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

Dark mode support #1913

Merged
merged 4 commits into from
May 14, 2024
Merged

Dark mode support #1913

merged 4 commits into from
May 14, 2024

Conversation

TheRealVizard
Copy link
Contributor

Description

This PR aims to add native support for dark mode.
It adds a button to switch between themes.
image
image

Checklist:

  • I have added the relevant tests for this change.
  • I have added an item to the Pending section of docs/changes.rst.

Copy link
Member

@matthiask matthiask left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

I think I like it. I wasn't convinced it's worth it at first, but the diff looks really clean and the changes are well localized. Thanks.

debug_toolbar/static/debug_toolbar/js/toolbar.js Outdated Show resolved Hide resolved
debug_toolbar/static/debug_toolbar/css/toolbar.css Outdated Show resolved Hide resolved
docs/changes.rst Outdated Show resolved Hide resolved
TheRealVizard and others added 2 commits May 13, 2024 10:34
Co-authored-by: Matthias Kestenholz <mk@feinheit.ch>
Copy link
Member

@matthiask matthiask left a comment

Choose a reason for hiding this comment

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

Thank you! One more thing. The Django admin panel only uses prefers-color-scheme in the JavaScript code to determine the initial value. This simplifies the CSS insofar as the variables for the dark mode do not have to be repeated. Do you think something like that would be a good idea here as well? See https://github.com/django/django/blob/a09082a9bec18f8e3ee8c10d473013ec67ffe93b/django/contrib/admin/static/admin/js/theme.js#L14

box-shadow:
inset 0 0 5px 2px #aaa,
0 1px 0 0 #eee;
box-shadow: inset 0 0 5px 2px #aaa, 0 1px 0 0 #eee;
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't look as if it has been formatted by prettier v4 (using pre-commit)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

probably was my VS formatter, odd since it's set to use prettier (maybe was not using the same rules)
image
My last commit reverted that change

@TheRealVizard
Copy link
Contributor Author

Thank you! One more thing. The Django admin panel only uses prefers-color-scheme in the JavaScript code to determine the initial value. This simplifies the CSS insofar as the variables for the dark mode do not have to be repeated. Do you think something like that would be a good idea here as well? See

Yes! This can be used to avoid duplication.

They still have it on their CSS, maybe in case JS is disabled by default...
https://github.com/django/django/blob/ceaf1e2848583ba832cc74715da38c802b6b0671/django/contrib/admin/static/admin/css/dark_mode.css#L1C1-L38C26

@matthiask
Copy link
Member

matthiask commented May 13, 2024

Ah yes, you're right. Maybe the difference is that the Django admin mostly works without JS while the debug toolbar is unusable without JS. They cannot fully depend on JS.

I would prefer removing the duplication and depending on the presence of JS some more, but it's not a requirement to merging this, at least not in my view. For me it's good.

@tim-schilling Maybe you have a different opinion?

@TheRealVizard
Copy link
Contributor Author

TheRealVizard commented May 13, 2024

Thank you! One more thing. The Django admin panel only uses prefers-color-scheme in the JavaScript code to determine the initial value. This simplifies the CSS insofar as the variables for the dark mode do not have to be repeated. Do you think something like that would be a good idea here as well? See

Yes! This can be used to avoid duplication.

They still have it on their CSS, maybe in case JS is disabled by default... https://github.com/django/django/blob/ceaf1e2848583ba832cc74715da38c802b6b0671/django/contrib/admin/static/admin/css/dark_mode.css#L1C1-L38C26

Ill push a change to this once i get home if it's needed

@tim-schilling
Copy link
Contributor

I would prefer removing the duplication and depending on the presence of JS some more, but it's not a requirement to merging this, at least not in my view. For me it's good.

@tim-schilling Maybe you have a different opinion?

Nope, I'm indifferent on that.

Copy link
Contributor

@tim-schilling tim-schilling left a comment

Choose a reason for hiding this comment

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

This looks really nice! My only gripe is that we're taking up an entire row of the toolbar for the toggle button. I'm not sure there's a better option though. I'm bringing it up to see if anyone else has an opinion.

@matthiask
Copy link
Member

For the record, I agree with this, but I think that this can be addressed later, in a different pull request. Thanks!

@matthiask matthiask merged commit 7271cac into jazzband:main May 14, 2024
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants