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 loading state to use a spinner and a faded static image. #11876

Merged
merged 3 commits into from
Nov 15, 2018
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
7 changes: 4 additions & 3 deletions packages/block-library/src/gallery/editor.scss
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@ ul.wp-block-gallery li {
outline: 4px solid theme(primary);
}

&.is-transient img {
@include edit-post__loading-fade-animation;
.is-transient img {
opacity: 0.3;
}

.editor-rich-text {
@@ -119,7 +119,8 @@ ul.wp-block-gallery li {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
margin-top: -9px;
margin-left: -9px;
}

// Last item always needs margins reset.
24 changes: 19 additions & 5 deletions packages/block-library/src/gallery/gallery-image.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import classnames from 'classnames';
/**
* WordPress Dependencies
*/
import { Component } from '@wordpress/element';
import { Component, Fragment } from '@wordpress/element';
import { IconButton, Spinner } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { BACKSPACE, DELETE } from '@wordpress/keycodes';
@@ -99,10 +99,24 @@ class GalleryImage extends Component {
break;
}

// Disable reason: Image itself is not meant to be
// interactive, but should direct image selection and unfocus caption fields
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
const img = url ? <img src={ url } alt={ alt } data-id={ id } onClick={ this.onImageClick } tabIndex="0" onKeyDown={ this.onImageClick } aria-label={ ariaLabel } /> : <Spinner />;
const img = (
// Disable reason: Image itself is not meant to be interactive, but should
// direct image selection and unfocus caption fields.
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
<Fragment>
<img
src={ url }
alt={ alt }
data-id={ id }
onClick={ this.onImageClick }
tabIndex="0"
onKeyDown={ this.onImageClick }
aria-label={ ariaLabel }
/>
{ isBlobURL( url ) && <Spinner /> }
</Fragment>
/* eslint-enable jsx-a11y/no-noninteractive-element-interactions */
);

const className = classnames( {
'is-selected': isSelected,
16 changes: 12 additions & 4 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ import {
PanelBody,
ResizableBox,
SelectControl,
Spinner,
TextControl,
TextareaControl,
Toolbar,
@@ -506,10 +507,17 @@ class ImageEdit extends Component {
} else {
defaultedAlt = __( 'This image has an empty alt attribute' );
}
// Disable reason: Image itself is not meant to be
// interactive, but should direct focus to block
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
const img = <img src={ url } alt={ defaultedAlt } onClick={ this.onImageClick } />;

const img = (
// Disable reason: Image itself is not meant to be interactive, but
// should direct focus to block.
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
<Fragment>
<img src={ url } alt={ defaultedAlt } onClick={ this.onImageClick } />
{ isBlobURL( url ) && <Spinner /> }
</Fragment>
/* eslint-enable jsx-a11y/no-noninteractive-element-interactions */
);

if ( ! isResizable || ! imageWidthWithinContainer ) {
return (
11 changes: 10 additions & 1 deletion packages/block-library/src/image/editor.scss
Original file line number Diff line number Diff line change
@@ -2,12 +2,21 @@
position: relative;

&.is-transient img {
@include edit-post__loading-fade-animation;
opacity: 0.3;
}

figcaption img {
display: inline;
}

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

// This is necessary for the editor resize handles to accurately work on a non-floated, non-resized, small image.