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 site logo crop #31607

Merged
merged 15 commits into from Sep 20, 2021
Merged

Add site logo crop #31607

merged 15 commits into from Sep 20, 2021

Conversation

@ajlende
Copy link
Contributor

@ajlende ajlende commented May 7, 2021

Description

Part of #30406.

Also fixes #29217 in 93dc967. This can be moved to another PR if people would prefer to keep the fix separate.

Adds cropping to the site logo by:

  1. Moving the cropping component to the @wordpress/block-editor package and exporting it as an __experimental component
  2. Using the exported cropper in the SiteLogo block

How has this been tested?

  1. Add SiteLogo block.
  2. See that toolbar doesn't appear when the logo is empty.
  3. Apply a crop when a logo is present.
  4. See that the site logo is updated when the crop is applied.

Screenshots

image

image

crop-logo

Types of changes

New feature

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).
@ajlende ajlende requested review from jasmussen and ellatrix May 7, 2021
@ajlende ajlende self-assigned this May 7, 2021
@ajlende ajlende requested a review from ajitbohra as a code owner May 7, 2021
@ajlende ajlende mentioned this pull request May 7, 2021
12 tasks
@jasmussen
Copy link
Contributor

@jasmussen jasmussen commented May 10, 2021

This is going to be so extremely useful for the site logo block, thanks for working on it! (Oh and by the way, I feel like at this point you've deserved to be admitted as a contributor, if you'd like to work on the main branch rather than your fork 😉). This is what I see:

site logo crop

In general this seems to be working well. There are some flow aspects to the cropping system that could be refined to benefit both this and the Image block, but we can look at that separately.

As shown at the end of the GIF, if I change the aspect ratio of the Site Logo the general shape/silhouette of the overall block does not appear to be updated. I wonder if that's related to #29217?

@ajlende
Copy link
Contributor Author

@ajlende ajlende commented May 11, 2021

I wonder if that's related to #29217?

It seems like it might be. The width calculation seems to be a render behind which causes issues both here and when the resize happens.

@ajlende ajlende force-pushed the add/site-logo-crop branch from fb356e0 to 8e19d32 Jun 21, 2021
@ajlende
Copy link
Contributor Author

@ajlende ajlende commented Jun 21, 2021

@jasmussen I finally circled back around on this, and I think the issue is fixed now after the rebase. Give it another look, and if everything is good we can get this merged :)

EDIT: I was able to reproduce it again now. Looking into the fix.

@jasmussen
Copy link
Contributor

@jasmussen jasmussen commented Jun 22, 2021

I was just about to compile this, then saw the edit :D

Please do ping me as soon as you can use my help, whether as a review or otherwise.

Copy link
Contributor

@jasmussen jasmussen left a comment

Very nice, thank you!

site logo
ar

If you can get a sanity check on the code it would be nice, but functionally this is solid!

@ajlende ajlende force-pushed the add/site-logo-crop branch 2 times, most recently from eb81d5d to bab8025 Jun 24, 2021
@ajlende ajlende force-pushed the add/site-logo-crop branch from bab8025 to e410a4d Jun 28, 2021
packages/block-editor/README.md Outdated Show resolved Hide resolved
@jasmussen
Copy link
Contributor

@jasmussen jasmussen commented Aug 20, 2021

Is this one blocked?

Conflicts:
	package-lock.json
	packages/block-editor/README.md
	packages/block-editor/package.json
	packages/block-library/src/site-logo/edit.js
@ajlende
Copy link
Contributor Author

@ajlende ajlende commented Sep 13, 2021

There was a bug with the applied image not showing up in trunk for a while, but it seems to be resolved. I merged in the changes and it seems to be working as intended again.

@ajlende ajlende requested a review from talldan Sep 13, 2021
size={ {
width: currentWidth,
height: currentHeight,
} }
Copy link
Contributor Author

@ajlende ajlende Sep 13, 2021

Using currentWidth and currentHeight fixes the bug described in #29217

@ajlende ajlende force-pushed the add/site-logo-crop branch from 3535708 to 2574192 Sep 14, 2021
Copy link
Member

@vcanales vcanales left a comment

When cropping, if we deselect the image block the crop tool stays on. This creates a couple of issues;

  1. At first it's hard to tell that the crop hasn't been applied, even after updating the post. I think it might be good to either Apply or Cancel when deselecting the block, or Applying when the post is saved while cropping.

Kapture 2021-09-14 at 10 01 53

  1. It becomes hard to select the image block again; dragging seems to interfere with clicking on the block. A way I found to achieve it was to tab into the block, and then clicking it.

Kapture 2021-09-14 at 10 05 58

I'm also wondering if it is possible to allow to "decrop" the image; as of right now, Applying the crop creates a new one, and in order to un-do from this point it's necessary to replace the cropped image with the original one.

@ajlende
Copy link
Contributor Author

@ajlende ajlende commented Sep 14, 2021

  1. At first it's hard to tell that the crop hasn't been applied, even after updating the post. I think it might be good to either Apply or Cancel when deselecting the block, or Applying when the post is saved while cropping.

  2. It becomes hard to select the image block again; dragging seems to interfere with clicking on the block. A way I found to achieve it was to tab into the block, and then clicking it.

Nice catch! Deselecting should match the behavior of the image block now.

I'm also wondering if it is possible to allow to "decrop" the image; as of right now, Applying the crop creates a new one, and in order to un-do from this point it's necessary to replace the cropped image with the original one.

Seems like a good idea—we could update the cropper to make sure an undo layer is created when hitting apply so we can, at least, hit ctrl+z to undo it until a page refresh.

Right now, this matches the behavior of the image block, so it's probably best left as a follow-up to fix in both places.

Copy link
Member

@vcanales vcanales left a comment

Right now, this matches the behavior of the image block, so it's probably best left as a follow-up to fix in both places.

Agreed! LGTM :)

@ajlende ajlende merged commit acf909f into WordPress:trunk Sep 20, 2021
17 of 19 checks passed
@ajlende ajlende deleted the add/site-logo-crop branch Sep 20, 2021
@github-actions github-actions bot added this to the Gutenberg 11.6 milestone Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment