Created
December 17, 2019 11:52
-
-
Save mwidmann/02a5a67db9de2b668df97d4126bdb687 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
/** | |
* WordPress dependencies | |
*/ | |
import { __ } from '@wordpress/i18n'; | |
import { registerBlockType } from '@wordpress/blocks'; | |
import { RichText } from '@wordpress/blockEditor'; | |
registerBlockType( 'russmedia/nordstern-lead', { | |
title: __( 'Lead', 'russmedia-nordstern-gutenberg' ), | |
icon: 'editor-table', | |
category: 'common', | |
keywords: [ __( 'Lead', 'russmedia-nordstern-gutenberg' ), 'Russmedia' ], | |
attributes: { | |
content: { | |
source: 'text', | |
selector: '.lead', | |
}, | |
}, | |
edit: ( props ) => { | |
const { content } = props.attributes; | |
return ( | |
<div className={ props.className }> | |
<RichText | |
tagName="h4" | |
multiline={ false } | |
className="lead" | |
placeholder={ __( 'Lead', 'russmedia-nordstern-gutenberg' ) } | |
formattingControls={ [] } | |
unstableOnSplit={ ( before, after, ...blocks ) => { | |
/* does nothing... */ | |
} } | |
value={ content } | |
onChange={ ( newContent ) => { | |
const newObject = Object.assign( {}, { content: newContent } ); | |
props.setAttributes( newObject ); | |
} } | |
/> | |
</div> | |
); | |
}, | |
save: ( props ) => { | |
const { content } = props.attributes; | |
if ( content ) { | |
return ( | |
<h4 className="wp-block-russmedia-nordstern-lead lead">{ content }</h4> | |
); | |
} | |
return null; | |
}, | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment