@wordpress/block-library
Version:
Block library for the WordPress editor.
39 lines (37 loc) • 945 B
JavaScript
import { __ } from '@wordpress/i18n';
import { RichText, useBlockProps } from '@wordpress/block-editor';
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
export default function CodeEdit( {
attributes,
setAttributes,
onRemove,
insertBlocksAfter,
mergeBlocks,
} ) {
const blockProps = useBlockProps();
return (
<pre { ...blockProps }>
<RichText
tagName="code"
identifier="content"
value={ attributes.content }
onChange={ ( content ) => setAttributes( { content } ) }
onRemove={ onRemove }
onMerge={ mergeBlocks }
placeholder={ __( 'Write code…' ) }
aria-label={ __( 'Code' ) }
preserveWhiteSpace
__unstablePastePlainText
__unstableOnSplitAtDoubleLineEnd={
insertBlocksAfter
? () =>
insertBlocksAfter(
createBlock( getDefaultBlockName() )
)
: undefined
}
style={ { whiteSpace: 'break-spaces' } }
/>
</pre>
);
}