Skip to content
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

Update: Image Block: Change image by drag & drop an image from the desktop #14983

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 31 additions & 29 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,39 +400,40 @@ class ImageEdit extends Component {
) }
</BlockControls>
);
const src = isExternal ? url : undefined;
const labels = {
title: ! url ? __( 'Image' ) : __( 'Edit image' ),
instructions: __( 'Drag an image to upload, select a file from your library or add one from an URL.' ),
};
const mediaPreview = ( !! url && <img
alt={ __( 'Edit image' ) }
title={ __( 'Edit image' ) }
className={ 'edit-image-preview' }
src={ url }
/> );
const mediaPlaceholder = (
<MediaPlaceholder
icon={ <BlockIcon icon={ icon } /> }
className={ className }
labels={ labels }
onSelect={ this.onSelectImage }
onSelectURL={ this.onSelectURL }
onDoubleClick={ this.toggleIsEditing }
onCancel={ !! url && this.toggleIsEditing }
notices={ noticeUI }
onError={ this.onUploadError }
accept="image/*"
allowedTypes={ ALLOWED_MEDIA_TYPES }
value={ { id, src } }
mediaPreview={ mediaPreview }
dropZoneUIOnly={ ! isEditing && url }
/>
);
if ( isEditing || ! url ) {
const src = isExternal ? url : undefined;

const labels = {
title: ! url ? __( 'Image' ) : __( 'Edit image' ),
instructions: __( 'Drag an image to upload, select a file from your library or add one from an URL.' ),
};

const mediaPreview = ( !! url && <img
alt={ __( 'Edit image' ) }
title={ __( 'Edit image' ) }
className={ 'edit-image-preview' }
src={ url }
/> );

return (
<Fragment>
{ controls }
<MediaPlaceholder
icon={ <BlockIcon icon={ icon } /> }
className={ className }
labels={ labels }
onSelect={ this.onSelectImage }
onSelectURL={ this.onSelectURL }
onDoubleClick={ this.toggleIsEditing }
onCancel={ !! url && this.toggleIsEditing }
notices={ noticeUI }
onError={ this.onUploadError }
accept="image/*"
allowedTypes={ ALLOWED_MEDIA_TYPES }
value={ { id, src } }
mediaPreview={ mediaPreview }
/>
{ mediaPlaceholder }
</Fragment>
);
}
Expand Down Expand Up @@ -707,6 +708,7 @@ class ImageEdit extends Component {
/>
) }
</figure>
{ mediaPlaceholder }
</Fragment>
);
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
Expand Down