Skip to content

Instantly share code, notes, and snippets.

@imranhsayed
Created April 4, 2019 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imranhsayed/974a0dbd37ce30adc5e9de4298e3ec35 to your computer and use it in GitHub Desktop.
Save imranhsayed/974a0dbd37ce30adc5e9de4298e3ec35 to your computer and use it in GitHub Desktop.
RichText Component
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