Skip to content

Commit

Permalink
Blocks: Port Audio block to use align supports
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Dec 18, 2017
1 parent 9a0ffe1 commit 7e9f5dd
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions blocks/library/audio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { registerBlockType } from '../../api';
import MediaUploadButton from '../../media-upload-button';
import Editable from '../../editable';
import BlockControls from '../../block-controls';
import BlockAlignmentToolbar from '../../block-alignment-toolbar';
import InspectorControls from '../../inspector-controls';
import BlockDescription from '../../block-description';

Expand All @@ -35,21 +34,15 @@ registerBlockType( 'core/audio', {
selector: 'audio',
attribute: 'src',
},
align: {
type: 'string',
},
caption: {
type: 'array',
source: 'children',
selector: 'figcaption',
},
},

getEditWrapperProps( attributes ) {
const { align } = attributes;
if ( 'left' === align || 'right' === align || 'wide' === align || 'full' === align ) {
return { 'data-align': align };
}
supports: {
align: true,
},

edit: class extends Component {
Expand All @@ -64,10 +57,9 @@ registerBlockType( 'core/audio', {
};
}
render() {
const { align, caption } = this.props.attributes;
const { caption } = this.props.attributes;
const { setAttributes, focus, setFocus } = this.props;
const { editing, className, src } = this.state;
const updateAlignment = ( nextAlign ) => setAttributes( { align: nextAlign } );
const switchToEditing = () => {
this.setState( { editing: true } );
};
Expand All @@ -90,10 +82,6 @@ registerBlockType( 'core/audio', {
};
const controls = focus && [
<BlockControls key="controls">
<BlockAlignmentToolbar
value={ align }
onChange={ updateAlignment }
/>
<Toolbar>
<Button
className="components-icon-button components-toolbar__control"
Expand Down Expand Up @@ -171,9 +159,9 @@ registerBlockType( 'core/audio', {
},

save( { attributes } ) {
const { align, src, caption } = attributes;
const { src, caption } = attributes;
return (
<figure className={ align ? `align${ align }` : null }>
<figure>
<audio controls="controls" src={ src } />
{ caption && caption.length > 0 && <figcaption>{ caption }</figcaption> }
</figure>
Expand Down

0 comments on commit 7e9f5dd

Please sign in to comment.