-
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
Revisit image floats. #7721
Revisit image floats. #7721
Changes from all commits
c402592
a2602f3
13a6daa
1362fa7
888fecb
35bf4c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import classnames from 'classnames'; | |
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Fragment } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
createBlock, | ||
|
@@ -216,15 +217,59 @@ export const settings = { | |
/> | ||
); | ||
|
||
return ( | ||
<figure className={ classes }> | ||
const figure = ( | ||
<Fragment> | ||
{ href ? <a href={ href }>{ image }</a> : image } | ||
{ caption && caption.length > 0 && <RichText.Content tagName="figcaption" value={ caption } /> } | ||
</Fragment> | ||
); | ||
|
||
if ( 'left' === align || 'right' === align || 'center' === align ) { | ||
return ( | ||
<div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wasn't this meant to be an aside (from the PR description)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but per discussion in #7721 (comment), I reverted to using a div. I will update the description. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also curious about this though, because it doesn't have a I'm a bit confused by that... |
||
<figure className={ classes }> | ||
{ figure } | ||
</figure> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<figure className={ classes }> | ||
{ figure } | ||
</figure> | ||
); | ||
}, | ||
|
||
deprecated: [ | ||
{ | ||
attributes: blockAttributes, | ||
save( { attributes } ) { | ||
const { url, alt, caption, align, href, width, height, id } = attributes; | ||
|
||
const classes = classnames( { | ||
[ `align${ align }` ]: align, | ||
'is-resized': width || height, | ||
} ); | ||
|
||
const image = ( | ||
<img | ||
src={ url } | ||
alt={ alt } | ||
className={ id ? `wp-image-${ id }` : null } | ||
width={ width } | ||
height={ height } | ||
/> | ||
); | ||
|
||
return ( | ||
<figure className={ classes }> | ||
{ href ? <a href={ href }>{ image }</a> : image } | ||
{ caption && caption.length > 0 && <RichText.Content tagName="figcaption" value={ caption } /> } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be |
||
</figure> | ||
); | ||
}, | ||
}, | ||
{ | ||
attributes: blockAttributes, | ||
save( { attributes } ) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -346,14 +346,16 @@ | |
width: 100%; | ||
|
||
// When images are floated, the block itself should collapse to zero height. | ||
margin-bottom: 0; | ||
height: 0; | ||
|
||
// Hide block outline when an image is floated. | ||
.editor-block-list__block-edit { | ||
&::before { | ||
content: none; | ||
} | ||
|
||
// This margin won't collapse on its own, so zero it out. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not quite sure what this means in this context, so maybe a bit more commenting would be handy. |
||
margin-top: 0; | ||
} | ||
|
||
// Keep a 1px margin to compensate for the border/outline. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<!-- wp:core/image {"align":"center"} --> | ||
<figure class="wp-block-image aligncenter"><img src="https://cldup.com/YLYhpou2oq.jpg" alt="" /><figcaption>Give it a try. Press the "really wide" button on the image toolbar.</figcaption></figure> | ||
<div class="wp-block-image aligncenter"><figure class="aligncenter"><img src="https://cldup.com/YLYhpou2oq.jpg" alt="" /><figcaption>Give it a try. Press the "really wide" button on the image toolbar.</figcaption></figure></div> | ||
<!-- /wp:core/image --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<!-- wp:image {"align":"center"} --> | ||
<figure class="wp-block-image aligncenter"><img src="https://cldup.com/YLYhpou2oq.jpg" alt=""/><figcaption>Give it a try. Press the "really wide" button on the image toolbar.</figcaption></figure> | ||
<!-- wp:image {"align":"center","className":"aligncenter"} --> | ||
<div class="wp-block-image aligncenter"><figure class="aligncenter"><img src="https://cldup.com/YLYhpou2oq.jpg" alt=""/><figcaption>Give it a try. Press the "really wide" button on the image toolbar.</figcaption></figure></div> | ||
<!-- /wp:image --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/latest-comments":{"attributes":{"className":{"type":"string"},"commentsToShow":{"type":"number","default":5,"minimum":1,"maximum":100},"displayAvatar":{"type":"boolean","default":true},"displayDate":{"type":"boolean","default":true},"displayExcerpt":{"type":"boolean","default":true},"align":{"type":"string","enum":["center","left","right","wide","full",""]}}},"core\/archives":{"attributes":{"showPostCounts":{"type":"boolean","default":false},"displayAsDropdown":{"type":"boolean","default":false},"align":{"type":"string","default":"none"}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"className":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string","default":"center"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}}} | ||
{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/latest-comments":{"attributes":{"className":{"type":"string"},"commentsToShow":{"type":"number","default":5,"minimum":1,"maximum":100},"displayAvatar":{"type":"boolean","default":true},"displayDate":{"type":"boolean","default":true},"displayExcerpt":{"type":"boolean","default":true},"align":{"type":"string","enum":["center","left","right","wide","full",""]}}},"core\/archives":{"attributes":{"showPostCounts":{"type":"boolean","default":false},"displayAsDropdown":{"type":"boolean","default":false},"align":{"type":"string","default":"none"}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"className":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}}} |
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 feels like a specific fix to a generic problem, how is this solved for other floated blocks? Can't we have a generic solution to left/right aligned blocks?
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.
Yes we can, though because this PR has gone on since July 5th, I wanted to limit the scope to images for now, and then expand beyond those as soon as we got this into master.