@wordpress/block-library
Version:
Block library for the WordPress editor.
63 lines (59 loc) • 1.17 kB
JavaScript
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import {
RichText,
BlockControls,
AlignmentToolbar,
useBlockProps,
} from '@wordpress/block-editor';
export default function VerseEdit( {
attributes,
setAttributes,
mergeBlocks,
onRemove,
style,
} ) {
const { textAlign, content } = attributes;
const blockProps = useBlockProps( {
className: classnames( {
[ `has-text-align-${ textAlign }` ]: textAlign,
} ),
style,
} );
return (
<>
<BlockControls>
<AlignmentToolbar
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
} }
/>
</BlockControls>
<RichText
tagName="pre"
identifier="content"
preserveWhiteSpace
value={ content }
onChange={ ( nextContent ) => {
setAttributes( {
content: nextContent,
} );
} }
aria-label={ __( 'Verse text' ) }
placeholder={ __( 'Write verse…' ) }
onRemove={ onRemove }
onMerge={ mergeBlocks }
textAlign={ textAlign }
{ ...blockProps }
__unstablePastePlainText
/>
</>
);
}