Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Fixed #32018 -- Extracted admin colors into CSS variables. #13435
Conversation
I purpose we first define variables for colors, the same way that bootstrap does, so we could end up with something like:
Then we use this colors to construct the variables for the other elements: --body-bg: var(--white)
--link-color: var(--blue-200)
--form-bg: var(--gray-100) Also, I used css-color-extractor on all admin CSS files, and this is the list of every color used, we can group the variables based on this: Some of them look really close to each other (like |
Thanks! Re. defining colors first. There's a different accepted issue for adding a dark mode here https://code.djangoproject.com/ticket/31259 – I think defining colors first isn't a big help in this case, except if we started to calculate colors from other colors. I have been experimenting a bit with this approach (see the base.html file) but this may be too much for a single pull request. Maybe colors should be redefined in 3rd party projects anyway, which should be much easier once we get good names down... ... which brings me to the second point: Naming is very hard. And it gets harder the more names we have to define. I experimented with using the same color for borders everywhere but that does not look right on different backgrounds. Other colors can be merged easily and I'd certainly propose we should try to merge those. Otherwise this PR wouldn't help at all with addressing the accessibility issues and with theming. Fresh eyes on the code are always helpful, thanks again for your inputs! |
cd4dbc4
to
3dabde2
Btw, I scrolled through the list of pull requests and found #13409 – merging was straightforward without many conflicts. A merge of the current branch tips is here https://github.com/matthiask/django/tree/mk/admin-css-31986-merge |
I really like this PR, I was going to work on this myself at some point This may or may not be a good idea, I'm just wondering if you've thought about it: Have you considered putting the variables definitions in a new file ( I'd also be in favour of moving some of the more similar colours together to improve consistency and maintainability - I think it should be in another ticket / PR though. |
@knyghty Thanks! Yes, I've thought about that. However, I don't think it's necessary since overriding those values also works when it happens when loading the theme CSS last since CSS works that way. Or even like this, with a project-specific {% extends 'admin/base.html' %}
{% block extrahead %}{{ block.super }}
<style>
/* Purple, just as an experiment to see what's missing */
:root {
--primary: #9774d5;
--secondary: #785cab;
--link-fg: #7c449b;
--link-selected-fg: #8f5bb2;
}
</style>
{% endblock %}
``` |
Oh, you mean you can override the CSS variables after they are set? That's very good to know, I had no idea, thanks. So then a dark or other alternate theme could just implement the same vars in a new file that's loaded whenever? If that's the case, it sounds good. It might be nice to just have the colours in one place so you know what you can override, but I think having them all together in base CSS file is good enough |
Regarding:
Doing this in a different ticket may be fine but either we first convert everything to use CSS variables (meaning we have to find names for all those colors which we'll drop again anyway) or we standardize colors first. Both sound like good approaches but since contributor and reviewer time isn't an endless resource I'd strongly prefer moving forward with the approach outlined here. Killing two birds with one stone and all that.
Yes, exactly. |
I've imported https://github.com/matthiask/django/tree/mk/admin-css-31986-merge into https://github.com/matthiask/django-variable-admin and published this to https://pypi.org/project/django-variable-admin/ so that I can use this in projects and find any remaining problems with the pull request. |
70968f2
to
f85a5c5
f85a5c5
to
1b11602
1b11602
to
59770ac
Hello, I think that using variables makes it much easier to make theme changes in Django and add other themes like the dark theme. I hope that this PR will be merged soon and I will rebase #12444 on it. Also, I think that dedicated and designed dark themes are nicer than calculated dark themes from light ones. |
Hi @matthiask. Thanks for this. Really good.
I think we should take this. Nice addition, and should allow @mimi89999 to implement a dark mode (which folks seem to like |
https://code.djangoproject.com/ticket/32018#ticket
Note! This pull request contains the following changes which could be seen as not being strictly related to the title of the pull request:
.object-tools
' hover state is not using the primary color anymore. Most hover states use a simple desaturation/darkness effect.:last-child
selector should have hidden the bottom border but it didn't, because it targets the last child (as it should) and not the last visible child which would be useful but CSS does not support this)Separating those changes from the current pull request would be possible. It would be much more work preparing the pull request however, and I'd also argue that reviewing wouldn't be less work because I, as a reviewer, would want to check out the changes locally anyway, especially since Django does not have (and should not have IMHO) automated tests for the admin CSS.
I added a few inline comments to CSS rules which are probably unused. I didn't add comments to rules which are only used in the admindocs application; those could be separated out as well, but maybe someone is relying on their presence. A case of practicality over purity in my book.
I didn't touch the vendorized select2 code, but tested with a dark interface for fun. Some code to test a different color scheme or even a dark mode scheme is here: 95b489f