Skip to content

Commit

Permalink
Allow soft returns for native Verse block
Browse files Browse the repository at this point in the history
  • Loading branch information
derekblank committed Jul 25, 2023
1 parent be21ed4 commit a11d823
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions packages/block-library/src/verse/edit.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* 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,
style,
insertBlocksAfter,
} ) {
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 }
multiline={ true }
blurOnSubmit={ true }
onMerge={ mergeBlocks }
textAlign={ textAlign }
textAlignVertical={ 'top' }
{ ...blockProps }
__unstablePastePlainText
__unstableOnSplitAtEnd={ () =>
insertBlocksAfter( createBlock( getDefaultBlockName() ) )
}
/>
</>
);
}

0 comments on commit a11d823

Please sign in to comment.