Skip to content

Commit

Permalink
Image: Try different resting state for placeholder, alternate version (
Browse files Browse the repository at this point in the history
…#43180)

* Image: Try different resting state for placeholder, alternate version

* Polish after rebase.

* Try: Minimal styling.

* Add back the legacy placeholder.
  • Loading branch information
jasmussen authored Aug 18, 2022
1 parent 14092ce commit ef94685
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
20 changes: 19 additions & 1 deletion packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { get, has, isEmpty, omit, pick } from 'lodash';
* WordPress dependencies
*/
import { getBlobByURL, isBlobURL, revokeBlobURL } from '@wordpress/blob';
import { withNotices } from '@wordpress/components';
import { withNotices, Placeholder } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import {
BlockAlignmentControl,
Expand All @@ -28,6 +28,23 @@ import { image as icon } from '@wordpress/icons';
*/
import Image from './image';

// Much of this description is duplicated from MediaPlaceholder.
const placeholder = ( content ) => {
return (
<Placeholder
className="block-editor-media-placeholder"
withIllustration={ true }
icon={ icon }
label={ __( 'Image' ) }
instructions={ __(
'Upload an image file, pick one from your media library, or add one with a URL.'
) }
>
{ content }
</Placeholder>
);
};

/**
* Module constants
*/
Expand Down Expand Up @@ -344,6 +361,7 @@ export function ImageEdit( {
onSelectURL={ onSelectURL }
notices={ noticeUI }
onError={ onUploadError }
placeholder={ placeholder }
accept="image/*"
allowedTypes={ ALLOWED_MEDIA_TYPES }
value={ { id, src } }
Expand Down
35 changes: 32 additions & 3 deletions packages/block-library/src/image/editor.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
// Provide special styling for the placeholder.
// @todo: this particular minimal style of placeholder could be componentized further.
.wp-block-image.wp-block-image {
// Show Placeholder style on-select.
&.is-selected .components-placeholder {
// Block UI appearance.
color: $gray-900;
background-color: $white;
box-shadow: inset 0 0 0 $border-width $gray-900;
border: none;

// @todo: this should eventually be overridden by a custom border-radius set in the inspector.
border-radius: $radius-block-ui;

> svg {
opacity: 0;
}
}

// Remove the transition while we still have a legacy placeholder style.
// Otherwise the content jumps between the 1px placeholder border, and any inherited custom
// parent border that may get applied when you deselect.
.components-placeholder__label,
.components-placeholder__instructions,
.components-button {
transition: none;
}
}


figure.wp-block-image:not(.wp-block) {
margin: 0;
}
Expand All @@ -14,13 +44,12 @@ figure.wp-block-image:not(.wp-block) {
display: inline;
}

// Shown while image is being uploaded
// Shown while image is being uploaded.
.components-spinner {
position: absolute;
top: 50%;
left: 50%;
margin-top: -9px;
margin-left: -9px;
transform: translate(-50%, -50%);
}
}

Expand Down
10 changes: 8 additions & 2 deletions packages/components/src/placeholder/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,20 @@

// Show placeholder buttons on block selection.
// Note that these can't be display: none; or visibility: hidden;, as that breaks the writing flow.
.components-placeholder__label,
.components-placeholder__instructions,
.components-button {
opacity: 0;
transition: opacity 0.1s linear;
@include reduce-motion("transition");
}

.is-selected > & .components-button {
opacity: 1;
.is-selected > & {
.components-placeholder__label,
.components-placeholder__instructions,
.components-button {
opacity: 1;
}
}

// By painting the borders here, we enable them to be replaced by the Border control.
Expand Down

0 comments on commit ef94685

Please sign in to comment.