Skip to content

Conversation

spaceninja
Copy link
Member

@spaceninja spaceninja commented Sep 9, 2022

Overview

This PR adds the styles for the new "Outlined" block style we added to the Image block in the WordPress theme. Ideally, we would just add the u-border-small class directly, but WordPress adds the class to the outermost element — in this case, the figure — and we only want the border to apply to the nested img element.

Screenshots

Screen Shot 2022-09-09 at 1 37 35 PM

It's subtle, but there's a 1px border around the image.

Testing

  1. On the preview deploy, go to Vendor > WordPress > Core Blocks > Image.
  2. In the controls for the story, you can set the style to "Outlined" which will match the markup rendered by WordPress.
  3. Verify that an outline is added when you set the Outlined style, and not otherwise.
  4. Test in combination with assorted Alignment options as well — the outline should always be applied to the image directly.

This PR adds the styles for the new "Outlined" block style we added to
the Image block in the WordPress theme. Ideally, we would just add the
`u-border-small` class directly, but WordPress adds the class to the
outermost element — in this case, the `figure` — and we only want the
border to apply to the nested `img` element.

Fixes #862
@spaceninja spaceninja requested a review from a team September 9, 2022 20:39
@changeset-bot
Copy link

changeset-bot bot commented Sep 9, 2022

🦋 Changeset detected

Latest commit: 5980351

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudfour/patterns Minor

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

@netlify
Copy link

netlify bot commented Sep 9, 2022

Deploy Preview for cloudfour-patterns ready!

Name Link
🔨 Latest commit 5980351
🔍 Latest deploy log https://app.netlify.com/sites/cloudfour-patterns/deploys/631ba585716b6d0008ac7c1b
😎 Deploy Preview https://deploy-preview-2039--cloudfour-patterns.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Comment on lines -5 to -12
const alignmentClasses = {
None: '',
Left: 'alignleft',
Center: 'aligncenter',
Right: 'alignright',
Full: 'alignfull',
Wide: 'alignwide',
};
Copy link
Member Author

Choose a reason for hiding this comment

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

These are only used in the Image story, so I moved them below to set directly.

}}
>
{(args) => blockImageDemo({ class: args.alignment })}
{(args) => blockImageDemo({ alignment: args.alignment, style: args.style })}
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 changed class to alignment because we're setting multiple classes now, and it made the logic in the twig file easier to understand.

Comment on lines +6 to +7
{% if alignment in ['alignleft', 'aligncenter', 'alignright'] %}
<div class="wp-block-image {{style}}">
Copy link
Member Author

Choose a reason for hiding this comment

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

This is explained in the CSS, but this awkward thing where we're adding a wrapper element for certain alignments is mirroring the behavior of WordPress. I simplified the if check and added the block style, since it's always set on the element that gets wp-block-image.

Copy link
Member

Choose a reason for hiding this comment

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

Nice! I like the if blah in array pattern. 👍🏽

/// 1. We're using 1px borders here rather than size.$edge-small because it
/// was causing subpixel rendering errors leaving a slight gap between the
/// image and the border.
&.is-style-outlined img {
Copy link
Member

Choose a reason for hiding this comment

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

@spaceninja Can you help me understand why the code uses a "state" is- prefix here? I was expecting a modifier class (e.g., .wp-block-image--outlined).

I might be missing something obvious. I haven't had a chance to create new blocks or CSS for blocks yet. 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep — we don't have control over it. We're using WordPress's native "block styles" which let you name your style (in this case "outlined" and it automatically adds a class, in this case is-style-outlined.

Since we're dealing with extending a built-in block, our options are somewhat limited.

{%
if class == 'alignleft' or class == 'aligncenter' or class == 'alignright'
%}
{% if alignment in ['alignleft', 'aligncenter', 'alignright'] %}
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to DRY the ['alignleft', 'aligncenter', 'alignright'] array?

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 think it's fine — it's also worth remembering that this is just the storybook example, so it's not going to affect the real site if someone edited this and broke it.

Copy link
Member

@gerardo-rodriguez gerardo-rodriguez left a comment

Choose a reason for hiding this comment

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

:shipit:

@spaceninja spaceninja merged commit 59f65eb into main Sep 12, 2022
@spaceninja spaceninja deleted the feature/image-block-outlined branch September 12, 2022 16:45
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