const { __ } = wp.i18n; const { Component, } = wp.element; const { BaseControl, DropZone, Button, } = wp.components; const { MediaPlaceholder, MediaUpload, mediaUpload, } = wp.editor; /** * Component */ export default class ComponentGalleryControl extends Component { constructor() { super(...arguments); } render() { const ALLOWED_MEDIA_TYPES = [ 'image' ]; const { val, label, help, onChange, } = this.props; return ( { ! val || ! val.length ? ( { const result = images.map( ( image ) => { return image.id; } ); onChange( result ); } } accept="image/*" allowedTypes={ ALLOWED_MEDIA_TYPES } disableMaxUploadErrorMessages multiple onError={ ( e ) => { // eslint-disable-next-line no-console console.log( e ); } } /> ) : '' } { val && val.length ? ( { const result = images.map( ( image ) => { return image.id; } ); onChange( result ); } } allowedTypes={ ALLOWED_MEDIA_TYPES } multiple gallery value={ val } render={ ( { open } ) => (
{ const currentImages = val || []; mediaUpload( { allowedTypes: ALLOWED_MEDIA_TYPES, filesList: files, onFileChange: ( images ) => { const result = images.map( ( image ) => { return image.id; } ); onChange( currentImages.concat( result ) ); }, onError( e ) { // eslint-disable-next-line no-console console.log( e ); }, } ); } } /> { val ? (
{val.map(imageId => { return ( ) })}
) : '' }
) } /> ) : '' }
); } }