Skip to content

Commit

Permalink
feature: add consistant illustrator to media text block
Browse files Browse the repository at this point in the history
  • Loading branch information
up1512001 committed Nov 7, 2024
1 parent ab6e729 commit 2f2f6fb
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions packages/block-library/src/media-text/media-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
store as blockEditorStore,
} from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { useViewportMatch } from '@wordpress/compose';
import { useViewportMatch, useResizeObserver } from '@wordpress/compose';
import { useDispatch } from '@wordpress/data';
import { forwardRef } from '@wordpress/element';
import { isBlobURL } from '@wordpress/blob';
Expand Down Expand Up @@ -76,26 +76,43 @@ function PlaceholderContainer( {
mediaUrl,
onSelectMedia,
toggleUseFeaturedImage,
isSelected,
} ) {
const { createErrorNotice } = useDispatch( noticesStore );

const onUploadError = ( message ) => {
createErrorNotice( message, { type: 'snackbar' } );
};

const [ placeholderResizeListener, { width: placeholderWidth } ] =
useResizeObserver();

const isSmallContainer = placeholderWidth && placeholderWidth < 160;

return (
<MediaPlaceholder
icon={ <BlockIcon icon={ icon } /> }
labels={ {
title: __( 'Media area' ),
} }
className={ className }
onSelect={ onSelectMedia }
accept="image/*,video/*"
onToggleFeaturedImage={ toggleUseFeaturedImage }
allowedTypes={ ALLOWED_MEDIA_TYPES }
onError={ onUploadError }
disableMediaButtons={ mediaUrl }
placeholder={ ( content ) => (
<Placeholder
className="block-editor-media-placeholder"
icon={ icon }
withIllustration={ ! isSelected || isSmallContainer }
label={ ! isSmallContainer && __( 'Media area' ) }
instructions={ __(
'Upload a media file or pick one from your media library.'
) }
>
{ content }
{ placeholderResizeListener }
</Placeholder>
) }
/>
);
}
Expand Down

0 comments on commit 2f2f6fb

Please sign in to comment.