Skip to content

Commit

Permalink
Refactored Gallery: Add loading state to gallery image size options (#…
Browse files Browse the repository at this point in the history
…27087)

* Add loading spinner for image size options
Co-authored-by: Glen Davies <glen.davies@a8c.com>
  • Loading branch information
aaronrobertshaw authored and Glen Davies committed Feb 23, 2021
1 parent 663c708 commit adf9b28
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
20 changes: 16 additions & 4 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ import {
*/
import { compose } from '@wordpress/compose';
import {
BaseControl,
Button,
PanelBody,
SelectControl,
ToggleControl,
withNotices,
RangeControl,
Spinner,
} from '@wordpress/components';
import {
MediaPlaceholder,
Expand Down Expand Up @@ -364,7 +366,7 @@ function GalleryEdit( props ) {
return <View { ...blockProps }>{ mediaPlaceholder }</View>;
}

const shouldShowSizeOptions = hasImages && ! isEmpty( imageSizeOptions );
const shouldShowSizeOptions = ! isEmpty( imageSizeOptions );
const hasLinkTo = linkTo && linkTo !== 'none';

return (
Expand Down Expand Up @@ -401,16 +403,26 @@ function GalleryEdit( props ) {
onChange={ toggleOpenInNewTab }
/>
) }
{ shouldShowSizeOptions && (
{ shouldShowSizeOptions ? (
<SelectControl
label={ __( 'Image size' ) }
value={ sizeSlug }
options={ imageSizeOptions }
onChange={ updateImagesSize }
/>
) : (
<BaseControl className={ 'gallery-image-sizes' }>
<BaseControl.VisualLabel>
{ __( 'Image size' ) }
</BaseControl.VisualLabel>
<View className={ 'gallery-image-sizes__loading' }>
<Spinner />
{ __( 'Loading options…' ) }
</View>
</BaseControl>
) }
{ dirtyImageOptions && (
<div className={ 'gallery-settings-buttons' }>
<View className={ 'gallery-settings-buttons' }>
<Button isPrimary onClick={ applyImageOptions }>
{ __( 'Apply to all images' ) }
</Button>
Expand All @@ -421,7 +433,7 @@ function GalleryEdit( props ) {
>
{ __( 'Cancel' ) }
</Button>
</div>
</View>
) }
</PanelBody>
</InspectorControls>
Expand Down
31 changes: 25 additions & 6 deletions packages/block-library/src/gallery/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ figure.wp-block-gallery {

.blocks-gallery-item {
// Hide the focus outline that otherwise briefly appears when selecting a block.
figure:not( .is-selected ):focus,
figure:not(.is-selected):focus,
img:focus {
outline: none;
}

figure.is-selected {
box-shadow: 0 0 0 $border-width $white,
0 0 0 3px var( --wp-admin-theme-color );
box-shadow:
0 0 0 $border-width $white,
0 0 0 3px var(--wp-admin-theme-color);
border-radius: $radius-block-ui;
outline: 2px solid transparent;

Expand Down Expand Up @@ -86,9 +87,9 @@ figure.wp-block-gallery {
position: absolute;
top: -2px;
margin: $grid-unit-10;
z-index: z-index( '.block-library-gallery-item__inline-menu' );
z-index: z-index(".block-library-gallery-item__inline-menu");
transition: box-shadow 0.2s ease-out;
@include reduce-motion( 'transition' );
@include reduce-motion( "transition" );
border-radius: $radius-block-ui;
background: $white;
border: $border-width solid $gray-900;
Expand All @@ -106,7 +107,7 @@ figure.wp-block-gallery {
}

.components-button.has-icon {
&:not( :focus ) {
&:not(:focus) {
border: none;
box-shadow: none;
}
Expand Down Expand Up @@ -144,3 +145,21 @@ figure.wp-block-gallery {
margin-right: 8px;
}
}

.gallery-image-sizes {
.components-base-control__label {
display: block;
margin-bottom: 4px;
}

.gallery-image-sizes__loading {
display: flex;
align-items: center;
color: $gray-700;
font-size: $helptext-font-size;
}

.components-spinner {
margin: 0 8px 0 4px;
}
}

0 comments on commit adf9b28

Please sign in to comment.