@wordpress/block-library
Version:
Block library for the WordPress editor.
68 lines (64 loc) • 1.36 kB
JavaScript
/**
* External dependencies
*/
import clsx from 'clsx';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import {
RichText,
BlockControls,
AlignmentToolbar,
useBlockProps,
} from '@wordpress/block-editor';
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
export default function VerseEdit( {
attributes,
setAttributes,
mergeBlocks,
onRemove,
insertBlocksAfter,
style,
} ) {
const { textAlign, content } = attributes;
const blockProps = useBlockProps( {
className: clsx( {
[ `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
__unstableOnSplitAtDoubleLineEnd={ () =>
insertBlocksAfter( createBlock( getDefaultBlockName() ) )
}
/>
</>
);
}