-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Refactor image block's image editing tools into separate components. #27089
Conversation
Size Change: +665 B (0%) Total Size: 1.19 MB
ℹ️ View Unchanged
|
9ee1eb1
to
c1f4139
Compare
c1f4139
to
4ab1444
Compare
I have done extensive manual testing to the image block on this branch and found no problems. |
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.
The refactoring introduced no new bugs in my testing and the refactored code adds a bit more clarity (e.g. rotateClockwise
instead of rotate, the separate hooks for saving and transforming etc.).
Thanks @draganescu! |
Description
While trying to come up with a solution to #24676, I found the image editing tools could be modularised more.
There's some really great functionality, but the UI is all in a single component that replaces almost the entire image block's UI when active:
https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/image/image-editor.js
One of the things I wanted to try is rendering the toolbar buttons in a dropdown.
Dropdown
hasrenderToggle
andrenderContent
callback functions, and there's no way to easily have the 'Crop' button as a toggle and the various image editing components as the 'content'.This breaks up the single component into multiple components/hooks:
ImageEditingProvider
is a provider that should wrap all the image editing components, it holds the state for the edits.useImageEditingContext
is a hook that allows an individual component to access values like 'position', 'aspect' from context as well as functions for modifying those values like 'setPosition', 'setAspect'.AspectRatioDropdown
RotationButton
ImageCropper
ZoomDropdown
.How has this been tested?
Some e2e tests have been added in a separate PR (#27262).
Manual testing also recommended.
Screenshots
Types of changes
Refactor
Checklist: