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 paragraph block to use the colors support key #21037

Merged
merged 4 commits into from
Mar 27, 2020

Conversation

youknowriad
Copy link
Contributor

@youknowriad youknowriad commented Mar 20, 2020

Fixes #21163.

Based on #21021 to try test the API on different blocks (paragraph for this PR)

@github-actions
Copy link

github-actions bot commented Mar 20, 2020

Size Change: -3.57 kB (0%)

Total Size: 856 kB

Filename Size Change
build/annotations/index.js 3.44 kB +18 B (0%)
build/block-editor/index.js 101 kB -417 B (0%)
build/block-editor/style-rtl.css 10.9 kB -38 B (0%)
build/block-editor/style.css 10.9 kB -40 B (0%)
build/block-library/editor-rtl.css 7.22 kB -12 B (0%)
build/block-library/editor.css 7.23 kB -12 B (0%)
build/block-library/index.js 110 kB +15 B (0%)
build/block-library/style-rtl.css 7.44 kB +9 B (0%)
build/block-library/style.css 7.45 kB +9 B (0%)
build/components/index.js 190 kB -1 kB (0%)
build/edit-post/index.js 91.2 kB +17 B (0%)
build/edit-post/style-rtl.css 8.43 kB -38 B (0%)
build/edit-post/style.css 8.43 kB -37 B (0%)
build/edit-site/index.js 6.73 kB +15 B (0%)
build/edit-site/style-rtl.css 2.91 kB +27 B (0%)
build/edit-site/style.css 2.9 kB +24 B (0%)
build/edit-widgets/style-rtl.css 2.57 kB -12 B (0%)
build/edit-widgets/style.css 2.57 kB -12 B (0%)
build/editor/editor-styles-rtl.css 428 B +47 B (10%) ⚠️
build/editor/editor-styles.css 431 B +49 B (11%) ⚠️
build/editor/index.js 42.8 kB -1.06 kB (2%)
build/editor/style-rtl.css 3.38 kB -611 B (18%) 👏
build/editor/style.css 3.38 kB -600 B (17%) 👏
build/i18n/index.js 3.49 kB -1 B
build/rich-text/index.js 14.5 kB +87 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 998 B 0 B
build/api-fetch/index.js 3.39 kB 0 B
build/autop/index.js 2.58 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 6.02 kB 0 B
build/block-directory/style-rtl.css 760 B 0 B
build/block-directory/style.css 760 B 0 B
build/block-library/theme-rtl.css 669 B 0 B
build/block-library/theme.css 671 B 0 B
build/block-serialization-default-parser/index.js 1.65 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 57.5 kB 0 B
build/components/style-rtl.css 15.8 kB 0 B
build/components/style.css 15.7 kB 0 B
build/compose/index.js 6.21 kB 0 B
build/core-data/index.js 10.6 kB 0 B
build/data-controls/index.js 1.04 kB 0 B
build/data/index.js 8.25 kB 0 B
build/date/index.js 5.37 kB 0 B
build/deprecated/index.js 771 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.06 kB 0 B
build/edit-widgets/index.js 4.43 kB 0 B
build/element/index.js 4.44 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 6.95 kB 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/hooks/index.js 1.93 kB 0 B
build/html-entities/index.js 622 B 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/keyboard-shortcuts/index.js 2.3 kB 0 B
build/keycodes/index.js 1.69 kB 0 B
build/list-reusable-blocks/index.js 2.99 kB 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/media-utils/index.js 4.84 kB 0 B
build/notices/index.js 1.57 kB 0 B
build/nux/index.js 3.01 kB 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/plugins/index.js 2.54 kB 0 B
build/primitives/index.js 1.5 kB 0 B
build/priority-queue/index.js 781 B 0 B
build/redux-routine/index.js 2.84 kB 0 B
build/server-side-render/index.js 2.55 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4.01 kB 0 B
build/viewport/index.js 1.61 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.18 kB 0 B

compressed-size-action

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

Seeing how all this simplifies block implementation I’m sold on the idea :)

@@ -1,3 +1,8 @@
p {
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure it’s safe to set those values for all paragraphs including front-end as part of the block definition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good question and one we can only address by trying some themes. It does require a devnote but I think it's for the best.

Copy link
Member

Choose a reason for hiding this comment

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

My second thought is that it's probably fine if you consider that with the full site editing, you should create the whole page using only blocks. If someone is using a hardcoded paragraph or heading, it means they might reconsider using nested blocks.

Copy link
Member

Choose a reason for hiding this comment

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

I think applying these styles widely will be a very major change most current themes are not expecting that p elements have color and background property set by default.
When a theme does .content { color: 'red' } probably the expectation was that the color would be applied to paragraphs inside the content and now that will not be the case.
During previous tries with @q and @nosolosw we used wp-gs class to signal a theme support global styles and so it was safe to add these styles. The problem is that here we want the variables set if the theme does not support global styles as they required for things to work, so I'm not sure of the best path.

Copy link
Member

@oandregal oandregal Mar 24, 2020

Choose a reason for hiding this comment

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

😍

I've got #21021 in my review queue, so I'm not fully up to date on how this works. Seeing this is the result, though, I'm pretty excited about it! As to how this could be rolled out, I see 3 approaches. I'll list them from ideal to less ideal:

1. What you're proposing here.

I like this the best. However, it'll require themes to adapt their code. There's no nice fallback mechanism, according to how the cascade works with CSS properties.

Example of how may it work for a property that is inherited (color):

  • the theme sets body, .content { color: black }
  • the paragraph block uses the proposal here and core doesn't enqueue any value for --wp--text-color
  • because the CSS property is invalid and color is an inherited property, its value will be taken from the nearest ancestor

Example of how would it fail for a property that cascades (color):

  • the theme sets p { color: black; }
  • the paragraph block uses the proposal here and core doesn't enqueue any value for --wp--text-color
  • because the CSS property is invalid and color is an inherited property, its value will be taken from the nearest ancestor and the theme rule targeting the p is ignored

Example of how would it fail for a property that doesn't cascade (background-color):

  • the theme sets body, .content { background-color: black }
  • the paragraph block uses the proposal here and core doesn't enqueue any value for --wp--background-color
  • because the CSS property is invalid and background-color is not inherited, its value will be taken from the user agent

2. Only enqueue the styles containing the CSS variables if theme opts-in.

I've proposed this at #20273 and I'd like to go with this, at a minimum, during the exploration phase.

I don't know how it'd work with the changes at #21021, though. I also wanted to note that, although in 20273 I proposed an opt-in mechanism that is specific to "global styles", it doesn't need to be that way. We could use, for example, the existing editor styles --- I haven't dug into this deeper, but wanted to share anyway.

3. Add a class to scope the styles.

This is the last resort for me. It's comfortable for us but it creates a split API for themes: when they want to style a block they'll have to know the block internals and they'll end up with something like:

.wp-block-quote { ... }
.wp-global-styles.wp-block-quote { ... }

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 think core will always include a value for --wp--text-color right? The idea is that we provide defaults for the variables

I'm not sure I agree with this. The paragraph doesn't need a default color to work?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, the paragraph does not need a default color. But I'm generally speaking I think we want to pass the idea block developers can use global styles variables and know they will have sensible defaults, right? The variable --wp--text-color may be used in other places besides a paragraph.

If the variables don't have a default, blocks will need to provide their defaults, and we may have two blocks both using --wp--text-color for something so ideally their text color would be the same but as we don't provide defaults both blocks may use their defaults and have different colors. It seems if we don't provide a set of defaults for all the variables, the experience is going to be inconsistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the idea block developers can use global styles variables and know they will have sensible defaults, right?

I don't think so personally. If a block needs a default for something, it should just provide it as a fallback.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also for most of these variables, the default will be the browser default anyway as the default need to be unopinionated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After some more discussions about this, we're going with the :root p { color: var( --wp--color--text ) to give it more specificity. It is granted that this has the potential to break some theme, themes could fix with several ways including the theme.json config file and it puts us in a better position for FSE and global styles theme compatibility.

We'll have to communicate this on the next plugin release. We'll keep monitoring themes and adapt.

One of the potential solutions we could explore based on that feedback is to apply aa has-styles class whenever a CSS variable is used (color or anything else)

@youknowriad youknowriad self-assigned this Mar 24, 2020
@youknowriad youknowriad added [Block] Paragraph Affects the Paragraph Block [Type] Code Quality Issues or PRs that relate to code quality Needs Dev Note Requires a developer note for a major WordPress release cycle labels Mar 24, 2020
@youknowriad youknowriad changed the base branch from update/group-colors to master March 24, 2020 13:47
@youknowriad youknowriad marked this pull request as ready for review March 24, 2020 13:47
@ellatrix
Copy link
Member

This would fix #21163. What's blocking this?

@youknowriad
Copy link
Contributor Author

We need some testing across themes to check the conflicts with CSS variables.
And I'll add a deprecated version now.

@roo2
Copy link
Contributor

roo2 commented Mar 27, 2020

also fixes #20810

@youknowriad
Copy link
Contributor Author

Anyone to give the ✅here :)

@yansern
Copy link
Contributor

yansern commented Mar 27, 2020

Hold your horses! The Color Settings panel is missing when I tested this PR. Not sure if its just me!

image

@youknowriad
Copy link
Contributor Author

Capture d’écran 2020-03-27 à 10 17 45 AM

I can see them just fine, maybe something in your setup?

@yansern
Copy link
Contributor

yansern commented Mar 27, 2020

Okay, double-checked. The Color Settings panel is missing when I cherry-picked your commits on top of the 7.8.0 tag. The Color Settings is intact when I checked out this PR's branch.

@youknowriad youknowriad merged commit 0aec10d into master Mar 27, 2020
@youknowriad youknowriad deleted the update/paragraph-ccolors branch March 27, 2020 09:31
@github-actions github-actions bot added this to the Gutenberg 7.9 milestone Mar 27, 2020
@ItsJonQ ItsJonQ mentioned this pull request Mar 27, 2020
6 tasks
@jorgefilipecosta
Copy link
Member

Hi @youknowriad,
I am not sure if it is already known but using classes for named colors and variables for custom colors is causing an issue:
In the group block if we select a predefined text color it is not applied to the paragraphs inside it while if we select custom color in the group it applies to nested paragraphs as expected.

@youknowriad
Copy link
Contributor Author

In the group block if we select a predefined text color it is not applied to the paragraphs inside it while if we select custom color in the group it applies to nested paragraphs as expected.

Mmm right! potentially we could set the CSS variable in the classes. I'd love if we could generate these styles to avoid telling block authors to update their CSS

@youknowriad
Copy link
Contributor Author

Alternatively, if you think we should explore switching to CSS variables for the named colors in a PR. That would work too.

@jorgefilipecosta
Copy link
Member

Alternatively, if you think we should explore switching to CSS variables for the named colors in a PR. That would work too.

This solution seems to be more future proof.

},
};

const migrateCustomColors = ( attributes ) => {
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to share this migration function across our blocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I duplicated for now but yes it's always the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Paragraph Affects the Paragraph Block [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom color picker in the paragraph block closing prematurely
7 participants