Created
November 21, 2019 15:47
-
-
Save ryanwelcher/dde2c52f28f6c6a2bfc958b220ed3410 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Component } = wp.element; | |
const { ServerSideRender } = wp.components; | |
const { BlockControls, InnerBlocks } = wp.blockEditor; | |
import LivePreviewButton from '../../components/live-preview-button'; | |
class EditComponent extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { preview: false } | |
} | |
render() { | |
const { attributes, clientId, name } = this.props; | |
return ( | |
<> | |
<BlockControls> | |
<LivePreviewButton | |
clientId={ clientId } | |
onChange={ preview => this.setState( { preview } ) } | |
/> | |
</BlockControls> | |
{ this.state.preview ? ( | |
<div> | |
<ServerSideRender | |
block={ name} | |
attributes={ attributes } | |
/> | |
</div> | |
) : ( | |
<> | |
<InnerBlocks/> | |
</> | |
)} | |
</> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment