Build: using a postcss plugin to generate the admin-schemes styles#6739
Build: using a postcss plugin to generate the admin-schemes styles#6739youknowriad merged 11 commits intomasterfrom
Conversation
|
For lighten/darken, you can use https://github.com/postcss/postcss-color-function you can use the CSS colors modules which are still in draft https://drafts.csswg.org/css-color/#modifying-colors |
| }, | ||
| }, | ||
| } ), | ||
| require( 'autoprefixer' ), |
There was a problem hiding this comment.
Should autoprefixer be installed as a dependency for this?
And @wordpress/browserslist-config for the Autoprefixer configuration.
There was a problem hiding this comment.
I don't think autoprefixer should be a dependency, it's a separate postCSS plugin. I'll add the browserlist config.
There was a problem hiding this comment.
Ah, right you are, my bad, this is Gutenberg's webpack.config.js file ;)
| "postcss": "^6.0.16", | ||
| "postcss-value-parser": "^3.3.0" | ||
| } | ||
| } |
There was a problem hiding this comment.
Can this be reformatted to use tabs for indentation please
|
Awesome, I ❤️ PostCSS p.s. http://postcss.parts is a great resource when searching for PostCSS plugins |
|
I love that there's so much hard-coded CSS that's suddenly red in this PR. Nice work. I also like that you were able to port the primary and secondary colors both. I look forward to one day when we can style the whole admin using postCSS like this 🤞 The switch isn't styled, though, and this might be the tricky aspect, that will need a little TLC. As part of #6438, I made it so the switch is never "warning colored". You can see how that's done here: https://github.com/WordPress/gutenberg/blob/master/edit-post/assets/stylesheets/main.scss#L8 In nearly all rules, the switch is the same color as the Publish button. But in Sunrise and Midnight, the switch uses the 2nd spot color, to avoid using warning colors such as red and orange in this case. We need to ensure that's still the case here. |
The good thing about this PR is that it's easy to just introduce a new named color specific to the switch and controls that need to behave similarly to solve this issue. |
c6b496b to
0eccdde
Compare
| "main": "src/index.js", | ||
| "dependencies": { | ||
| "postcss": "^6.0.16" | ||
| } |
There was a problem hiding this comment.
Can you add the Lerna config after this line please:
,
"publishConfig": {
"access": "public"
}|
@jasmussen I updated the PR and tried to fix the colors of the switches. Let me know if it's correct. The reason, they were not being transformed is that they were not using the regular "primary" color in the default theme but a slightly different shade. |
Cool. It's now colored. However it's the wrong color, and this is the problem I was referring to before. Every color scheme but Midnight and Sunrise should use the Midnight and Sunrise should use the Wrong color for Midnight: Right color for Midnight: |
6019023 to
192fd71
Compare
|
@jasmussen I added a "toggle" color to fix this. Let me know what you think? |
|
Nice! I can confirm that all colors look right now on the switch. Well done. |
| @@ -0,0 +1,55 @@ | |||
| const postcss = require( 'postcss' ); | |||
There was a problem hiding this comment.
it doesn't need to be transpiled, should we put in the top folder?
There was a problem hiding this comment.
I personally prefer to be consistent. Maybe we should introduce an exclusion rule in our potential build script instead
There was a problem hiding this comment.
I think we should raise this in the #core-js chat, I'm leaning towards consistency and thinking we should put all @wordpress packages into /src folders.
With more and more packages being released and the increase in contributors looking to grok all of @WordPress' packages, consistency in package layout and formatting I think would help new users and contributors when first exploring all the new shiny things WordPress are putting forward.
''Not a blocker, so can be decided at a later date''
There was a problem hiding this comment.
''Not a blocker, so can be decided at a later date''
Agreed 👍
| @@ -0,0 +1,13 @@ | |||
| # @wordpress/postcss-themes | |||
There was a problem hiding this comment.
For consistency, can we name it postcss-themes-webpack-plugin?
See https://github.com/WordPress/packages/tree/master/packages/custom-templated-path-webpack-plugin.
There was a problem hiding this comment.
Well this is not a webpack plugin, it's a postcss plugin and the name is following the postcss rules.
There was a problem hiding this comment.
Agreed, it is a PostCSS plugin.
I will note that I preemptively went to check on the name at PostCSS.parts
A PostCSS plugin already exists with the name postcss-theme https://github.com/andywer/postcss-theme, this package here in this PR is scoped with @wordpress so our package name would be @wordpress/postcss-theme
I don't see any issues personally with the @wordpress/postcss-theme name but just wanting to make a note of it regardless for if others have any issues with the name.
There was a problem hiding this comment.
Sorry, I didn't quite get it :D
Skip it.
| color: $white !important; | ||
| background-size: 100px 100% !important; | ||
| background-image: linear-gradient( -45deg, $blue-medium-500 28%, $blue-dark-900 28%, $blue-dark-900 72%, $blue-medium-500 72%) !important; | ||
| background-image: linear-gradient( -45deg, theme(primary) 28%, $blue-dark-900 28%, $blue-dark-900 72%, theme(primary) 72%) !important; |
There was a problem hiding this comment.
Don't want to add you too much work in case there is no linter, but noting that we use spacing in scss files around parenthesis. 🤷♂️
There was a problem hiding this comment.
Yes, I'll update but we should definitely add a linter ;)
|
One of the tests fails because of the Otherwise, everything looks great. Thanks for adding tests. They read great and snapshots are very helpful to understand how it is supposed to work. |
|
I just now noticed that Basically I feel like the medium blues should exist as the base, and themes can then add on top of that. In other words, I think we should restore $blue-medium-500 as a distinct variable, even if the theme color simply references it. What do you think? |
|
@jasmussen sounds, like a good idea given it might bring some confusion, unless @youknowriad knows good reasons to avoid it :) |
I think I prefer to remove all the colors instead :). If the colors are available we'll be tempted to use them but this will not translate to other themes while if we remove them we kind of force people to think about theme colors when adding UI. Though, there's probably a middle ground where some colors are shared across all themes (maybe link colors) and in that case, it's fine to keep. |
I agree, long term. But near term, the color schemes are simply not advanced enough that they should dictate how the rest of the UI is designed. For now they are limited to spot colors and secondary colors that override the main theme. It would be nice long term if every theme had a full range of colors. But so long as they are in the override territory, we need to keep the range of blues that are designed for the default theme. |
|
|
||
| // Extending colors to use theme colors | ||
| .react-datepicker__time-container { | ||
| .react-datepicker__time { |


This PR adds a PostCSS plugin to generate the admin-schemes automatically at build-time.
This has some pros over the previous approach.
edit-poststyle. If you load just the components stylesheet, it will come bundled with the admin-schemes styles.Usage:
Instead of using colors directly in our rules, we need to use these helpers:
color: theme(primary)The argument passed to the
themehelper is one of the defined theme colors (primary/secondary/primary-dark15 for now, we can add as much as colors as we want)Some drawbacks:
We can't use
darken/lightenon theme colors, because the Sass loader is run before the post-css transformation, for example I had to define aprimary-dark15theme color to replace the previous call todarken( theme(primary), 15 )The date picker styles were overriden using sass variables and since the date picker styles uses darken/lighten, we can't do this anymore, we'd have to figure out another way to override those.
This PR will help with #6562
Testing instructions