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

Add gradient and color support in Quote #24968

Closed

Conversation

ntsekouras
Copy link
Contributor

@ntsekouras ntsekouras commented Sep 1, 2020

Description

This PR adds gradient, color, line height and font size support in Quote block and is part of #22700.

This PR surfaced a problem with a broken Quote deprecation, that is being removed here.

How has this been tested?

I've tested with the default themes and I could see that many of them override some of these options. For example a theme could override explicitly the color of the Quote and others padding. By looking over other related PRs I observed that this is the case for the other blocks as well, so I believe this is okay as themes should have the last say in some styles.

@ntsekouras ntsekouras added [Block] Quote Affects the Quote Block [Type] Feature New feature to highlight in changelogs. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Sep 1, 2020
@ntsekouras ntsekouras self-assigned this Sep 1, 2020
@github-actions
Copy link

github-actions bot commented Sep 1, 2020

Size Change: +4.92 kB (0%)

Total Size: 1.17 MB

Filename Size Change
build/api-fetch/index.js 3.41 kB -34 B (0%)
build/block-editor/index.js 128 kB +1.83 kB (1%)
build/block-editor/style-rtl.css 11 kB +259 B (2%)
build/block-editor/style.css 11 kB +260 B (2%)
build/block-library/index.js 136 kB +147 B (0%)
build/block-library/theme-rtl.css 756 B +15 B (1%)
build/block-library/theme.css 756 B +14 B (1%)
build/components/index.js 200 kB +69 B (0%)
build/components/style-rtl.css 15.5 kB -34 B (0%)
build/components/style.css 15.5 kB -29 B (0%)
build/edit-navigation/index.js 11.7 kB +13 B (0%)
build/edit-post/index.js 305 kB +608 B (0%)
build/edit-post/style-rtl.css 6.26 kB +646 B (10%) ⚠️
build/edit-post/style.css 6.25 kB +639 B (10%) ⚠️
build/edit-site/index.js 17.1 kB +122 B (0%)
build/edit-widgets/index.js 12 kB +70 B (0%)
build/editor/index.js 45.6 kB +321 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.67 kB 0 B
build/autop/index.js 2.82 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 7.99 kB 0 B
build/block-directory/style-rtl.css 953 B 0 B
build/block-directory/style.css 952 B 0 B
build/block-library/editor-rtl.css 8.55 kB 0 B
build/block-library/editor.css 8.55 kB 0 B
build/block-library/style-rtl.css 7.47 kB 0 B
build/block-library/style.css 7.47 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 47.7 kB 0 B
build/compose/index.js 9.67 kB 0 B
build/core-data/index.js 12.3 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/data/index.js 8.55 kB 0 B
build/date/index.js 5.38 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 4.48 kB 0 B
build/edit-navigation/style-rtl.css 1.16 kB 0 B
build/edit-navigation/style.css 1.16 kB 0 B
build/edit-site/style-rtl.css 3.06 kB 0 B
build/edit-site/style.css 3.06 kB 0 B
build/edit-widgets/style-rtl.css 2.46 kB 0 B
build/edit-widgets/style.css 2.45 kB 0 B
build/editor/editor-styles-rtl.css 492 B 0 B
build/editor/editor-styles.css 493 B 0 B
build/editor/style-rtl.css 3.81 kB 0 B
build/editor/style.css 3.81 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.71 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 621 B 0 B
build/i18n/index.js 3.57 kB 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/keyboard-shortcuts/index.js 2.52 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.12 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.32 kB 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.4 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.41 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 13.9 kB 0 B
build/server-side-render/index.js 2.77 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.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

@oandregal
Copy link
Member

I've taken a look at this and it looks like we need to remove the failing test. The reason it fails is because:

  • At some point, the block had a style attribute (type number) that was deprecated => a test was added to check that this att was no longer serialized after it was deprecated.
  • The block now gains again a style attribute (type object) to store the things we declare for typography and color => the test fails because it's expecting not to have it. But this is a legitimate case, so we need to update the test to account for the new circumstances.

A related question is: is it ok adding an attribute with the same name than a deprecated one? In this case, it's fine:

  • At parsing, the block won't appear as invalid because the new attribute parses the content from the style HTML element, which the old one didn't use (so it shouldn't have any value we don't know how to process).
  • At runtime, it behaves as expected.
  • At serializing, the new attribute will be serialized.

@@ -29,4 +29,8 @@
&.is-large {
border: none;
}

.has-background & {
Copy link
Member

Choose a reason for hiding this comment

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

I saw that we use this padding in other blocks that have background color as well, but we add it in the style.css stylesheet instead of the theme.css. Not sure what's best, perhaps @jasmussen would know?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good question.

Thje theme.scss file requires opt-in, style.scss is "baseline styles". Which other blocks are we using this same padding in?

Generally my instinct would be that this remains a bit of an opinionated style, and that the better place for it is in theme.scss so themes can decide themselves exactly how much padding, if any, they want to add to blocks that have background colors. But I'm not strongly of that opinion.

Is there something else we can do? Can Global Styles absorb some of this "if background then add padding" functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which other blocks are we using this same padding in?

Blocks that use this hook (color). As an example p.has-background and most of them don't have a theme.scss, they have this rule in styles.scss.

Maybe I should add it to styles.scss like the other ones, to be more consistent.

Can Global Styles absorb some of this "if background then add padding" functionality?

@nosolosw @jorgefilipecosta any thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

I searched for $block-bg-padding and/or .has-background and this is what I found:

  • use styles.scss: columns, heading, list, paragraph.
  • use theme.scss: group, separator.

Not sure if there will be more. I don't have a preference and arguments can be made for both options. I trust Joen's instinct, perhaps theme.scss is less disruptive.

Another point for theme.scss is the question about global styles. Riad mentioned that we could look at using support for theme.json to do some other things (like a simpler block markup, cleaning up some styles, etc). I'd leave that out of this PR for now, but just mentioning that's another point for theme.scss (it can be more easily migrated to global styles).

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm personally not sure if the separation between theme.scss and style.scss was ever a successful thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would agree with that, but I do think the goal of the separation was noble, and it would be nice if global styles could help there.

Two examples come to mind, when we started this, the figcaption element was rarely styled and looked out of place with his size and margins, so that was given a size and margin. And the quote had a left border.

For a theme that does style those two things, having to undo or override those styles is annoying. Therefore the separation.

If global styles could provide these came opinionated designs but allow themes to replace them (instead of overriding or unstyling), that could be a better solution.

@jasmussen
Copy link
Contributor

I see this:

quote

That is, cool stuff, this is nice! However, a few things.

The font size doesn't work in my theme because in my editor style, I set the font size of the p tag, and so it doesn't inherit from the blockquote. I wonder if we need CSS like blockquote p { font-size: inherit; } when an explicit font size is set?

What would we do with a group block? Would we ever enable font size controls there? We'd have the same inheritance problem, and we know the quote block will eventually support innerblocks, at which point you can just set the font size on the paragraph block inside. In other words, should we decide on how to handle this before we add font size and line height support?

The gradient is cool. Don't mind the swatches breaking onto a new line, I know why that is and will fix that separately.

@oandregal
Copy link
Member

Nik, this is great work! Technically, this is ready.

A different question that I have is: to what extent we should do this.

To understand this better, I tested this PR with the last 3 default themes: TwentySeventeen, TwentyNineteen, TwentyTwenty. These are the results:

Property TwentySeventeen TwentyNineteen TwentyTwenty
Text Color Doesn't work Doesn't style the cite Doesn't style the cite
Background Color Works fine Works fine Works fine
Font Size Doesn't work Affects the cite but not the paragraph in default style, affects both in the large style. Doesn't work with large style, only affects paragraph in default
Line Height Doesn't opt-in into this Doesn't opt-in into this Doesn't opt-in into this

Not very promising. I think part of the issue is that the block represents two entities (the text + the cite) and our current style system doesn't accommodate this use case very well yet.

🤔 In thinking about how to continue I reckon I don't have a strong answer. Sharing my thoughts in case they're useful:

  • Does it make sense to start by adding only background color (with gradients), and iterate from there based on feedback?
  • It seems to me that we need some design-infused mind to go through the list that we have and help us prioritize/decide which tools make sense in which cases. This is something we've been making block per block, so far.
  • Should we migrate first the blocks that already have support for some of these things but they use a different mechanism? For example, the Pullquote block.

What do you think?

@ntsekouras
Copy link
Contributor Author

Hey @nosolosw ! Your feedback is really helpful!

Does it make sense to start by adding only background color (with gradients), and iterate from there based on feedback?

All your points make sense and I'll change the code to add only the color, but that means both text and background color (I don't think there is an option to add only one..). It was just a small PR to better understand how this works and it totally served its purpose.

Regarding the cite color though, we explicitly style it and it didn't seem a bad idea to me, to differentiate the color there and keep it more subtle. Overall I think you're right about the two entities(text+cite) here and that the direction would be first to change blocks that already have this kind functionality like Pullquote.

About the themes vs styles files, it seemed to me from the feedback that doesn't make much of a difference for now, but it's great that triggered some questions about handling it better in the future in Global styles work. I don't have a strong opinion here and I think it can live in themes for now, no?

@youknowriad
Copy link
Contributor

I think this block was meant to be refactored to use inner blocks at some point, it may solve some of the theme incompatibilities?

@jasmussen
Copy link
Contributor

I think this block was meant to be refactored to use inner blocks at some point, it may solve some of the theme incompatibilities?

That wouldn't solve this problem:

The font size doesn't work in my theme because in my editor style, I set the font size of the p tag, and so it doesn't inherit from the blockquote. I wonder if we need CSS like blockquote p { font-size: inherit; } when an explicit font size is set?

So even if the blockquote has a specificed font size or margin, so long as any blocks inside also have that, it won't affect the children.

@ntsekouras ntsekouras changed the title Add gradient, color, line height and font size support in Quote Add gradient and color support in Quote Sep 3, 2020
@oandregal
Copy link
Member

If the block is refactored to use inner blocks, the inner blocks (paragraph, cite) already have design tools and the value will be attached to them (paragraph has font-size and colors, etc). In this case, we could make it so the wrapper (blockquote) only has attached the properties that are relevant to it (background color) but not the other ones that will conflict (font-size, etc).

How does this look?

@jasmussen
Copy link
Contributor

How does this look?

I may be missing some nuance to your question, but I'm imagining the following blocks:

Paragraph
Quote
	Paragraph
	Image
	Paragraph
Paragraph

☝️ The block list above shows a paragraph, a quote, and a paragraph. The Quote has 3 nested innerblocks, one of which is an image.

Paragraphs can have text colors changed, as they always have been able to.

The Quote block, just like a group block, can change colors that are inherited. But it makes less sense for it to be able to set font size and lineheight, as those are best customized on the Paragraphs themselves.

Does that make sense?

@ntsekouras
Copy link
Contributor Author

If the block is refactored to use inner blocks, the inner blocks (paragraph, cite)

I'm not sure if you're suggesting refactoring Quote to use Innerblocks in this PR.

I am not very familiar with the nuances of global styles so it's not clear to me about what this PR's direction should be with both comments above ( @nosolosw , @jasmussen ).

Would be adding only the color hook for now be an enhancement, or would it cause more problem in the long road since we want to refactor with inner blocks?

@youknowriad
Copy link
Contributor

I'm not sure if you're suggesting refactoring Quote to use Innerblocks in this PR.

Not specifically but if this PR is blocked we can consider trying that on its own separately before moving back to this one.

@oandregal
Copy link
Member

My point was that using inner blocks would fix the issues with themes because the inner blocks already have the design tools, so we don't have to add them to the quote itself (where they don't work well). Note that this is how the style system works, it's not exactly a Global Styles thing.

I guess the next steps for this block could be: 1) converting it to use inner blocks and 2) decide whether adding colors (background/text) to the quote makes sense. I don't have a strong opinion on what should be done first. I perhaps suggest doing the conversion first because the text color doesn't work for cite.

An alternative would be to implement #24927 so we can decide whether a block has text/background color independently and then add only background color for this block.

@jasmussen
Copy link
Contributor

Also worth noting that which ever path forward we choose, it should assume that quote and list get nesting at some point, and not optimize too much for how they work today.

@ntsekouras
Copy link
Contributor Author

Based on all the above comments I think it's better to close this PR and prioritize to refactor Quote block to use inner blocks.

Thank you all for your input and feedback!

@ntsekouras ntsekouras closed this Sep 7, 2020
@oandregal oandregal deleted the add/quote-color-gradient-line-height-font-size branch October 6, 2020 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Quote Affects the Quote Block Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Feature New feature to highlight in changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants