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 theme #1177
Dark theme #1177
Conversation
b6ec129
to
31be58e
Compare
This is so so so great and very well documented! I need to dig deeper on it and check it out locally properly but it looks very good. It's going to be also very helpful for the migration we are planning where theming variables should be very well defined and documented. I'm keeping open meanwhile I can check it out but it's a great work, thank you! |
Also sorry, I've introduced some conflicts with some codestyle changes pushed recently, may you solve them? |
The organisation of the css variables as been reviewed to accomodate a dark theme.
Thank you for your appreciation. |
Hi!
|
Nice catch! I'll fix this.
It's because I kept the primary color untouched. If a user wants to use the dark theme, a primary color matching it well is to be picked. Here the blue is indeed too dark. I don't know if the green chosen in the material guidelines is a recommended color or if it happens to be the primary (or accent) color in the example. As this is left to interpretation, I can do whichever you choose.
Same as above. I'm really curious how prevalent are the flat colored buttons on Android though. AFAIK in most cases it's either flat and neutral or raised and colored. |
I've worked on it a bit and it turns out that this is actually very tricky.
I'm kinda stuck on this problem as none of the outcomes seem to be both possible (AFAIK) and desirable. |
It's been a while and I did not come back to this. Sorry 🙏 |
This commit makes changing to a dark theme much easier.
It introduces a lot of changes to the overall organisation of the css variables and how they are used in the various
theme.css
files. I've done my best to make the visual changes to the default theme as minimal as possible, but I prioritized consistency nonetheless. More on this below.How-to switch to the dark theme
User
Configure Postcss so it uses the following variables:
Developer
Go into
./components/variables.css
and change every instance oftheme-light
totheme-dark
Rationale
The original goal was simply to use a dark theme in my project. However, it required to dig into the material design guidelines and change many css variables accordingly. Even then, some colors are hardcoded into the
theme.css
files, so you need to revert to inline styles or custom theming.Given that the specs themselves mention the dark theme, I thought appropriate to make the changes here.
Process
The process has been the following:
used in
./components/colors.css
; these are prefixed bytheme-light
or
theme-dark
./components/variables.css
to add a level of indirectiontheme.css
file by a new or existingcolor in the appropriate
config.css
fileconfig.css
file by a color from./components/variable.css
(or a function of such a color)Along the way I tried to fix anything that didn't fit the material design specs.
I also tried to introduce the minimum amount of variables in
./components/variable.css
by reusing them or computing a new color based on those.Benefits
No hard-coded colors
Except in special circumstances, the properties in the
theme.css
files don't use hard-coded colors. It makes the colors fully configurable from css variables.Two dependent layers
We have two layer of style configuration through css variables: the global layer (through
components/variable.css
) and the component layer (theconfig.css
files). Because the component layer entirely depends on the global layer, you can make very impactful color changes with very few definitions.The same relationship holds between
components/colors.css
andcomponents/variables.css
, where the former defines variables according to the spec and the latter makes use of those.Dark theme
Because the colors of each theme are in
./components/colors.css
alongside the palette, users don't have to refer to the spec in order to use the dark theme.Pitfalls
Too many global variables
The specs didn't make reusing colors easy.
The statusbar, snackbar and switch button have arbitrary colors that need their own theme-dependent variables, even though their scope is limited. I leaned toward consistency and defined those variables in
./components/colors.css
. I can move those to theconfig.css
file of the appropriate component upon request.Wild guesses
The specs are incomplete so I had to make some colors up.
For the light theme I've been mostly annoyed by the absence of the Chip colors.
For the dark theme, many colors are missing. It impacts the components Table, Chip, Snackbar and others.
Only static
You can only switch to the dark theme statically.
With how things are laid out, I don't think that we can currently reproduce the on-the-fly theme change feature of Material-UI.
Inverted components become problematic
Inverted components are easy to deal with when you assume a light theme.
However, when the theme can be arbitrary, it's hard to come up with a decent result.
Possible solutions were:
override the variables
I favored 2. The problem is that inverted buttons for the dark theme are not conformant to spec.
The third solution is tempting but it would make the already crowded list of global variables even bigger.
I really think we should reevaluate this feature, as I don't really understand its usefulness.
Detailed changes
Code
config.css
, for consistency.config.css
forconsistency
config.css
so the colorsalways come first (that was for convenience)
theme.css
by a variable fromthe corresponding
config.css
spec
page so it staysbeautiful under the dark theme
Aesthetic
I don't see the difference
All these visual changes can be reverted back upon request
Compare in the browser
You can see the result directly following those links:
spec
page before the changesspec
page after the changesspec
page after the changes with a dark theme