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

Add an edit button to embed blocks #8084

Merged
merged 2 commits into from
Jul 26, 2018
Merged
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
24 changes: 20 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, Toolbar } 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,26 @@ 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>
<Toolbar>
{ ( html && <IconButton
className="components-toolbar__control"
label={ __( 'Edit URL' ) }
icon="edit"
onClick={ this.switchBackToURLInput }
/> ) }
</Toolbar>
</BlockControls>
);

if ( fetching ) {
return (
Expand Down Expand Up @@ -233,6 +248,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