-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show PostFeaturedImage in editor (#25412)
* show PostFeaturedImage in editor * change wording * add placeholder chip
- Loading branch information
1 parent
b3a6f4d
commit d2d04cb
Showing
5 changed files
with
49 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,46 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useEntityProp, useEntityId } from '@wordpress/core-data'; | ||
import { useEntityProp } from '@wordpress/core-data'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { ResponsiveWrapper } from '@wordpress/components'; | ||
import { ResponsiveWrapper, Icon } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { postFeaturedImage as icon } from '@wordpress/icons'; | ||
|
||
function PostFeaturedImageDisplay() { | ||
function PostFeaturedImageDisplay( { context: { postId, postType } } ) { | ||
const [ featuredImage ] = useEntityProp( | ||
'postType', | ||
'post', | ||
'featured_media' | ||
postType, | ||
'featured_media', | ||
postId | ||
); | ||
const media = useSelect( | ||
( select ) => | ||
featuredImage && select( 'core' ).getMedia( featuredImage ), | ||
[ featuredImage ] | ||
); | ||
return media ? ( | ||
if ( ! media ) { | ||
return ( | ||
<div className="post-featured-image_placeholder"> | ||
<Icon icon={ icon } /> | ||
<p> { __( 'Featured Image' ) }</p> | ||
</div> | ||
); | ||
} | ||
const alt = media.alt_text || __( 'No alternative text set' ); | ||
return ( | ||
<ResponsiveWrapper | ||
naturalWidth={ media.media_details.width } | ||
naturalHeight={ media.media_details.height } | ||
> | ||
<img src={ media.source_url } alt="Post Featured Media" /> | ||
<img src={ media.source_url } alt={ alt } /> | ||
</ResponsiveWrapper> | ||
) : null; | ||
); | ||
} | ||
|
||
export default function PostFeaturedImageEdit() { | ||
if ( ! useEntityId( 'postType', 'post' ) ) { | ||
return __( 'Post Featured Image' ); | ||
export default function PostFeaturedImageEdit( props ) { | ||
if ( ! props.context?.postId ) { | ||
return __( 'Featured Image' ); | ||
} | ||
return <PostFeaturedImageDisplay />; | ||
return <PostFeaturedImageDisplay { ...props } />; | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/block-library/src/post-featured-image/editor.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
div[data-type="core/post-featured-image"] { | ||
.post-featured-image_placeholder { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: flex-start; | ||
border-radius: $radius-block-ui; | ||
background-color: $white; | ||
box-shadow: inset 0 0 0 $border-width $gray-900; | ||
padding: $grid-unit-15; | ||
svg { | ||
margin-right: $grid-unit-15; | ||
} | ||
p { | ||
font-family: $default-font; | ||
font-size: $default-font-size; | ||
margin: 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,10 @@ | |
& > span { | ||
display: block; | ||
} | ||
&, | ||
& > img { | ||
width: auto; | ||
} | ||
} | ||
|
||
.components-responsive-wrapper__content { | ||
|