-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Issues/29574 css color variables #29575
Issues/29574 css color variables #29575
Conversation
858fe3c
to
3822161
Compare
I noticed here the styles with comment "// Required for default theme compatibility" in woocommerce.scss remain the original, it would be good to have these variable based too for consistency - I'm wondering whether the styles changed and these should use the variables with the old line remaining above so for compatibility if the browser (IE11 and down) does not support CSS variables those original ones are used as a fallback? |
assets/css/woocommerce.scss
Outdated
text-decoration: none; | ||
|
||
&:hover { | ||
text-decoration: none; | ||
color: lighten($secondarytext, 10%); | ||
color: lighten(var( --wc-secondary )text, 10%); |
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.
Those aren't possible, SCSS needs some value to be able to process using the lighten()
function, so this will cause a compilation error, also there's a syntax error here, since var( --wc-secondary )text
isn't valid.
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.
Those SCSS functions will need to get removed, at least seems like we are using lighten()
and darken()
, I haven't yet checked if anything else needs to be replaced, but this two functions are used in many ways, what makes even harder to try to keep, and feels like will require a small refactoring... At least for what I could remember CSS, feels like that we could use CSS filters to some, but probably will not work when trying to only apply to a border or something like, and feels like that we could introduce some more variables and start to use rgba()
or hsla()
to help defining those other colors.
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.
Thanks for your help.
There's some syntax errors in many files from the templates, some occurrences of var( --wc-highlight )s-color
, also I could find some some SCSS functions that will not work if using CSS variables, I left some thoughts about it in a inline comment.
Anyway, those errors make impossible to compile SCSS, and feels like that it will require a bigger refactoring.
Also seems like there's one extra unrelated change about tax rates in the abstract WC_Order class.
Thanks.
3822161
to
aca7c28
Compare
(cherry picked from commit aca7c28)
aca7c28
to
baac6f0
Compare
@claudiosanches ooof... some copy/paste fails. I've tried to clean up my commit and pull. But you're definitely right... not sure how to handle the I guess you could do something like
but you could collect a lot of variable pretty quickly that way. |
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 could probably apply the same rules of thumb here as for variables generally.
For instance, if we are doing darken($secondary, 10%)
multiple times across the source then it may as well become a variable. A 'one off' on the other hand like darken($secondary, 60%)
that happens in only one location could perhaps just be translated to the CSS equivalent (ie, using the hsl() function) in situ—unless we feel using a variable adds clarity/improved readability.
Please also note there were a few other syntax errors stopping things from compiling successfully (some were flagged in the earlier discussion, and I marked a few more).
Thanks for all the work here so far!
assets/css/twenty-twenty-one.scss
Outdated
$highlights-color: #88a171; | ||
:root { | ||
--wc-highlight: #88a171; | ||
}: |
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.
The trailing colon needs to be removed:
}: | |
} |
assets/css/twenty-nineteen.scss
Outdated
$highlights-color: #0073aa; | ||
:root { | ||
--wc-highlight: #0073aa; | ||
}: |
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.
The trailing colon needs to be removed:
}: | |
} |
assets/css/twenty-twenty.scss
Outdated
$highlights-color: #cd2653; | ||
:root { | ||
--wc-highlight: #cd2653; | ||
}: |
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.
The trailing colon needs to be removed:
}: | |
} |
assets/css/woocommerce.scss
Outdated
background-color: $primary; | ||
color: $primarytext; | ||
background-color: var( --wc-primary ); | ||
color: var( --wc-primary )text; |
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.
I think Claudio already flagged, but we need to clear up instances like this in order for Grunt to compile things successfully:
color: var( --wc-primary )text; | |
color: var( --wc-primary ); |
(If we can successfully compile, it will be easier to evaluate this change 😃 )
@barryhughes quick scan shows there's 3%, 5%, 10%, 15%, 20% and 40% darken calculations on the secondary color. 15% and 40% appear a single time but the others appear more than once.
I'm not particularly familiar with I can fix the rogue |
Do you folks want to have this another look @claudiosanches @barryhughes or do we want to do a bigger refactor? |
Hey @peterfabian — I think solving #29574 would be valuable for themers and this PR is on the right track, but of course still needs work (and input to guide Helga or whomever takes it over). Less sure as to priority. |
I think it's super valuable for plugin devs too! :) |
@peterfabian this PR still needs some work, there's still a invalid value:
Also we probably could consider some refactoring to remove all dependency from SASS. |
Not a super high priority, but since quite a bit of work has been done both by @helgatheviking and us, it might make sense to timebox it to an hour or two to push it forward. What time investment do you folks think this would need? Though, I'm wondering if this work needs an update wrt the changes in WP 5.8 (theme.json) |
Fixed the But that still leaves what to do about the use of Possible options:
I think this might work? but then anyone overriding the root color will always have to use rgb.
|
If I may join the conversation, I also think @helgatheviking PR it's a good idea and it makes sense and to renovate the WooCommerce styles a bit, making them a bit more reusable and manageable. Some week ago I did a PR to change the a font that me me notice that in almost all the custom styles of the templates is used if you need for these things i can help, with scss i'm at home😉! (and not new to this) |
I think we are onboard with the over-arching idea, and see the benefits, but there are also some complexities to figure out (and right now we unfortunately don't have ready-made answers, and are prioritizing other pieces of work). Note a finished thought, but perhaps there is scope to switch to HSL color values as a way to make this easier to manage? However, we would need input from someone with more experience in this area (and, as ever, we'd need to consider backwards compatibility and the relative comfort of third-party developers and customizers): :root {
/* Define the HSL components of our key colors */
--signature-hue: 302;
--signature-saturation: 58.9%;
--signature-lightness: 64.7%;
/* Assemble them into shorthands */
--signature-color: hsl( var(--signature-hue), var(--signature-saturation), var(--signature-lightness) );
--signature-color-dark: hsl( var(--signature-hue), var(--signature-saturation), calc( var(--signature-lightness) * 0.8 ) );
}
/* Using pre-defined shorthands */
#a { background: var(--signature-color); }
#b { background: var(--signature-color-dark); }
/* "One-off" variations */
#c { background: hsl( var(--signature-hue), var(--signature-saturation), calc( var(--signature-lightness) * 1.2 ) ); } ☝🏽 For instance, in the above example, we can imagine Orchid (#DA70D6) having been set as our signature color via the theme customizer. We'd then take care of breaking this down into its consituent HSL values and output them at some appropriate point. From there, we could assemble more convenient composite values (like This might help to cleanly solve some of the issues with the huge number of darkness-based variations. On the other hand, perhaps a design review would reveal that we can easily reduce the range of colors we are using by default. tl;dr—thank you for the work and ideas, and please continue to develop this if you feel so inclined: owing to other pressures, though, we might not be able to give this our full focus until some later point. |
Thanks for following-up 🙃
That is definitely a concern I share (and, personally, I don't find I can easily picture what a color looks like if I am given its HSL value, whereas an RGB or it's hex equivalent are quite easy to transform in my mind...but, perhaps for others the opposite is true).
Also agree in the sense that consistency is important. Given that and my last comment it probably seems odd I suggested an HSL-based solution at all, but the core reason was to solve the technical dilemma whereby:
💯 ... more of this (--wc-highlight) and less of this (--wc-green) makes sense to me.
So does the following sound like an accurate summary of what you are suggesting (or, if I'm misinterpreting, could you post a revised summary)?
|
Yes, everything is correct! i did not mention that the colours could be provided by theme.json but this is a later thing that can be added afterwards. |
So as far as I can understand there are therefore two possible ways:
I prepared a scss function which I think could solve the problem, please have a look at it if it seems acceptable to you as a solution to use scss/hsl I can convert all the styles into short! let me know! Can I tell you the trick of how to visualize hsl colours rapidly? First think that its representation is not a cube like rgb but a cylinder. The first parameter (the radius, so it's a wheel) defines the tone: 0 is red, 120 is green and 240 is blue (around this values, before and after of course). The next two parameters define saturation (from grey to coloured) and brightness (from white to black). It's really handy and when you get the hang of this, and it's much more intuitive than rgb. I know without having to check that hsl(60, X, Y) is yellow because it is between red and green or that hsl(180, 100%, 80%) will be a light blue because it is near the blue value and with an high saturation and lightness. |
Hopefully I've not skipped part of your solution, but I think the core problem here is that SCSS/SASS is an ahead-of-time technology (OK, that may not be strictly true as a hard rule, but that is how it is currently used in this project), and so the result of calls to any SCSS functions is, in effect, going to be a bunch of hardcoded color values. Whereas, at least as I understood it, what @helgatheviking was shooting for (and what I think has a lot of value) is a situation where true CSS variables can be used to define a base palette (which can be dynamically set through interactions with the theme customizer). I realize it's possible to make SASS understand CSS variables, but even then we'd lose the dynamic component of the solution.
That is an awesome explanation, thank you 🙃 |
Sorry but i guess I've not explained the code properly, because what the sass function actually does is create the custom properties with the hsl colours as you showed me, and not use static scss vars as before. And what is generated is completely dynamic and no longer dependent on sass that was used to emulate it's functions but dinamically, give it a try! In order to set the main color and its variations:
note
ps. I may be biased, but I don't think that SCSS/SASS will ever be abandoned: since it is a turing complete language it is definitely something else compared to what css is (or will be). I have always intended scss as a process parallel to css that on a large project allows you to keep everything maintainable and with neat code. |
you can try it here changing the
I don't know if this is a good idea because the customiser will probably be abandoned. Anyway in the past I have done this "error" and it works with custom properties, see here. But ok, it would need a style configuration panel that allows to choose a primary secondary and highlight color (as it is done for WooCommerce mails). Anyway I want to mention this changes allow the possibility to override very easy the whole WooCommerce color palette without anything other. For example I will be able to set the primary colour to red using css only just adding @helgatheviking, what do you think about those changes? |
Sorry @erikyo, I obviously wasn't paying enough attention first time round (the codepen was helpful, though, so thank you). This looks like a nice approach.
Yes, true—not the best example perhaps—but my point was rather about keeping things dynamic such that if the basic palette is changed (by altering one of the core CSS variables), be that through interaction with the theme customizer or something else, everything else should change accordingly without re-compiling the stylesheet (and it looks like your solution solves this very thing).
Agreed: I like this a lot. I'm flagging for discussion just so I can check in with the team and see if anything else is needed here (this should also give an opportunity for others to chime in), but I think we're on to something good here: thanks for all the work and discussion so far—hugely appreciated 👍 |
hi @barryhughes, very happy to hear your feedback so, starting with what was already there took me very little time to update and get the style built! So that the discussion can start with something that works. I also created a branch with the update to dart-sass... now it's the mainstream one and if I wanted to use/include some styles in my own sheet this change would ensure that woo styles are compatible |
I love where this convo is going! It's a bit beyond me now, but yeah purpose-named color variables would be great. where I was getting stuck was on Woo's current use of |
This is the rebased version but I am not able to add it to this pull request 😅 Anyway could be the starting point for an initial testing.
me too! Honestly, I had never thought about using hsl but @barryhughes's suggestion (and necessity) made me try that way. I think it's a good balance until there are relative rgb colours, then "maybe" it will be time to align with WordPress. With this in mind, I changed the base colours and used those of the block-editor (with fallback on the previous statically defined ones). I had commented on an issue on wordpress to make available the --wp--preset--success or --wp--preset--error etc variables but with no luck. |
if i had to guess, we'll need to close this PR and move to yours. |
@helgatheviking could you cherry-pick my changes? |
I tried my best! If that's not good for any reason, I think it may be easier for you to submit a new PR? |
More than perfect! Thanks and sorry for the trouble but at least in this way everything remains in this pull request that you have opened and that deserves to be closed by you! thank you for your efforts! Later the stylesheet can be improved and optimized, these fixes I have done are a fix to build the style but for example all the colors such as black and white still need to be replaced. |
I updated in my branch the scss style to make it compatible with the version used here on WooCommerce repo (sass 1.45.0 which is dart-sass but probably an earlier version than the one I was using). I've changed a little the style so it can be compiled also with node-sass and now it's 100% compatible with both. This change has forced me to introduce two new variables "--wc-luma--secondary-text" and "--wc-luma--secondary" but I think they are very convenient for user styling. I've also updated the WooCommerce style into my blog, you can try to change the variables with devTools, and you'll notice that the colours of the buttons, price, tabs and labels are going to change automatically and live (and it's really cool because I no longer need to overwrite woocommerce.css to colour the shop elements). |
- updated style - adds a rule to cssmin in order to avoid color "minification" - add a new file dedicated to custom properties - enqueue the stylesheet with custom props into header inline style
hi @helgatheviking and @barryhughes just pushed an update that completes the transition to hsl, let me know your thoughts... The only real change I made to the hue of some colors because with rgb keep a constant hue it's very difficult but with hsl not (and that why imho hsl are very handy - see screenshot). all blue colors are linked to the variable with the hue value of blue, red ones with var(-wc--red-hue) etc As the custom prop stylesheet I've added it to the already inlined by woocommerce (using file_get_contents tell me is there are security issues with that), in order inject the css variables in the header. i've added a hook "enqueue_woo_global_styles" (similar to the wordpress one) in order to let the user to modify or return false. last and least, edited the grunt config in order to NOT minify colors. This would not really be necessary but with this hsl approach it becomes a bit out of place to use rgb. I think it's a good starting point to rationalize the style and make it uniform, I've already removed a few errors and I've verified that the painting has not slowed down. Obviously this will make it easier in the future but for the moment it is a mere fantasy since isn't working yet on Canary Chrome. |
@erikyo—would you be happy to create a fresh PR based on your own branch? We can link back to this one for context, and it will make review a little easier. |
Closing in favor of #31902 (thanks for creating that—and apologies for the further delay, there are a few high priority items we're tackling first). |
👌no problem at all! When you are ready I've some changes to the frontend also for the performance concern, please take in charge also this pr, will avoid to use flexslider to generate thumbnail images improving the CLS
|
All Submissions:
Changes proposed in this Pull Request:
Replace SCSS color variables with CSS color variables. This will allow a theme to override the CSS root variable and have that change propagate to all the places where that color variable is used. Currently, overriding the root variable does nothing as the colors are still hard-coded into the CSS when built from the SCSS.
Closes #29574 .
How to test the changes in this Pull Request:
Other information:
Changelog entry