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

Update the theme colors to rely on CSS variables #23048

Merged
merged 12 commits into from
Jun 16, 2020

Conversation

youknowriad
Copy link
Contributor

@youknowriad youknowriad commented Jun 10, 2020

An alternative to #20460

This PR updates the theme (admin scheme) colors to use CSS variables. So to achieve high-luminance colors on a specific context, it should be as easy as doing something like

html {
  --wp-admin-theme-color: #3858e9;
  --wp-admin-theme-color-secondary: #1635bb; 
}

Notes

  • This relies on PostcssCustomProperties plugin to provide a fallback for IE11.

@youknowriad youknowriad added General Interface Parts of the UI which don't fall neatly under other labels. Needs Design Feedback Needs general design feedback. [Type] New API New API to be used by plugin developers or package users. CSS Styling Related to editor and front end styles, CSS-specific issues. labels Jun 10, 2020
@youknowriad youknowriad self-assigned this Jun 10, 2020
@jasmussen
Copy link
Contributor

HECK YES. I'm closing mine in favor of this.

With regards to the darker versions — I think we might be able to retire those entirely! The editor only really needs a single spot color, and we don't really need the additional ones in practice. We did for wp-admin due to how the themes were created, but I think one is sufficient. Here's where they're used:

Screenshot 2020-06-10 at 12 42 09

The next one here is lighter, but it doesn't have to be, there's no benefit to that:
Screenshot 2020-06-10 at 12 42 07

This one is also lighter, and doesn't have to be:

Screenshot 2020-06-10 at 12 42 23

Screenshot 2020-06-10 at 12 42 27

All those could use the same blue.

I believe that initially we added at least a secondary color because in some cases like the Midnight theme, the red spot color conflicts with the "is-destructive" red color, so we had an alternate:

Screenshot 2020-06-10 at 12 43 28

But the solution to that one, I think, is to maybe not use the red spot color from Midnight at all. Or if we do it, well, that's on you.

Headings are colored, by the way, they probably shouldn't be:

Screenshot 2020-06-10 at 12 43 09

I'm happy to jump in, maybe tomorrow, and help retire some of these, make sure things look good. But this is really nice work!

@youknowriad
Copy link
Contributor Author

There's a really weird failure when you run npm run build (causing the failures in the tests for this PR).

I tried debugging but I don't understand, when I run webpack directly, I have no errors but when I run the wp-scripts build wrapper wp-scripts build (which does the same thing), i have this weird error

ERROR in Cannot read property 'toLowerCase' of undefined

Any ideas @gziolo @ntwb

@ntwb
Copy link
Member

ntwb commented Jun 12, 2020

Nothing immediately comes to mind, I was going to run the CI and "Debug job", but I don't see this enabled on Travis CI for us, I also cannot find a setting to enable this 🤔

image

@@ -4,7 +4,7 @@
const { adminColorSchemes } = require( '@wordpress/base-styles' );

module.exports = [
require( 'postcss-custom-properties' )(),
require( '@wordpress/postcss-themes' )( adminColorSchemes ),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we switch these two presets priorities, the admin schemes won't work on IE11 (the default one still works) but we'll gain in terms of size of the production CSS build. I think it's fine to do it but I'll bring this to #core-css meetings.

Copy link
Contributor

Choose a reason for hiding this comment

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

The postcss-themes plugin also causes issue with over-specificity of color scheme rules, that's why the inspector panel headings are colored. The generated rule body.admin-color-ectoplasm .components-button[aria-expanded="true"] is overriding the "correct" .components-panel__body-toggle.components-button rule, which is set to plain black, not a color scheme color.

If these are swapped, only the :root is generated for each scheme, which fixes that specificity issue.

IMO it's okay to only have default on IE11, since there are these other drawbacks to keeping support.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the setup, it's way better now. IE11 only shows the default colors.

@github-actions
Copy link

github-actions bot commented Jun 12, 2020

Size Change: -9.37 kB (0%)

Total Size: 1.12 MB

Filename Size Change
build/block-directory/style-rtl.css 955 B +63 B (6%) 🔍
build/block-directory/style.css 955 B +63 B (6%) 🔍
build/block-editor/style-rtl.css 10.7 kB -1.41 kB (13%) 👏
build/block-editor/style.css 10.7 kB -1.42 kB (13%) 👏
build/block-library/editor-rtl.css 7.57 kB -309 B (4%)
build/block-library/editor.css 7.58 kB -308 B (4%)
build/block-library/style-rtl.css 8.02 kB +65 B (0%)
build/block-library/style.css 8.02 kB +64 B (0%)
build/block-library/theme-rtl.css 749 B +65 B (8%) 🔍
build/block-library/theme.css 751 B +65 B (8%) 🔍
build/components/style-rtl.css 15.9 kB -3.6 kB (22%) 🎉
build/components/style.css 15.9 kB -3.63 kB (22%) 🎉
build/edit-navigation/style-rtl.css 1.04 kB +65 B (6%) 🔍
build/edit-navigation/style.css 1.04 kB +66 B (6%) 🔍
build/edit-post/style-rtl.css 5.6 kB +12 B (0%)
build/edit-post/style.css 5.6 kB +14 B (0%)
build/edit-site/style-rtl.css 3.13 kB +183 B (5%) 🔍
build/edit-site/style.css 3.13 kB +182 B (5%) 🔍
build/edit-widgets/style-rtl.css 2.54 kB +146 B (5%) 🔍
build/edit-widgets/style.css 2.54 kB +146 B (5%) 🔍
build/editor/editor-styles-rtl.css 486 B +63 B (12%) ⚠️
build/editor/editor-styles.css 487 B +64 B (13%) ⚠️
build/editor/style-rtl.css 3.82 kB -444 B (11%) 👏
build/editor/style.css 3.82 kB -444 B (11%) 👏
build/format-library/style-rtl.css 561 B +59 B (10%) ⚠️
build/format-library/style.css 562 B +60 B (10%) ⚠️
build/list-reusable-blocks/style-rtl.css 537 B +311 B (57%) 🆘
build/list-reusable-blocks/style.css 537 B +311 B (57%) 🆘
build/nux/style-rtl.css 681 B +65 B (9%) 🔍
build/nux/style.css 676 B +63 B (9%) 🔍
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.62 kB 0 B
build/api-fetch/index.js 3.4 kB 0 B
build/autop/index.js 2.83 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 7.27 kB 0 B
build/block-editor/index.js 106 kB 0 B
build/block-library/index.js 129 kB 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 48.1 kB 0 B
build/components/index.js 195 kB 0 B
build/compose/index.js 9.32 kB 0 B
build/core-data/index.js 11.4 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/data/index.js 8.44 kB 0 B
build/date/index.js 5.47 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.17 kB 0 B
build/edit-navigation/index.js 8.26 kB 0 B
build/edit-post/index.js 302 kB 0 B
build/edit-site/index.js 16.6 kB 0 B
build/edit-widgets/index.js 9.34 kB 0 B
build/editor/index.js 44.8 kB 0 B
build/element/index.js 4.64 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.72 kB 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/keyboard-shortcuts/index.js 2.51 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.13 kB 0 B
build/media-utils/index.js 5.29 kB 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.4 kB 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.5 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 14 kB 0 B
build/server-side-render/index.js 2.68 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.28 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.85 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@youknowriad
Copy link
Contributor Author

As you can see here #23048 (comment) this increases the CSS bundle size because we need fallbacks for the CSS variable usage. That said, if this is acceptable #23048 (comment) we might even gain in CSS size :)

I do think it's fine to move forward either way though.

@youknowriad
Copy link
Contributor Author

I fixed the production build issue btw.

@ryelle ryelle self-requested a review June 12, 2020 14:33
@youknowriad youknowriad force-pushed the update/theme-colors-css-variables branch from 9886e96 to 190b041 Compare June 16, 2020 09:30
@youknowriad youknowriad merged commit 988d3a0 into master Jun 16, 2020
@youknowriad youknowriad deleted the update/theme-colors-css-variables branch June 16, 2020 10:25
@youknowriad
Copy link
Contributor Author

Thanks for your help here @ryelle and @jasmussen I'm really excited to see this land.

@mtias
Copy link
Member

mtias commented Jun 23, 2020

This is great and should help in building a new more vivid color scheme :)

@vg-robin
Copy link

This is all good, but why is converting admin colors to CSS variables a Gutenberg-specific thing?
I've just implemented this in a theme (like this) and with that approach the CSS vars are available to everyone, using Gutenberg or not.
Why not move it to core?

@joyously
Copy link

Why not move it to core?

Gutenberg is in core, but it is something that is developed outside of WP and used by WP. The CSS meetings have been all about the audit of the admin CSS and implementing the admin color schemes with CSS variables, so it is being worked on in core also. Join in at the #core-css channel on Slack.

@vg-robin
Copy link

Sorry, yes, I appreciate that, and sorry if I'm being dim.
Doesn't my point still stand though? Isn't the proposal about adding this to the Gutenberg-specific stylesheets? Since many sites and themes disable Gutenberg (by whatever means, and for whatever reason) this new functionality can't be relied upon by plug-in developers or used for admin interface elements on non-Gutenberg sites.
I'm just saying it would be really useful if it could encompass those scenarios too. (I've been developing in three such scenarios just this month.)
And if it is coming to non-Gutenberg admin CSS, why then add it to Gutenberg? Doesn't that create duplication, with potential conflicts?

"Render unto Gutenberg the things that are Gutenberg's...." :)

@joyously
Copy link

Don't put "Gutenberg the editor" in the same box as "Gutenberg the plugin that is for more parts of the admin than just the editor". Right now, users can disable the block editor. That won't apply to the parts of Gutenberg that become the WP admin.
And you can still use the Gutenberg editor on projects external to WP, so it has to be able to control its editor page independently.

@vg-robin
Copy link

However much the definition of the term "Gutenberg" expands - it could become the new OS for the ISS - my point still stands.
I'm not remotely arguing against Gutenberg, but you're talking about the future and my comment addresses current (and past) installations.
As a minimum, all this would take is a formal announcement of the official CSS variable names, and some mechanism, like a named action, or a reserved stylesheet handle, that outputs a style sheet that declares them.
Then a plugin author could check if WP is outputting them, and, if not, implement the output itself - a standardised polyfill.
And that would be pretty easy, surely? This seems like low-hanging fruit.
I don't particularly care if that output is done by "Gutenberg" (however defined) or not. Obviously the block editor will be improved by consuming the CSS variables, but so will lots of other things, is all I'm saying.

@joyously
Copy link

I'm not sure why you are arguing on this issue. Please reference the issues at Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json
You are taking one isolated PR out of context. As I said, it is being worked on.

@ellatrix ellatrix mentioned this pull request Jul 3, 2020
12 tasks
@youknowriad youknowriad removed the Needs Dev Note Requires a developer note for a major WordPress release cycle label Jul 16, 2020
jeherve added a commit to Automattic/jetpack that referenced this pull request Aug 3, 2020
jeherve added a commit to Automattic/jetpack that referenced this pull request Aug 4, 2020
jeherve added a commit to Automattic/jetpack that referenced this pull request Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS Styling Related to editor and front end styles, CSS-specific issues. General Interface Parts of the UI which don't fall neatly under other labels. Needs Design Feedback Needs general design feedback. [Type] New API New API to be used by plugin developers or package users.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants