Skip to content

Commit

Permalink
Update: Image Block: Change image by drag & drop an image from the de…
Browse files Browse the repository at this point in the history
…sktop (#14983)
  • Loading branch information
jorgefilipecosta authored May 1, 2019
1 parent 56e6d77 commit 6552706
Showing 1 changed file with 31 additions and 29 deletions.
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

0 comments on commit 6552706

Please sign in to comment.