From 460d63b70e99dfd7e33640e23a7607eeae4efa72 Mon Sep 17 00:00:00 2001
From: Joen A <1204802+jasmussen@users.noreply.github.com>
Date: Wed, 17 Nov 2021 18:22:40 +0100
Subject: [PATCH] Try: Let Featured Image block inherit dimensions, look like a
placeholder (#36517)
* Try: Let Featured Image block inherit dimensions, look like a placeholder
* Inherit dimensions.
* Change notice to snackbar.
* Fix edgecase.
---
.../src/post-featured-image/edit.js | 82 +++++++---
.../src/post-featured-image/editor.scss | 144 +++++++++++++++---
.../block-library/src/site-logo/editor.scss | 1 +
3 files changed, 186 insertions(+), 41 deletions(-)
diff --git a/packages/block-library/src/post-featured-image/edit.js b/packages/block-library/src/post-featured-image/edit.js
index 513771c4c123f0..0aaff3c717f8df 100644
--- a/packages/block-library/src/post-featured-image/edit.js
+++ b/packages/block-library/src/post-featured-image/edit.js
@@ -2,34 +2,50 @@
* WordPress dependencies
*/
import { useEntityProp, store as coreStore } from '@wordpress/core-data';
-import { useSelect } from '@wordpress/data';
+import { useSelect, useDispatch } from '@wordpress/data';
import {
- Icon,
ToggleControl,
PanelBody,
+ Placeholder,
withNotices,
+ Button,
} from '@wordpress/components';
import {
InspectorControls,
BlockControls,
MediaPlaceholder,
MediaReplaceFlow,
- BlockIcon,
useBlockProps,
} from '@wordpress/block-editor';
import { __, sprintf } from '@wordpress/i18n';
-import { postFeaturedImage } from '@wordpress/icons';
+import { upload } from '@wordpress/icons';
+import { SVG, Path } from '@wordpress/primitives';
+import { store as noticesStore } from '@wordpress/notices';
/**
* Internal dependencies
*/
import DimensionControls from './dimension-controls';
+const placeholderIllustration = (
+
+);
+
const ALLOWED_MEDIA_TYPES = [ 'image' ];
const placeholderChip = (
-
-
-
{ __( 'Featured Image' ) }
+
+ { placeholderIllustration }
);
@@ -38,7 +54,6 @@ function PostFeaturedImageDisplay( {
setAttributes,
context: { postId, postType, queryId },
noticeUI,
- noticeOperations,
} ) {
const isDescendentOfQueryLoop = !! queryId;
const { isLink, height, width, scale } = attributes;
@@ -48,42 +63,67 @@ function PostFeaturedImageDisplay( {
'featured_media',
postId
);
+
const media = useSelect(
( select ) =>
featuredImage &&
select( coreStore ).getMedia( featuredImage, { context: 'view' } ),
[ featuredImage ]
);
+
const blockProps = useBlockProps( {
- style: { width },
+ style: { width, height },
} );
+
+ const placeholder = ( content ) => {
+ return (
+
+ { placeholderIllustration }
+ { content }
+
+ );
+ };
+
const onSelectImage = ( value ) => {
if ( value?.id ) {
setFeaturedImage( value.id );
}
};
- function onUploadError( message ) {
- noticeOperations.removeAllNotices();
- noticeOperations.createErrorNotice( message );
- }
+
+ const { createErrorNotice } = useDispatch( noticesStore );
+ const onUploadError = ( message ) => {
+ createErrorNotice( message[ 2 ], { type: 'snackbar' } );
+ };
+
let image;
if ( ! featuredImage && isDescendentOfQueryLoop ) {
return
{ placeholderChip }
;
}
+
+ const label = __( 'Add a featured image' );
+
if ( ! featuredImage ) {
image = (
}
onSelect={ onSelectImage }
- notices={ noticeUI }
- onError={ onUploadError }
accept="image/*"
allowedTypes={ ALLOWED_MEDIA_TYPES }
- labels={ {
- title: __( 'Featured image' ),
- instructions: __(
- 'Upload a media file or pick one from your media library.'
- ),
+ onError={ onUploadError }
+ placeholder={ placeholder }
+ notices={ noticeUI }
+ mediaLibraryButton={ ( { open } ) => {
+ return (
+