Skip to content

Commit

Permalink
Enhancement: Add text alignment options to verse block toolbar (#6700)
Browse files Browse the repository at this point in the history
* Add text alignment options to verse block toolbar

* Changed attribute align to textAlign

Props @nfmohit-wpmudev
  • Loading branch information
Nahid F. Mohit authored and Tammie Lister committed May 23, 2018
1 parent 270ca2a commit f145991
Showing 1 changed file with 37 additions and 15 deletions.
52 changes: 37 additions & 15 deletions core-blocks/verse/index.js
Expand Up @@ -2,8 +2,13 @@
* WordPress
*/
import { __ } from '@wordpress/i18n';
import { Fragment } from '@wordpress/element';
import { createBlock } from '@wordpress/blocks';
import { RichText } from '@wordpress/editor';
import {
RichText,
BlockControls,
AlignmentToolbar,
} from '@wordpress/editor';

/**
* Internal dependencies
Expand All @@ -29,6 +34,9 @@ export const settings = {
source: 'children',
selector: 'pre',
},
textAlign: {
type: 'string',
},
},

transforms: {
Expand All @@ -51,30 +59,44 @@ export const settings = {
},

edit( { attributes, setAttributes, className } ) {
const { content } = attributes;
const { textAlign, content } = attributes;

return (
<RichText
tagName="pre"
value={ content }
onChange={ ( nextContent ) => {
setAttributes( {
content: nextContent,
} );
} }
placeholder={ __( 'Write…' ) }
wrapperClassName={ className }
formattingControls={ [ 'bold', 'italic', 'strikethrough' ] }
/>
<Fragment>
<BlockControls>
<AlignmentToolbar
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
} }
/>
</BlockControls>
<RichText
tagName="pre"
value={ content }
onChange={ ( nextContent ) => {
setAttributes( {
content: nextContent,
} );
} }
style={ { textAlign: textAlign } }
placeholder={ __( 'Write…' ) }
wrapperClassName={ className }
formattingControls={ [ 'bold', 'italic', 'strikethrough' ] }
/>
</Fragment>
);
},

save( { attributes, className } ) {
const { textAlign, content } = attributes;

return (
<RichText.Content
tagName="pre"
className={ className }
value={ attributes.content }
style={ { textAlign: textAlign } }
value={ content }
/>
);
},
Expand Down

0 comments on commit f145991

Please sign in to comment.