Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try unifying all the media blocks placeholder under a unique component #6820

Merged
merged 1 commit into from
May 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 21 additions & 57 deletions core-blocks/audio/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import {
Button,
FormFileUpload,
IconButton,
Placeholder,
Toolbar,
} from '@wordpress/components';
import { IconButton, Toolbar } from '@wordpress/components';
import { Component, Fragment } from '@wordpress/element';
import {
MediaUpload,
MediaPlaceholder,
RichText,
BlockControls,
editorMediaUpload,
} from '@wordpress/editor';

/**
Expand All @@ -29,14 +22,13 @@ export default class AudioEdit extends Component {
// without setting the actual value outside of the edit UI
this.state = {
editing: ! this.props.attributes.src,
src: this.props.attributes.src,
};
}

render() {
const { caption, id } = this.props.attributes;
const { caption, src } = this.props.attributes;
const { setAttributes, isSelected, className } = this.props;
const { editing, src } = this.state;
const { editing } = this.state;
const switchToEditing = () => {
this.setState( { editing: true } );
};
Expand All @@ -48,57 +40,29 @@ export default class AudioEdit extends Component {
this.setState( { src: media.url, editing: false } );
}
};
const onSelectUrl = ( event ) => {
event.preventDefault();
if ( src ) {
// set the block's src from the edit component's state, and switch off the editing UI
setAttributes( { src } );
this.setState( { editing: false } );
const onSelectUrl = ( newSrc ) => {
// set the block's src from the edit component's state, and switch off the editing UI
if ( newSrc !== src ) {
setAttributes( { src: newSrc, id: undefined } );
}
return false;
this.setState( { editing: false } );
};
const setAudio = ( [ audio ] ) => onSelectAudio( audio );
const uploadFromFiles = ( event ) => editorMediaUpload( event.target.files, setAudio, 'audio' );

if ( editing ) {
return (
<Placeholder
<MediaPlaceholder
icon="media-audio"
label={ __( 'Audio' ) }
instructions={ __( 'Select an audio file from your library, or upload a new one' ) }
className={ className }>
<form onSubmit={ onSelectUrl }>
<input
type="url"
className="components-placeholder__input"
placeholder={ __( 'Enter URL of audio file here…' ) }
onChange={ ( event ) => this.setState( { src: event.target.value } ) }
value={ src || '' } />
<Button
isLarge
type="submit">
{ __( 'Use URL' ) }
</Button>
</form>
<FormFileUpload
isLarge
className="wp-block-audio__upload-button"
onChange={ uploadFromFiles }
accept="audio/*"
>
{ __( 'Upload' ) }
</FormFileUpload>
<MediaUpload
onSelect={ onSelectAudio }
type="audio"
value={ id }
render={ ( { open } ) => (
<Button isLarge onClick={ open }>
{ __( 'Media Library' ) }
</Button>
) }
/>
</Placeholder>
labels={ {
title: __( 'Audio' ),
name: __( 'an audio' ),
} }
className={ className }
onSelect={ onSelectAudio }
onSelectUrl={ onSelectUrl }
accept="audio/*"
type="audio"
value={ this.props.attributes }
/>
);
}

Expand Down
16 changes: 0 additions & 16 deletions core-blocks/audio/editor.scss
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
.wp-block-audio .components-placeholder__input {
margin-top: 0.5em;
}

.wp-block-audio .components-button.is-large {
margin-top: 0.5em;
}

.wp-block-audio audio {
width: 100%;
}

.wp-block-audio .components-placeholder__fieldset {
max-width: 400px;

form {
max-width: none;
}
}
35 changes: 31 additions & 4 deletions core-blocks/audio/test/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`core/audio block edit matches snapshot 1`] = `
<div
class="components-placeholder wp-block-audio"
class="components-placeholder editor-media-placeholder wp-block-audio"
>
<div
class="components-placeholder__label"
Expand All @@ -26,15 +26,42 @@ exports[`core/audio block edit matches snapshot 1`] = `
<div
class="components-placeholder__instructions"
>
Select an audio file from your library, or upload a new one
Drag an audio, upload a new one or select a file from your library.
</div>
<div
class="components-placeholder__fieldset"
>
<div
class="components-drop-zone"
>
<div
class="components-drop-zone__content"
>
<svg
aria-hidden="true"
class="dashicon dashicons-upload components-drop-zone__content-icon"
focusable="false"
height="40"
role="img"
viewBox="0 0 20 20"
width="40"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M8 14V8H5l5-6 5 6h-3v6H8zm-2 2v-6H4v8h12.01v-8H14v6H6z"
/>
</svg>
<span
class="components-drop-zone__content-text"
>
Drop files to upload
</span>
</div>
</div>
<form>
<input
class="components-placeholder__input"
placeholder="Enter URL of audio file here…"
placeholder="Enter URL here…"
type="url"
value=""
/>
Expand All @@ -49,7 +76,7 @@ exports[`core/audio block edit matches snapshot 1`] = `
class="components-form-file-upload"
>
<button
class="components-button components-icon-button wp-block-audio__upload-button is-button is-default is-large"
class="components-button components-icon-button editor-media-placeholder__upload-button is-button is-default is-large"
type="button"
>
<svg
Expand Down
14 changes: 11 additions & 3 deletions core-blocks/cover-image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
BlockControls,
InspectorControls,
BlockAlignmentToolbar,
ImagePlaceholder,
MediaPlaceholder,
MediaUpload,
AlignmentToolbar,
RichText,
Expand Down Expand Up @@ -183,8 +183,16 @@ export const settings = {
return (
<Fragment>
{ controls }
<ImagePlaceholder
{ ...{ className, icon, label, onSelectImage } }
<MediaPlaceholder
icon={ icon }
className={ className }
labels={ {
title: label,
name: __( 'an image' ),
} }
onSelect={ onSelectImage }
accept="image/*"
type="image"
/>
</Fragment>
);
Expand Down
6 changes: 3 additions & 3 deletions core-blocks/cover-image/test/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`core/cover-image block edit matches snapshot 1`] = `
<div
class="components-placeholder wp-block-cover-image"
class="components-placeholder editor-media-placeholder wp-block-cover-image"
>
<div
class="components-placeholder__label"
Expand All @@ -26,7 +26,7 @@ exports[`core/cover-image block edit matches snapshot 1`] = `
<div
class="components-placeholder__instructions"
>
Drag image here or add from media library
Drag an image, upload a new one or select a file from your library.
</div>
<div
class="components-placeholder__fieldset"
Expand Down Expand Up @@ -62,7 +62,7 @@ exports[`core/cover-image block edit matches snapshot 1`] = `
class="components-form-file-upload"
>
<button
class="components-button components-icon-button wp-block-image__upload-button is-button is-default is-large"
class="components-button components-icon-button editor-media-placeholder__upload-button is-button is-default is-large"
type="button"
>
<svg
Expand Down
15 changes: 10 additions & 5 deletions core-blocks/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
BlockControls,
BlockAlignmentToolbar,
MediaUpload,
ImagePlaceholder,
MediaPlaceholder,
InspectorControls,
editorMediaUpload,
} from '@wordpress/editor';
Expand Down Expand Up @@ -199,11 +199,16 @@ export default class GalleryEdit extends Component {
return (
<Fragment>
{ controls }
<ImagePlaceholder
className={ className }
<MediaPlaceholder
icon="format-gallery"
label={ __( 'Gallery' ) }
onSelectImage={ this.onSelectImages }
className={ className }
labels={ {
title: __( 'Gallery' ),
name: __( 'images' ),
} }
onSelect={ this.onSelectImages }
accept="image/*"
type="image"
multiple
/>
</Fragment>
Expand Down
6 changes: 3 additions & 3 deletions core-blocks/gallery/test/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`core/gallery block edit matches snapshot 1`] = `
<div
class="components-placeholder wp-block-gallery"
class="components-placeholder editor-media-placeholder wp-block-gallery"
>
<div
class="components-placeholder__label"
Expand All @@ -26,7 +26,7 @@ exports[`core/gallery block edit matches snapshot 1`] = `
<div
class="components-placeholder__instructions"
>
Drag images here or add from media library
Drag images, upload a new one or select a file from your library.
</div>
<div
class="components-placeholder__fieldset"
Expand Down Expand Up @@ -62,7 +62,7 @@ exports[`core/gallery block edit matches snapshot 1`] = `
class="components-form-file-upload"
>
<button
class="components-button components-icon-button wp-block-image__upload-button is-button is-default is-large"
class="components-button components-icon-button editor-media-placeholder__upload-button is-button is-default is-large"
type="button"
>
<svg
Expand Down
15 changes: 10 additions & 5 deletions core-blocks/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
RichText,
BlockControls,
InspectorControls,
ImagePlaceholder,
MediaPlaceholder,
MediaUpload,
BlockAlignmentToolbar,
UrlInputButton,
Expand Down Expand Up @@ -203,11 +203,16 @@ class ImageEdit extends Component {
return (
<Fragment>
{ controls }
<ImagePlaceholder
className={ className }
<MediaPlaceholder
icon="format-image"
label={ __( 'Image' ) }
onSelectImage={ this.onSelectImage }
labels={ {
title: __( 'Image' ),
name: __( 'an image' ),
} }
className={ className }
onSelect={ this.onSelectImage }
accept="image/*"
type="image"
/>
</Fragment>
);
Expand Down
16 changes: 0 additions & 16 deletions core-blocks/image/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,6 @@
}
/*!rtl:end:ignore*/

.wp-block-audio__upload-button.components-button,
.wp-block-image__upload-button.components-button,
.wp-block-video__upload-button.components-button {
margin-right: 5px;

.dashicon {
vertical-align: middle;
margin-bottom: 3px;
}


&:hover {
color: $dark-gray-800;
}
}

.editor-block-list__block[data-type="core/image"][data-align="center"] {
.wp-block-image {
margin-left: auto;
Expand Down
Loading