Skip to content

Commit

Permalink
Integrate Media Library button into Gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaz committed May 22, 2017
1 parent d31021f commit 0e25d20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion blocks/library/gallery/gallery-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default class GalleryImage extends wp.element.Component {
render() {
return (
<div key={ this.props.i } className="blocks-gallery-image">
<img src={ this.props.img.src } alt={ this.props.img.alt } />
<img src={ this.props.img.url } alt={ this.props.img.alt } />
</div>
);
}
Expand Down
24 changes: 9 additions & 15 deletions blocks/library/gallery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import './style.scss';
import { registerBlock, query as hpq } from '../../api';

import Button from 'components/button';
import Placeholder from 'components/placeholder';
import MediaUploadButton from '../../media-upload-button';

import GalleryImage from './gallery-image';

Expand All @@ -22,28 +22,22 @@ registerBlock( 'core/gallery', {

edit( { attributes, setAttributes } ) {
const { images } = attributes;

const canned = [
{ src: 'https://lorempixel.com/240/180', alt: '240x180' },
{ src: 'https://lorempixel.com/244/183', alt: '244x183' },
{ src: 'https://lorempixel.com/248/186', alt: '248x186' },
{ src: 'https://lorempixel.com/252/189', alt: '252x189' },
{ src: 'https://lorempixel.com/256/192', alt: '256x192' },
{ src: 'https://lorempixel.com/260/195', alt: '260x195' },
{ src: 'https://lorempixel.com/264/198', alt: '264x198' },
{ src: 'https://lorempixel.com/268/201', alt: '268x201' },
];

if ( ! images ) {
const setMediaUrl = ( imgs ) => setAttributes( { images: imgs } );
return (
<Placeholder
instructions={ wp.i18n.__( 'Drag images here or insert from media library' ) }
icon="format-gallery"
label={ wp.i18n.__( 'Gallery' ) }
className="blocks-gallery">
<Button isLarge onClick={ () => setAttributes( { images: canned } ) }>
<MediaUploadButton
onSelect={ setMediaUrl }
type="image"
auto-open
multiple="true"
>
{ wp.i18n.__( 'Insert from Media Library' ) }
</Button>
</MediaUploadButton>
</Placeholder>
);
}
Expand Down

0 comments on commit 0e25d20

Please sign in to comment.