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

Chore: Styles Gutenberg core image block #802

Merged
merged 36 commits into from
Aug 17, 2020

Conversation

derekshirk
Copy link
Contributor

@derekshirk derekshirk commented Jun 18, 2020

Overview

This pull request adds a few small style adjustments to Gutenberg image blocks to improve layout and alignment for WP image blocks.

  • Removes margin-bottom from image blocks
  • Fixes issue with smaller/resized images with center alignment

Additionally, This PR now adds CSS support for Gutenberg wide and full images.

Screenshots

Screen Shot 2020-08-10 at 1 33 53 PM

Screen Shot 2020-08-10 at 11 24 58 AM

Before alignment fix

Screen Shot 2020-06-22 at 11 38 40 AM

After alignment fix

Screen Shot 2020-06-22 at 11 39 33 AM

Testing

  1. Review changes
  2. Check code comments, make sure they are clear, concise, explain the "why" of what they are annotating and above all that the changes they are introducing are sensible.

See #710

@changeset-bot
Copy link

changeset-bot bot commented Jun 18, 2020

🦋 Changeset is good to go

Latest commit: 361cae5

We got this.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@derekshirk derekshirk self-assigned this Jun 18, 2020
@derekshirk derekshirk marked this pull request as ready for review June 22, 2020 23:22
@derekshirk derekshirk requested review from tylersticka and removed request for tylersticka June 22, 2020 23:22
@derekshirk derekshirk changed the title Chore: Styles Gutenberg core image block [DRAFT] Chore: Styles Gutenberg core image block Jun 22, 2020
tylersticka
tylersticka previously approved these changes Jun 22, 2020
@derekshirk derekshirk changed the title [DRAFT] Chore: Styles Gutenberg core image block Chore: Styles Gutenberg core image block Jun 22, 2020
@derekshirk
Copy link
Contributor Author

After I opened this PR up for review, I realized that this PR did not include the changes I intended to add to the core/image documentation about how u-pull-inline utility classes can be used to extend the left and right edges of an image outside of the parent prose container.

I plan to update that before merging.

Comment on lines 377 to 380
`u-pull-inline-{amount}` class names from our [negative
margin](/?path=/docs/utilities-spacing--negative-margin) utility classes can
be added to the additional css section of the image block to extend the left and
right edges of images beyond their parent prose container.
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've updated this section of documentation and re-requesting review.

Copy link
Member

Choose a reason for hiding this comment

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

I'm surprised to see the direction to use utility classes. Is it possible for us to add opinionated defaults for the breakout alignment options I see in the Gutenberg demo ("wide width," "full width")? I'd love to get these common things out of our post drafts and into our code.

Screen Shot 2020-06-23 at 10 24 51 AM

Copy link
Contributor Author

@derekshirk derekshirk Jun 23, 2020

Choose a reason for hiding this comment

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

Is it possible for us to add opinionated defaults for the breakout alignment options I see in the Gutenberg demo

I will update this PR to account for the "wide width" and "full width" settings.

Copy link
Contributor Author

@derekshirk derekshirk Aug 6, 2020

Choose a reason for hiding this comment

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

@tylersticka I know you had a busy day, so no need to respond to this right away.

Part of my confusion was that my image block editor options looked different than your screenshot above from your Gutenberg demo. In my local development environment, I'm using the version of Gutenberg that ships with WordPress and my 'alignment' options only included: left, center and right options.

Screen Shot 2020-08-06 at 3 36 40 PM

As far as I can tell, this option needs to be enabled via add_theme_support
https://gogutenberg.com/blocks/image/

Which appears to work...

Screen Shot 2020-08-06 at 4 24 46 PM

Unless I'm missing something, my plan is to submit a PR to the WP repo to allow for these "advanced alignment" options as well.

@tylersticka tylersticka removed their request for review June 24, 2020 16:30
@derekshirk
Copy link
Contributor Author

derekshirk commented Aug 12, 2020

@tylersticka

You might consider adding knobs for this to toggle the various classes, which might make testing easier?

Excellent idea!

A few notes:

  1. I'm still a little "green" when it comes to setting up knobs in Storybook, so I imagine my changes will elicit some additional feedback.

The way the story was configured prior looked like this:

<Preview>
  <Story name="core/image">
    {`<figure class="wp-block-image size-large is-style-default">
        <img
          src="/media/MtBlanc1.jpg"
          alt="Mont Blanc"
          class="wp-image-130"
          srcset="
            /media/MtBlanc1.jpg         500w,
            /media/MtBlanc1-300x225.jpg 300w
          "
          sizes="(max-width: 500px) 100vw, 500px"
        />
        <figcaption>Mont Blanc appears—still, snowy, and serene.</figcaption>
      </figure>`}
  </Story>
</Preview>

I wasn't sure how to add knobs to this format, so I followed some examples I observed elsewhere and reformatted the story like this:

<Preview>
  <Story name="core/image">
    {blockImageDemo({
      class: select('alignment class', alignmentClasses, null),
    })}
  </Story>
</Preview>

I am curious about the legitimacy of this approach and possibly learning better/alternate ways to configure this.

  1. Regarding the select knob...I ended up adding the options like this:
const alignmentClasses = {
  None: null,
  Left: 'alignleft',
  Center: 'aligncenter',
  Right: 'alignright',
  Full: 'alignfull',
  Wide: 'alignwide',
};

I wonder if their is a more efficient way to accomplish this.

  1. I assumed it would help demonstrate the effects of alignment classes, if I added surrounding placeholder text to the block/image story but wanted to confirm if this was desirable or not.

  2. I added some conditional logic to src/vendor/wordpress/demo/image.twig that might seem strange (6200fed). I did this because WP actually modifies the markup of the image block it outputs depending the selected alignment classes. Feedback welcome!

@derekshirk derekshirk requested a review from tylersticka August 12, 2020 20:58
Copy link
Member

@tylersticka tylersticka left a comment

Choose a reason for hiding this comment

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

Works well, some comments inline

position: relative;

/**
* 1. Setting a width of `100%` prevents resized and centered images from
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Comment numbering isn't necessary when there is only one line in the block.

src/vendor/wordpress/_wordpress.scss Show resolved Hide resolved
Comment on lines 142 to 145
left: calc(12vw / -2); /* 1 */
margin-left: auto;
margin-right: auto;
width: calc(100% + 12vw); /* 1 */
Copy link
Member

Choose a reason for hiding this comment

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

Would this accomplish the same thing?

Suggested change
left: calc(12vw / -2); /* 1 */
margin-left: auto;
margin-right: auto;
width: calc(100% + 12vw); /* 1 */
margin-left: -6vw; /* 1 */
margin-right: -6vw; /* 1 */

Copy link
Contributor Author

@derekshirk derekshirk Aug 12, 2020

Choose a reason for hiding this comment

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

It does! I like it, much simpler. I am introducing these changes manually.

<Meta title="Vendor/WordPress/Gutenberg" />
import blockImageDemo from './demo/image.twig';
const alignmentClasses = {
None: null,
Copy link
Member

Choose a reason for hiding this comment

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

Storybook select values are converted to strings no matter what they are, so (annoyingly) null is the same as passing in a string called 'null'. You can pass in an empty string, though, (''), which should have the desired effect.

(It's times like these I wish knobs were better documented... but they've been replaced by a more elegant solution in the latest Storybook release, so that's nice!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, that was extremely helpful. I had originally started with an empty string, but ended up mimicking what I saw in the documentation I was reading, which used null. 🙃

<figcaption>Mont Blanc appears—still, snowy, and serene.</figcaption>
</figure>`}
{blockImageDemo({
class: select('alignment class', alignmentClasses, null),
Copy link
Member

Choose a reason for hiding this comment

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

I would either shorten this to "alignment," or show the full class names (alignright instead of Right). As is, it says "alignment class" but it's not actually showing the class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! Excellent feedback.

@@ -0,0 +1,30 @@
<div
class="demo-container"
Copy link
Member

Choose a reason for hiding this comment

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

Consider using the Rhythm object pattern for this, especially since your styles account for it.

@derekshirk derekshirk requested a review from tylersticka August 12, 2020 23:17
Copy link
Member

@tylersticka tylersticka left a comment

Choose a reason for hiding this comment

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

Working well, but two issues still to resolve:

  1. I notice if I change from the "None" alignment option to "Center," the amount of whitespace below the example increases but nothing else does.
  2. Because this PR adds a feature, you need to make sure the addition is part of our changelog. Instructions are in the contribution guide: https://github.com/cloudfour/cloudfour.com-patterns/blob/v-next/CONTRIBUTING.md#changelog-entries

@derekshirk
Copy link
Contributor Author

Hi @tylersticka,

I notice if I change from the "None" alignment option to "Center," the amount of whitespace below the example increases but nothing else does.

I want to make sure I understand expectations here correctly.

1. Whitespace question

I can't determine if you are suggesting that the amount of whitespace should change or not. I had originally assumed you were suggesting that it should not, so I pushed one possible "solution" (3ed4aae) to "remedy" that. However, now I'm not so sure!

Example of update introducing no change in whitespace

knobs-alignment-update

If I compare behavior of c4staging.wpengine.com/ master branch I notice the white space does change when switching between these two alignment options:

knobs-alignment-comparison

Note the classic editor will apply a class of alignnone while the block editor does not. alignnone does not appear to have any styles associated with it.

2. Alignment question

I also want to make sure I understand the second part of your comment:

but nothing else does.

I interpret this as, "when 'None' is selected and the image size is reduced it should not maintain centered alignment". It appears that "None" and "Center" currently behave similarly when reducing the image size due to some styles defined in our base CSS.

/src/base/_defaults.scss

/*
 * ...
 * 2. Center content
 * ...
 */

figure {
  ...

  & > * {
    margin-left: auto; /* 2 */
    margin-right: auto; /* 2 */
  }

  ...

If my interpretation is correct, is it more desirable to override the existing <figure> styles defined in _defaults.scss within our vendor _wordpress.scss (only for .wp-block-image elements), so that when no alignment class is selected the resulting behavior is like this:

knobs-alignment-no-styles

An alternate approach might require rethinking how the base <figure> styles are written but centering <figure> contents by default seemed smart to me.

Thanks!

@tylersticka
Copy link
Member

I can't determine if you are suggesting that the amount of whitespace should change or not. I had originally assumed you were suggesting that it should not, so I pushed one possible "solution" (3ed4aae) to "remedy" that. However, now I'm not so sure!

I couldn't see a reason why one would have whitespace and the other would not. The issue is the (seemingly unintentional) inconsistency, not the presence of or lack of whitespace.

Was the whitespace intentional, or an oversight? If it was not intentional, and there isn't a design justification for it, then we should remove it. If it was intentional but was omitted from the default, then we should add it.

Does that make sense?

I also want to make sure I understand the second part of your comment:

but nothing else does.

This isn't a second part, I just meant that only aligncenter adds whitespace. It's just the inconsistency.

If you intended for aligncenter to have more whitespace below it, then we should have added whitespace consistency. If you did not intend for aligncenter to have more whitespace below it, then you were correct in removing it.

@tylersticka
Copy link
Member

tylersticka commented Aug 14, 2020

To summarize:

  • Did you intend for aligncenter to have more whitespace below it?
    • Yes: I'd like to know why. We can't just have inconsistency without a justification.
    • No: Okay, is it an improvement (or "happy accident")?
      • Yes: Then we should add it to the other options as well.
      • No: Then it was a good idea to remove it.

@derekshirk
Copy link
Contributor Author

Did you intend for aligncenter to have more whitespace below it?

Based on my observations on cloudfour.com I had thought the additional whitespace was intentional. So my only "intent" at the time was to mimic what I thought was expected, due to the display: block; property included with WordPress's aligncenter class. This is by no means a justification.

cloudfour-dot-com-aligncenter-whitespace

No: Okay, is it an improvement (or "happy accident")?
→ Yes: Then we should add it to the other options as well.
→ No: Then it was a good idea to remove it.

No, I don't think so. I think the additional whitespace throws off the vertical rhythm applied by our Rhythm object pattern.

Happy to discuss further.

tylersticka
tylersticka previously approved these changes Aug 17, 2020
@derekshirk derekshirk requested a review from tylersticka August 17, 2020 17:03
@derekshirk
Copy link
Contributor Author

Hi @tylersticka,

I added a changeset (69c1af7) and it dismissed your approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants