Skip to content

Commit

Permalink
Add an edit button to embed blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
notnownikki committed Jul 24, 2018
1 parent a1bc317 commit c1a0503
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions core-blocks/embed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import classnames from 'classnames';
*/
import { __, sprintf } from '@wordpress/i18n';
import { Component, Fragment, renderToString } from '@wordpress/element';
import { Button, Placeholder, Spinner, SandBox } from '@wordpress/components';
import { Button, Placeholder, Spinner, SandBox, IconButton } from '@wordpress/components';
import { createBlock } from '@wordpress/blocks';
import {
RichText,
} from '@wordpress/editor';
import { RichText, BlockControls } from '@wordpress/editor';
import apiFetch from '@wordpress/api-fetch';

/**
Expand Down Expand Up @@ -84,6 +82,7 @@ function getEmbedBlockSettings( { title, description, icon, category = 'embed',
super( ...arguments );

this.doServerSideRender = this.doServerSideRender.bind( this );
this.switchBackToURLInput = this.switchBackToURLInput.bind( this );

this.state = {
html: '',
Expand Down Expand Up @@ -173,10 +172,24 @@ function getEmbedBlockSettings( { title, description, icon, category = 'embed',
);
}

switchBackToURLInput() {
this.setState( { html: undefined } );
}

render() {
const { html, type, error, fetching } = this.state;
const { url, caption } = this.props.attributes;
const { setAttributes, isSelected, className } = this.props;
const controls = (
<BlockControls>
{ ( html && <IconButton
className="components-toolbar__control"
label={ __( 'Edit URL' ) }
icon="edit"
onClick={ this.switchBackToURLInput }
/> ) }
</BlockControls>
);

if ( fetching ) {
return (
Expand Down Expand Up @@ -233,6 +246,7 @@ function getEmbedBlockSettings( { title, description, icon, category = 'embed',

return (
<Fragment>
{ controls }
<figure className={ classnames( className, 'wp-block-embed', { 'is-video': 'video' === type } ) }>
{ ( cannotPreview ) ? (
<Placeholder icon={ icon } label={ __( 'Embed URL' ) }>
Expand Down

0 comments on commit c1a0503

Please sign in to comment.