From c1a050373f8b9b7a276c0cffbd4c36d2bf32ac75 Mon Sep 17 00:00:00 2001 From: Nicola Heald Date: Fri, 20 Jul 2018 15:05:02 +0100 Subject: [PATCH] Add an edit button to embed blocks --- core-blocks/embed/index.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/core-blocks/embed/index.js b/core-blocks/embed/index.js index 529644ee90dea..6703a7db741db 100644 --- a/core-blocks/embed/index.js +++ b/core-blocks/embed/index.js @@ -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'; /** @@ -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: '', @@ -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 = ( + + { ( html && ) } + + ); if ( fetching ) { return ( @@ -233,6 +246,7 @@ function getEmbedBlockSettings( { title, description, icon, category = 'embed', return ( + { controls }
{ ( cannotPreview ) ? (