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 gallery crop option in Inspector #1545

Merged
merged 7 commits into from
Jun 29, 2017
Merged

Add gallery crop option in Inspector #1545

merged 7 commits into from
Jun 29, 2017

Conversation

jasmussen
Copy link
Contributor

@jasmussen jasmussen commented Jun 28, 2017

Fixes #1449.

Screenshot:

screen shot 2017-06-28 at 12 55 58

@jasmussen jasmussen added the [Status] In Progress Tracking issues with work in progress label Jun 28, 2017
@jasmussen jasmussen self-assigned this Jun 28, 2017
@jasmussen
Copy link
Contributor Author

@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.

@jasmussen jasmussen requested a review from youknowriad June 28, 2017 10:58
@mtias
Copy link
Member

mtias commented Jun 28, 2017

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>
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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 />
Copy link
Member

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.

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 figured we'd keep it manual for now, per the idea that we might have blocks with no inspector options, or even use the description elsewhere.

By the way, I've used this pattern for the design:

screen shot 2017-06-28 at 13 02 11

The italics will come in when the Read More block is merged.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good.

</InspectorControls>
),
<div key="gallery" className={ `blocks-gallery align${ align } columns-${ columns }` }>
<div key="gallery" className={ `blocks-gallery align${ align } columns-${ columns } crop-${ imageCrop }` }>
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 start standardizing on is-cropped classes, etc.

object-fit: cover;
}

// IE10+ hack
Copy link
Member

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?

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 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.

Copy link
Member

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.

Copy link
Contributor Author

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:

https://cloudup.com/chrUteDkrD3

Copy link
Member

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+?

@jasmussen jasmussen removed the [Status] In Progress Tracking issues with work in progress label Jun 28, 2017
@mtias
Copy link
Member

mtias commented Jun 28, 2017

Looks good to me. We'll probably want to use the classnames module to handle all the classes we have now, but we can do that later.

@jasmussen
Copy link
Contributor Author

As it turns out, the IE hack needs a little more time in the oven.

@jasmussen jasmussen added the [Status] In Progress Tracking issues with work in progress label Jun 28, 2017
@@ -121,16 +124,24 @@ registerBlockType( 'core/gallery', {
controls,
focus && images.length > 1 && (
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@jasmussen
Copy link
Contributor Author

First, the good news. I pushed a fix that makes this work in IE11 and Edge:

capture

Then the bad news. Turns out object-fit wasn't in Edge after all. It's in the next edge, which is admittedly due this fall, but still. Also, the fix I pushed might be slightly controversial. Please have a look: 84b6e6f

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 visibility: hidden;, we ensure that the div containing the background image is actually sized appropriately.

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.

@brentjett
Copy link

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.

@mtias
Copy link
Member

mtias commented Jun 28, 2017

@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.

@afercia
Copy link
Contributor

afercia commented Jun 28, 2017

@jasmussen well in the editor now the gallery images are just a series of empty <figure> elements. Empty because the images are hidden with visibility: hidden and thus there's really no content that can be read out.

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 visibility: hidden but I can try to ask to some experts 😏

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?

@jasmussen
Copy link
Contributor Author

I'm going to check up on the hidpi stuff, and also see whether we can do the fallback for IE & Edge only.

@jasmussen
Copy link
Contributor Author

I reverted back to the very minimal crop feature using object-fit. It has the least repercussions for plugins, and has the least complexity.

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.

@jasmussen jasmussen removed the [Status] In Progress Tracking issues with work in progress label Jun 29, 2017
@jasmussen
Copy link
Contributor Author

To put it differently, I think this is ready for final review.

@mtias mtias merged commit f12224f into master Jun 29, 2017
@mtias mtias deleted the add/gallery-crop branch June 29, 2017 13:05
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.

5 participants