Created
April 4, 2019 19:05
-
-
Save imranhsayed/974a0dbd37ce30adc5e9de4298e3ec35 to your computer and use it in GitHub Desktop.
RichText Component
This file contains 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 { registerBlockType } = wp.blocks; | |
const { RichText } = wp.editor; | |
const result = registerBlockType( 'myguten-block/test-block', { | |
title: 'Basic Example', | |
icon: 'smiley', | |
category: 'layout', | |
attributes: { | |
content: { | |
type: 'array', | |
source: 'children', | |
selector: 'p', | |
}, | |
}, | |
edit: ( props ) => { | |
console.log( props ); | |
const { attributes: { content }, setAttributes, className } = props; | |
const onChangeContent = ( newContent ) => { | |
setAttributes( { content: newContent } ); | |
}; | |
return ( | |
<RichText | |
tagName="p" | |
className={ className } | |
onChange={ onChangeContent } | |
value={ content } | |
/> | |
); | |
}, | |
save: ( props ) => { | |
return <RichText.Content tagName="p" value={ props.attributes.content } />; | |
}, | |
} ); | |
console.log( result ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment