Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions packages/block-library/src/quote/editor.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,47 @@
.wp-block-quote {
margin: 0;
margin: 0 inherit;
Copy link
Member

Choose a reason for hiding this comment

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

This could introduce unanticipated regressions—I'd leave the margins their original settings unless there's a good reason to adjust them.

Copy link
Member Author

Choose a reason for hiding this comment

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

I had to be presumptuous here. I've seen too many inexperienced CSS authors be overly explicit in learning to write CSS with shorthand properties.

Further reading: Harry Roberts "CSS Shorthand Syntax Considered an Anti-Pattern"

The left/right margin seemed overly explicit, unnecessary, and would cause more headaches for theme authors to overwrite with !important further down the line. I agree that there is potential for "unanticipated regressions" now. However, I project that the possibility of these regressions now within the Gutenberg editor vs the outputted styling and front-end experience would outweigh the potential to allow this overly explicit styling to remain.

Copy link
Member Author

Choose a reason for hiding this comment

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

@sarahmonster thanks for the great feedback. I truly appreciate it.

I tried to provide further reasoning behind my decisions. I would hope and encourage that we get another party's insight. I'm still new to the Gutenberg codebase and I don't want to miss anything in the larger scheme of things.

I hope that my reasoning is not perceived as a "no". I'm mostly just curious what more people think as I'm new to the project and tried to apply my most sound reasoning and experience, while also perusing existing Issues, Git Blame, and general history to get a sense of best practices and approaches.

Hopefully, somebody else will drop some feedback and I can get all this updated in another pass, sooner than later. Thanks again!

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 Sarah here that this is a little sensitive to introduce at this point, which is right before the 5.0 release. Which means we have to be extra careful not to cause regressions. In this case it's important to test this both with themes that do support wide alignments, and with themes that do not. There's also mobile, tablet, desktop breakpoints to consider, and even though these are editor styles, the frontend should ideally match.

I understand your arguments and reasons for changing this — and I think this would make a good separate pull request that looks at these editor specific margin rules for all the blocks, together. But changing this for just the quote block in isolation is just going to cause inconsistency, even if this becomes the only block that's "right".

In other words, unless this rule is strictly necessary for the purpose of this PR, I would not bundle it into this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jasmussen @sarahmonster

Thanks for the thorough and insightful review!

One thing still remains unclear. There are several mentions of “causing regressions”. Perhaps I’m missing some oversight on the Gutenberg project’s milestones and project goals. Since it has not been “officially” released yet then why are we concerned with regressions?

Copy link
Contributor

Choose a reason for hiding this comment

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

One thing still remains unclear. There are several mentions of “causing regressions”. Perhaps I’m missing some oversight on the Gutenberg project’s milestones and project goals. Since it has not been “officially” released yet then why are we concerned with regressions?

You mentioned yourself wanting to get these improvements in the 5.0 release. That release is due November 27th, which is two weeks from now. Which means any change we make between now and then has to be solid and stable, and, well, not cause regressions.

A regression could be:

  • A theme that wants to be Gutenberg aware when 5.0 launches, and has perhaps optimized towards the current implementation of the Quote block, such as TwentyNineteen. (Though we'd probably be able to fix up that specific theme beforehand, but the point is still valid for non twenty themes).
  • Regarding the alignments, any existing post authored and saved before this change, when merged, might present an "invalid content" box, or show up as being authored in the Classic block, unless we create a deprecation handler. Creating a deprecation handler is possible, but it's not easy, and it's a relatively big thing to do which means it needs to be thoroughly reviewed and tested, which is hard given there are a lot of other open isssues in the milestones we need to fix for the 5.0 release.
  • If a left/right change is made, it could cause a regression for RTL languages where a different default might be wanted.
  • If a change to margins is made, it could cause display issues on mobile, or in wide/full-wide configurations. For example, if you put a quote inside a full-wide columns block

This is not to say any of those regressions can't be caught and addressed in this PR. It's just that if this PR has a goal of getting merged before the 5.0 release, then it will be held to a higher standard (and should probably be reduced in scope) than if, for example, it goes into the 5.1 release, at which point it's totally fair to expand the scope.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jasmussen thanks for the clarification. Makes absolute sense.


&__citation {
font-size: $default-font-size;
}
}
} // &__citation

&.is-left {
border-left: 4px solid $black;
padding-left: 1em;
} // &.is-left

&.is-right {
border-right: 4px solid $black;
padding-right: 1em;
text-align: right;
} // &.is-right

&.is-center {
Copy link
Member

Choose a reason for hiding this comment

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

For consistency with the other quote styles and for easier overriding in themes, I think it would make sense to simplify the styling of centred quotes. Maybe just a full-width (ie, using a border) top- and bottom- border would work?

Copy link
Member Author

Choose a reason for hiding this comment

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

I disagree. I do not believe there is anything over complicated about the CSS using pseudo-elements. I believe it affords a nicer, elegant out-of-box look for centered quotes, while also allowing a lot of options for theme authors to overrides border-color, border-width, width and more.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have a small preference for Sarahs design, and would generally agree that simpler is almost always better. Additionally, the double borders makes it look more like the Pullquote block:

screenshot 2018-11-13 at 11 37 11

Your argument is not wrong, and there's nothing wrong with what you're doing here. In other words, both your points are valid.

Separate note on this, this is how Twenty Nineteen looks now:

screenshot 2018-11-13 at 11 30 35

screenshot 2018-11-13 at 11 30 41

In that vein it's worth clarifying a thing:

  1. editor.scss is always loaded by the editor
  2. style.scss is always loaded by the editor, and is always loaded by the frontend
  3. theme.scss is only loaded in editor and frontend if the theme opts into Gutenberg "opinionated styles"

TwentyNineteen opts into those opinionated styles. And those opinionated styles exist exactly so we can do things like these. But this also means we need to move all those visual styles into theme.scss so a theme only gets them if opting in. Right now there are a lot of rules in editor.scss that will be present regardless of theme opt-in.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, all these TwentyNineteen issues were noted in the original PR notes above. Thanks for clarifying though.

Copy link
Member

Choose a reason for hiding this comment

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

There isn't anything complicated, per se, about using pseudo-elements in CSS, but it presents a bit of cognitive dissonance when the three alignments are styled using a different approach. So for example, let's say in my theme I just want to change the colour of the border to be pink.. all I should need to do is apply border-color: pink to the .is-large-quote element in my theme, and I'm done.

I'm not opposed to adding extra complexity if it adds value, but from a purely visual perspective, I'm not sure either solution is likely to be better for the majority of users.

margin: 3em inherit;
padding-left: 2em;
padding-right: 2em;
text-align: center;

&::before {
background-color: $black;
content: "";
display: block;
height: 4px;
margin-left: calc(50% - 10%);
margin-bottom: 2em;
width: 20%;
} // &::before
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not do these closing comments. They aren't added anywhere else in Gutenberg.


&::after {
background-color: $black;
content: "";
display: block;
height: 4px;
margin-left: calc(50% - 10%);
margin-top: 2em;
width: 20%;
} // &::after

} // .is-center

} // .wp-block-quote
21 changes: 17 additions & 4 deletions packages/block-library/src/quote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { omit } from 'lodash';
import classnames from 'classnames';

/**
* WordPress dependencies
Expand Down Expand Up @@ -33,6 +34,7 @@ const blockAttributes = {
},
align: {
type: 'string',
default: 'is-left',
Copy link
Member

Choose a reason for hiding this comment

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

An unintended consequence of applying a new class as the default like this is that any quotes created prior to this change wouldn't have the class applied—so if you re-open a previously saved left-aligned quote block, it suddenly loses its styling!

I think it would be best instead to make the left-aligned styling the default for the block, and override it for the right- and centre-aligned options, even though it does involve writing more CSS to reset things.

I'm not sure if we have conventions here either, but I think other blocks tend to follow the "default styling, then overrides" approach. I'd need to do some digging to be sure though!

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, the default: 'is-left' is saying that newly created Quote blocks should automatically have the .is-left class assigned, therefore left-aligned styling applied.

This was the case before, as newly created Quote blocks had style="text-align: left;" automatically applied. So, nothing changes really. Should an editor re-open a previously saved left-aligned quote block it would not suddenly lose its styling. Instead, style="text-align: left;" would be removed and .is-left would get substituted.

With that said, it could potentially have regressions on prior blocks that were saved as style="text-align: right;" or style="text-align: center;", because it would replace those with .is-left automatically.

I could likely work up an instance using the deprecated block API to allow for graceful transition.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a change I'd recommend we do this close to 5.0 release, and it also needs to take RTL languages into account.

Copy link
Contributor

@talldan talldan Dec 4, 2018

Choose a reason for hiding this comment

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

I agree that there should be no class by default. It seems like the css way to do things in terms of the class being a 'modifier', and modifiers only being applied for a variation of a default.

I also think the classes could be more verbose, e.g. 'is-right-aligned', 'is-center-aligned'.

},
};

Expand Down Expand Up @@ -189,17 +191,23 @@ export const settings = {

edit( { attributes, setAttributes, isSelected, mergeBlocks, onReplace, className } ) {
const { align, value, citation } = attributes;

const classes = classnames(
className,
align,
);

return (
<Fragment>
<BlockControls>
<AlignmentToolbar
value={ align }
onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
setAttributes( { align: 'is-' + nextAlign } );
Copy link
Member

Choose a reason for hiding this comment

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

If this class is unique to this block, I'd probably recommend namespacing it. Again, not sure offhand what our conventions are here, but I think we tend to namespace pretty enthusiastically.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I'm not certain what the conventions are here either. I did peruse some other blocks, and based on things like .is-large, .is-style-large in current Quote block: https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/quote/theme.scss

and .is-style-solid-color in current Pullquote block: https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/pullquote/editor.scss#L30

I extrapolated: .is-left, .is-center and .is-right. I think these could potentially be reused (and likely should be) within other blocks as well. In this particular instance I don't get a sense that namespacing is typically used from what I've seen of Gutenberg codebase.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for digging into it and providing additional context!

It looks like we're sometimes using a data-attribute for alignments, unless I'm misunderstanding it:
https://github.com/WordPress/gutenberg/blob/085a6058eb6cb2c09470dfb1b5fab47b826c48b1/packages/block-library/src/table/editor.scss
https://github.com/WordPress/gutenberg/blob/3a210ab5c127c2a9b9791827515cae3a59452a20/packages/block-library/src/pullquote/editor.scss
(lots more too!)

Would it make sense to use that here as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like data-attributes are used when the whole block is aligned (i.e floated and not full-width). I'm not sure if it's something we'd consider for text alignment as well. I couldn't find any prior examples where anything other than inlines styles are used for text alignment (paragraph and verse).

} }
/>
</BlockControls>
<blockquote className={ className } style={ { textAlign: align } }>
<blockquote className={ classes }>
<RichText
multiline
value={ value }
Expand Down Expand Up @@ -240,11 +248,16 @@ export const settings = {
);
},

save( { attributes } ) {
save( { attributes, className } ) {
const { align, value, citation } = attributes;

const classes = classnames(
className,
align,
);

return (
<blockquote style={ { textAlign: align ? align : null } }>
<blockquote className={ classes }>
<RichText.Content multiline value={ value } />
{ ! RichText.isEmpty( citation ) && <RichText.Content tagName="cite" value={ citation } /> }
</blockquote>
Expand Down
18 changes: 9 additions & 9 deletions packages/block-library/src/quote/style.scss
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
.wp-block-quote {

&.is-style-large,
&.is-large {
margin: 0 0 16px;
Copy link
Member

Choose a reason for hiding this comment

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

I'd leave .is-style-large and .is-large alone here, and avoid changing the styling. Otherwise, the two quote styles are too similar.

I'd apply the border only to the default quote style.

Copy link
Member Author

@colorful-tones colorful-tones Nov 12, 2018

Choose a reason for hiding this comment

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

So, this is interesting to me, because currently in Gutenberg Quote block's theme.scss we're assigning a margin-bottom of 20px on the overall .wp-block-quote wrapper (see line #2). However, when the Quote block (again, current Gutenberg treatment) gets assigned as .is-large by the user, than we're decreasing the margin-bottom from 20px to 16px here: https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/quote/style.scss#L2

This screams inconsistency in oversight to me. 😞

Therefore, this is why I went to the extent of trying to update the overall styling of the Quote block component to a little more consistent and scaleable solution. In hopes that it would get merged before Gutenberg launch (WP 5.0).

Also, to clarify I changed px units to em, because using px is making things far too static, and has potential a11y concerns for users on both the back end and the front end.

Copy link
Contributor

Choose a reason for hiding this comment

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

I deeply appreciate your work here, and while you have several valid points, as we barrel towards the November 27th release, it's critical that we focus pull requests only on solving very specific issues, and that we avoid lumping in unrelated changes.

Even though there can be an argument for em changes, it's unrelated to the initial issue, and is only making this review more complex.

So, this is interesting to me, because currently in Gutenberg Quote block's theme.scss we're assigning a margin-bottom of 20px on the overall .wp-block-quote wrapper (see line #2). However, when the Quote block (again, current Gutenberg treatment) gets assigned as .is-large by the user, than we're decreasing the margin-bottom from 20px to 16px here:

Solid observation, worth fixing.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that it'd be good to split this out into a separate PR. It really helps in terms of:
a) helping PRs get shipped faster (smaller changes are easier to review)
b) acting as a form of documentation for a future developer who wants to understand the motivation behind a change.

padding: 0 1em;

p {
font-size: 24px;
font-size: 1.33em;
font-style: italic;
line-height: 1.6;
}
} // p

cite,
footer {
font-size: 18px;
text-align: right;
}
}
}
font-size: 1em;
} // cite, footer

} // &.is-style-large, &.is-large

} // .wp-block-quote
49 changes: 42 additions & 7 deletions packages/block-library/src/quote/theme.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.wp-block-quote {
margin: 20px 0;
margin: 1em inherit;
Copy link
Member

Choose a reason for hiding this comment

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

Same comment re: changing margins as above—could be fragile & result in unexpected changes.

Copy link
Member Author

Choose a reason for hiding this comment

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


cite,
footer,
Expand All @@ -9,10 +9,45 @@
margin-top: 1em;
position: relative;
font-style: normal;
}
}
} // cite, footer, &__citation

.wp-block-quote:not(.is-large):not(.is-style-large) {
Copy link
Member

Choose a reason for hiding this comment

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

Let's only apply the borders to the default quote style.

border-left: 4px solid $black;
padding-left: 1em;
}
&.is-left {
border-left: 4px solid $black;
padding-left: 1em;
} // &.is-left

&.is-right {
border-right: 4px solid $black;
padding-right: 1em;
text-align: right;
} // &.is-right

&.is-center {
margin: 3em inherit;
padding-left: 2em;
padding-right: 2em;
text-align: center;

&::before {
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above re: the centre-aligned quotes!

background-color: $black;
content: "";
display: block;
height: 4px;
margin-left: calc(50% - 10%);
margin-bottom: 2em;
width: 20%;
} // &::before

&::after {
background-color: $black;
content: "";
display: block;
height: 4px;
margin-left: calc(50% - 10%);
margin-top: 2em;
width: 20%;
} // &::after

} // .is-center

} // .wp-block-quote