Skip to content

Commit e4b97f5

Browse files
Gallery Block: Add Media Library buttons to the upload new image area; Media Upload: Allow galleries to open in the library frame.
1 parent 0f18024 commit e4b97f5

File tree

5 files changed

+73
-26
lines changed

5 files changed

+73
-26
lines changed

packages/block-library/src/gallery/edit.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -298,17 +298,38 @@ class GalleryEdit extends Component {
298298
);
299299
} ) }
300300
{ isSelected &&
301-
<li className="blocks-gallery-item has-add-item-button">
301+
<li className={ classnames(
302+
'blocks-gallery-item',
303+
'block-library-gallery-add-item'
304+
) }>
302305
<FormFileUpload
303306
multiple
304307
isLarge
305-
className="block-library-gallery-add-item-button"
306308
onChange={ this.uploadFromFiles }
307309
accept="image/*"
308310
icon="insert"
311+
className="block-library-gallery-add-item__upload-button"
309312
>
310313
{ __( 'Upload an image' ) }
311314
</FormFileUpload>
315+
<MediaUpload
316+
onSelect={ this.onSelectImages }
317+
allowedTypes={ ALLOWED_MEDIA_TYPES }
318+
addToGallery
319+
multiple
320+
gallery
321+
value={ images.map( ( img ) => img.id ) }
322+
render={ ( { open } ) => (
323+
<IconButton
324+
icon="admin-media"
325+
isTertiary
326+
onClick={ open }
327+
className="block-library-gallery-add-item__media-library-button"
328+
>
329+
{ __( 'Media Library' ) }
330+
</IconButton>
331+
) }
332+
/>
312333
</li>
313334
}
314335
</ul>

packages/block-library/src/gallery/editor.scss

+32-15
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,45 @@ ul.wp-block-gallery li {
5353
}
5454
}
5555

56-
.components-form-file-upload,
57-
.components-button.block-library-gallery-add-item-button {
56+
&.block-library-gallery-add-item.block-library-gallery-add-item {
5857
width: 100%;
59-
height: 100%;
58+
min-height: 100px;
59+
border: dotted;
60+
border-color: $light-gray-800;
61+
flex-direction: row;
62+
justify-content: center;
63+
align-items: center;
64+
65+
.dashicon {
66+
margin-right: 6px;
67+
}
6068
}
6169

62-
.components-button.block-library-gallery-add-item-button {
63-
display: flex;
64-
flex-direction: column;
65-
justify-content: center;
70+
.block-library-gallery-add-item__upload-button,
71+
.block-library-gallery-add-item__media-library-button {
6672
box-shadow: none;
73+
&.components-button:hover,
74+
&.components-button:focus {
75+
box-shadow: none;
76+
border: $border-width solid $dark-gray-500;
77+
}
78+
}
79+
80+
.block-library-gallery-add-item__upload-button {
6781
border: none;
68-
border-radius: 0;
69-
min-height: 100px;
82+
background: none;
83+
box-shadow: none;
84+
margin-right: 25px;
85+
border: $border-width solid transparent;
86+
}
7087

71-
& .dashicon {
72-
margin-top: 10px;
73-
}
88+
.block-library-gallery-add-item__media-library-button {
89+
background-color: $light-gray-100;
90+
border: $border-width solid $light-gray-500;
7491

75-
&:hover,
76-
&:focus {
77-
border: $border-width solid $dark-gray-500;
92+
93+
.dashicon {
94+
color: $light-gray-900;
7895
}
7996
}
8097

packages/block-library/src/gallery/style.scss

-8
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,6 @@
126126
margin-right: 0;
127127
}
128128

129-
// Make the "Add new Gallery item" button full-width (so it always appears
130-
// below other items).
131-
.blocks-gallery-item {
132-
&.has-add-item-button {
133-
width: 100%;
134-
}
135-
}
136-
137129
// Apply max-width to floated items that have no intrinsic width.
138130
&.alignleft,
139131
&.alignright {

packages/edit-post/src/hooks/components/media-upload/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class MediaUpload extends Component {
8080
allowedTypes,
8181
multiple = false,
8282
gallery = false,
83+
addToGallery = false,
8384
title = __( 'Select or Upload Media' ),
8485
modalClass,
8586
value,
@@ -92,7 +93,12 @@ class MediaUpload extends Component {
9293
this.onClose = this.onClose.bind( this );
9394

9495
if ( gallery ) {
95-
const currentState = value ? 'gallery-edit' : 'gallery';
96+
let currentState;
97+
if ( addToGallery ) {
98+
currentState = 'gallery-library';
99+
} else {
100+
currentState = value ? 'gallery-edit' : 'gallery';
101+
}
96102
const GalleryDetailsMediaFrame = getGalleryDetailsMediaFrame();
97103
const attachments = getAttachmentsCollection( value );
98104
const selection = new wp.media.model.Selection( attachments.models, {

packages/editor/src/components/media-upload/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ CSS class added to the media modal frame.
101101
- Type: `String`
102102
- Required: No
103103

104+
105+
### addToGallery
106+
107+
If true the gallery media modal will open in directly in the media library where additional images can be added.
108+
If false the gallery media modal will open in the edit mode where existing images can be edited.
109+
Only applies if gallery = true.
110+
111+
- Type: `Boolean`
112+
- Required: No
113+
- Default: `false`
114+
104115
## render
105116

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

0 commit comments

Comments
 (0)