Skip to content

Commit

Permalink
Implemented flow for adding in images in the gallery without going to…
Browse files Browse the repository at this point in the history
… the media library.
  • Loading branch information
jorgefilipecosta committed Feb 23, 2018
1 parent eba2144 commit 9c6cce7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
24 changes: 21 additions & 3 deletions blocks/library/gallery/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { mediaUpload } from '@wordpress/utils';
import {
IconButton,
DropZone,
FormFileUpload,
RangeControl,
SelectControl,
ToggleControl,
Expand Down Expand Up @@ -51,7 +52,8 @@ class GalleryBlock extends Component {
this.toggleImageCrop = this.toggleImageCrop.bind( this );
this.onRemoveImage = this.onRemoveImage.bind( this );
this.setImageAttributes = this.setImageAttributes.bind( this );
this.dropFiles = this.dropFiles.bind( this );
this.addFiles = this.addFiles.bind( this );
this.uploadFromFiles = this.uploadFromFiles.bind( this );

this.state = {
selectedImage: null,
Expand Down Expand Up @@ -122,7 +124,11 @@ class GalleryBlock extends Component {
} );
}

dropFiles( files ) {
uploadFromFiles( event ) {
this.addFiles( event.target.files );
}

addFiles( files ) {
const currentImages = this.props.attributes.images || [];
const { setAttributes } = this.props;
mediaUpload(
Expand Down Expand Up @@ -151,7 +157,7 @@ class GalleryBlock extends Component {

const dropZone = (
<DropZone
onFilesDrop={ this.dropFiles }
onFilesDrop={ this.addFiles }
/>
);

Expand Down Expand Up @@ -239,6 +245,18 @@ class GalleryBlock extends Component {
/>
</li>
) ) }
{ isSelected &&
<li className="blocks-gallery-item">
<FormFileUpload
multiple
isLarge
className="blocks-gallery-add-item-button"
onChange={ this.uploadFromFiles }
accept="image/*"
icon="insert"
/>
</li>
}
</ul>,
];
}
Expand Down
22 changes: 22 additions & 0 deletions blocks/library/gallery/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@
margin-top: -4px;
}

.components-form-file-upload,
.button.blocks-gallery-add-item-button {
width: 100%;
height: 100%;
}

.button.blocks-gallery-add-item-button {
box-shadow: none;
border: none;
border-radius: 0;
min-height: 100px;

& .dashicon {
margin-top: 10px;
}


&:hover,
&:focus {
border: 1px solid #999;
}
}
}

.blocks-gallery-item__inline-menu {
Expand Down
4 changes: 2 additions & 2 deletions components/form-file-upload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class FormFileUpload extends Component {
}

render() {
const { children, multiple = false, accept, onChange, ...props } = this.props;
const { children, multiple = false, accept, onChange, icon = 'upload', ...props } = this.props;

return (
<div className="components-form-file-upload">
<IconButton
icon="upload"
icon={ icon }
onClick={ this.openFileDialog }
{ ...props }
>
Expand Down

0 comments on commit 9c6cce7

Please sign in to comment.