Skip to content

Commit

Permalink
Gallery Block: Add Media Library buttons to the upload new image area…
Browse files Browse the repository at this point in the history
…; Media Upload: Allow galleries to open in the library frame.
  • Loading branch information
jorgefilipecosta committed Nov 27, 2018
1 parent 640b2ff commit 70134dd
Showing 4 changed files with 73 additions and 18 deletions.
27 changes: 25 additions & 2 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* External Dependencies
*/
import classnames from 'classnames';
import { filter, pick, map, get } from 'lodash';

/**
@@ -284,17 +285,39 @@ class GalleryEdit extends Component {
);
} ) }
{ isSelected &&
<li className="blocks-gallery-item has-add-item-button">
<li className={ classnames(
'blocks-gallery-item',
'has-add-item-button',
'block-library-gallery-add-item'
) }>
<FormFileUpload
multiple
isLarge
className="block-library-gallery-add-item-button"
onChange={ this.uploadFromFiles }
accept="image/*"
icon="insert"
className="block-library-gallery-add-item__upload-button"
>
{ __( 'Upload an image' ) }
</FormFileUpload>
<MediaUpload
onSelect={ this.onSelectImages }
allowedTypes={ ALLOWED_MEDIA_TYPES }
galleryOpenInLibrary
multiple
gallery
value={ images.map( ( img ) => img.id ) }
render={ ( { open } ) => (
<IconButton
icon="admin-media"
isLarge
onClick={ open }
className="block-library-gallery-add-item__media-library-button"
>
{ __( 'Media Library' ) }
</IconButton>
) }
/>
</li>
}
</ul>
45 changes: 30 additions & 15 deletions packages/block-library/src/gallery/editor.scss
Original file line number Diff line number Diff line change
@@ -53,28 +53,43 @@ ul.wp-block-gallery li {
}
}

.components-form-file-upload,
.components-button.block-library-gallery-add-item-button {
&.block-library-gallery-add-item {
width: 100%;
height: 100%;
min-height: 100px;
border: dotted;
border-color: $light-gray-800;
flex-direction: row;
justify-content: center;
align-items: center;

.dashicon {
margin-right: 6px;
}
}

.components-button.block-library-gallery-add-item-button {
display: flex;
flex-direction: column;
justify-content: center;
.block-library-gallery-add-item__upload-button,
.block-library-gallery-add-item__media-library-button {
box-shadow: none;
&.components-button:hover,
&.components-button:focus {
box-shadow: none;
border: $border-width solid $dark-gray-500;
}
}

.block-library-gallery-add-item__upload-button {
border: none;
border-radius: 0;
min-height: 100px;
background: none;
box-shadow: none;
margin-right: 25px;
}

& .dashicon {
margin-top: 10px;
}
.block-library-gallery-add-item__media-library-button {
background-color: $light-gray-100;

&:hover,
&:focus {
border: $border-width solid $dark-gray-500;

.dashicon {
color: $light-gray-900;
}
}

Original file line number Diff line number Diff line change
@@ -78,6 +78,7 @@ class MediaUpload extends Component {
allowedTypes,
multiple = false,
gallery = false,
galleryOpenInLibrary = false,
title = __( 'Select or Upload Media' ),
modalClass,
value,
@@ -90,7 +91,12 @@ class MediaUpload extends Component {
this.onClose = this.onClose.bind( this );

if ( gallery ) {
const currentState = value ? 'gallery-edit' : 'gallery';
let currentState;
if ( galleryOpenInLibrary ) {
currentState = 'gallery-library';
} else {
currentState = value ? 'gallery-edit' : 'gallery';
}
const GalleryDetailsMediaFrame = getGalleryDetailsMediaFrame();
const attachments = getAttachmentsCollection( value );
const selection = new wp.media.model.Selection( attachments.models, {
11 changes: 11 additions & 0 deletions packages/editor/src/components/media-upload/README.md
Original file line number Diff line number Diff line change
@@ -101,6 +101,17 @@ CSS class added to the media modal frame.
- Type: `String`
- Required: No


### galleryOpenInLibrary

If true the gallery media modal will open in directly in the media library where additional images can be added.
If false the gallery media modal will open in the edit mode where existing images can be edited.
Only applies if gallery = true.

- Type: `Boolean`
- Required: No
- Default: `false`

## render

A callback invoked to render the Button opening the media library.

0 comments on commit 70134dd

Please sign in to comment.