-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 gallery crop option in Inspector #1545
Conversation
@youknowriad do you have any tips for how I can make the crop enabled by default? I would guess I have to tweak this line: https://github.com/WordPress/gutenberg/pull/1545/files#diff-a7fc58c9ade4d7f0d4de7abd9f6275aaR79 Thanks. |
Lovely. |
@@ -121,16 +124,24 @@ registerBlockType( 'core/gallery', { | |||
controls, | |||
focus && images.length > 1 && ( | |||
<InspectorControls key="inspector"> | |||
<p className="editor-block-inspector__description">Image galleries are a great way to share groups of pictures on your site.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just mind note: we should create a component for this <BlockDescription>
to avoid copying and relying on classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could create a PR for that if nobody is working on it yet. Sounds quite simple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go for it!
@@ -121,16 +124,24 @@ registerBlockType( 'core/gallery', { | |||
controls, | |||
focus && images.length > 1 && ( | |||
<InspectorControls key="inspector"> | |||
<p className="editor-block-inspector__description">Image galleries are a great way to share groups of pictures on your site.</p> | |||
<hr /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something we want after every description? Perhaps we should do it with a CSS border in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
blocks/library/gallery/index.js
Outdated
</InspectorControls> | ||
), | ||
<div key="gallery" className={ `blocks-gallery align${ align } columns-${ columns }` }> | ||
<div key="gallery" className={ `blocks-gallery align${ align } columns-${ columns } crop-${ imageCrop }` }> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's start standardizing on is-cropped
classes, etc.
blocks/library/gallery/style.scss
Outdated
object-fit: cover; | ||
} | ||
|
||
// IE10+ hack |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this apply to IE11 and Edge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to test this in IE11 yet. Couldn't get docker running. Going to try again with a different approach.
But it should apply to 10 and 11. Edge supports object-fit
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't support IE10.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is IE11. Looking again at hacks:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the comment just say IE11+
?
Looks good to me. We'll probably want to use the |
As it turns out, the IE hack needs a little more time in the oven. |
@@ -121,16 +124,24 @@ registerBlockType( 'core/gallery', { | |||
controls, | |||
focus && images.length > 1 && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the description should be shown at all times, not just when there's more than 1 image. Of course, this check makes sense for the controls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if we even need a description for this block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Responded in core slack, I think this is a great place to show contextual help. We want to ensure to have best practices in place that suggest no more than 2 lines, but it feels like it's worth using this spot to show this.
First, the good news. I pushed a fix that makes this work in IE11 and Edge: Then the bad news. Turns out You too, @afercia, if you have time, thank you. Basically what I'm doing is checking whether the image should be cropped, and if cropped, then output the image as a background. By putting the image file itself inside, but with It works perfectly, but it's technically outputting the image twice. I don't know how kosher that is, so please be honest in your code review. The alternative is to not output the image at all, and instead rely on a fixed aspect ratio, like 3:2 or 1:1 for all cropped thumbnails (which is easy) — we can even let you pick the aspect ratio as Matías suggested. But I'm not sure of the sematic implications of outputting background images. So thoughts appreciated. |
The only issue I see with cropping, regardless of how you accomplish it technically, is that not all images have their focal point dead center. This is a broader issue than this ticket, but ideally there would be a way on a per-image basis to specify a focal point or at minimum, where the origin of the image should be anchored. This is more likely a feature that should be provided by the media library and consumed by components like this. |
@jasmussen I think using images as background could have ramifications with plugins filtering the images (things like photon) as well as hi-dpi / mobile tweaks. |
@jasmussen well in the editor now the gallery images are just a series of empty One, very hacky, way to fix this could be (and would need to be tested) giving the figure elements an aria-label but I wouldn't recommend it. The best option is always sticking to the standard semantics and expected behavior, not just for accessibility but also for max interoperability. I wouldn't know how other software or devices would react to empty figure elements. One more concern is about how themes would then implement this in the front-end. Replicating the hack used in the editor would simply make the images not available to all users. I'm not sure if Google crawls elements hidden with What would be needed to implement the same layout with some more standard CSS (e.g. transform or something)? Would knowing in advance if the image is landscape or portrait help? |
I'm going to check up on the hidpi stuff, and also see whether we can do the fallback for IE & Edge only. |
This is a work in progress. Pushing so as to test in IE.
b71d0f2
to
5ebb52f
Compare
I reverted back to the very minimal crop feature using It means crop doesn't work in IE11 or Edge. This fall it will work in Edge (which thankfully auto updates). If we'd like to support IE11, which we probably should at some point, we should explore that in a separate PR. Best option here seems to be exploring utilizing the thumbnails WordPress already provides. |
To put it differently, I think this is ready for final review. |
Fixes #1449.
Screenshot: