-
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 aspect ratio to image placeholder #54216
Conversation
Size Change: +10.1 kB (+1%) Total Size: 1.53 MB
ℹ️ View Unchanged
|
@@ -726,6 +778,10 @@ export default function Image( { | |||
); | |||
} | |||
|
|||
if ( ! url && ! temporaryURL ) { | |||
return sizeControls; |
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.
Do we need a new sizeControls
const or can we reuse 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.
controls
includes caption and I think setting caption on placeholder is not expected.
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.
Could we update controls to extend sizeControls?
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.
Sure we could add some internal getter for controls that supports an include caption arg but why tho 😁 - it's not something really reused, it's a one time need in terms of the block's codebase.
<ResolutionTool | ||
value={ sizeSlug } | ||
onChange={ updateImage } | ||
options={ imageSizeOptions } | ||
/> |
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 don't think the ResolutionTool
is needed if you don't have an image to set the resolution of.
<DimensionsTool | ||
value={ { width, height, scale, aspectRatio } } | ||
onChange={ ( { | ||
width: newWidth, | ||
height: newHeight, | ||
scale: newScale, | ||
aspectRatio: newAspectRatio, | ||
} ) => { | ||
// Rebuilding the object forces setting `undefined` | ||
// for values that are removed since setAttributes | ||
// doesn't do anything with keys that aren't set. | ||
setAttributes( { | ||
// CSS includes `height: auto`, but we need | ||
// `width: auto` to fix the aspect ratio when | ||
// only height is set due to the width and | ||
// height attributes set via the server. | ||
width: | ||
! newWidth && newHeight ? 'auto' : newWidth, | ||
height: newHeight, | ||
scale: newScale, | ||
aspectRatio: newAspectRatio, | ||
} ); | ||
} } | ||
defaultScale="cover" | ||
defaultAspectRatio="auto" | ||
scaleOptions={ scaleOptions } | ||
unitsOptions={ dimensionsUnitsOptions } | ||
/> | ||
) } |
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 bit is being reused in controls
. May as well make it another internal variable that gets used in both places so changes to one don't go missing on the other by accident.
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.
that's what i meant!
Very excited to see this coming along! This will be a huge win for patterns in particular. Tested this and my only point of feedback is around the placement of the placeholder text. Right now, when selecting aspect ratio sizes like the Tall option, the options seem to disappear off the page: ![]() Here's a recording: aspect.ratio.movFinally, I noticed that for changing the sizing to be really small, the options are cut off in an inelegant way. Definitely edge case but wanted to note as I remember this coming up previously with columns #17721: ![]() |
Thanks for the testing @annezazu 🎉 For the placeholder actions going offscreen maybe I can align them top left instead of center left. For the "very small" edge case I have no idea what to try. |
Can we make the placeholder scrollable? |
I added a commit for this. |
Added a commit for this. |
I also did the refactor, so I think this is ready for another review. |
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.
It gets the job done fine, but does expose a need to improve the active placeholder state.
CleanShot.2023-09-08.at.16.30.07.mp4
Would appreciate @ajlende's review.
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 @scruffian 's changes address all the feedback but I won't approve my own PR 😆
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.
LGTM 👍
What?
Closes #48081
Why?
To make placeholders better for layout construction.
How?
Testing Instructions
Testing Instructions for Keyboard
N/A
Screenshots or screencast
placeholder-aspect-ratio.mp4