From f3fb6a6ac3f23f7e04de5f08bc02f702e5360f1c Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Thu, 28 Oct 2021 11:36:50 +0200 Subject: [PATCH 1/2] Add alignment option to post comment edit block --- .../src/post-comment-edit/block.json | 3 ++ .../src/post-comment-edit/edit.js | 33 +++++++++++++++++-- .../src/post-comment-edit/index.php | 9 ++++- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/post-comment-edit/block.json b/packages/block-library/src/post-comment-edit/block.json index a838989efd98ea..b5fc5d5f92e88e 100644 --- a/packages/block-library/src/post-comment-edit/block.json +++ b/packages/block-library/src/post-comment-edit/block.json @@ -11,6 +11,9 @@ "linkTarget": { "type": "string", "default": "_self" + }, + "textAlign": { + "type": "string" } }, "supports": { diff --git a/packages/block-library/src/post-comment-edit/edit.js b/packages/block-library/src/post-comment-edit/edit.js index 320507a373378a..dc917216777266 100644 --- a/packages/block-library/src/post-comment-edit/edit.js +++ b/packages/block-library/src/post-comment-edit/edit.js @@ -1,15 +1,41 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; + /** * WordPress dependencies */ -import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; +import { + AlignmentControl, + BlockControls, + InspectorControls, + useBlockProps, +} from '@wordpress/block-editor'; import { PanelBody, ToggleControl } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; export default function Edit( { - attributes: { className, linkTarget }, + attributes: { className, linkTarget, textAlign }, setAttributes, } ) { - const blockProps = useBlockProps( { className } ); + const blockProps = useBlockProps( { + className: classnames( { + [ `has-text-align-${ textAlign }` ]: textAlign, + className, + } ), + } ); + + const blockControls = ( + + + setAttributes( { textAlign: newAlign } ) + } + /> + + ); const inspectorControls = ( @@ -28,6 +54,7 @@ export default function Edit( { return ( <> + { blockControls } { inspectorControls }
$classes ) ); + return sprintf( '
%4$s
', - get_block_wrapper_attributes(), + $wrapper_attributes, esc_url( $edit_comment_link ), $link_atts, esc_html__( 'Edit' ) From 4961c83451dca5977e06213f154898ba81b35c50 Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Thu, 28 Oct 2021 12:27:06 +0200 Subject: [PATCH 2/2] Remove not needed classname --- packages/block-library/src/post-comment-edit/edit.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/block-library/src/post-comment-edit/edit.js b/packages/block-library/src/post-comment-edit/edit.js index dc917216777266..3f45948bc5c060 100644 --- a/packages/block-library/src/post-comment-edit/edit.js +++ b/packages/block-library/src/post-comment-edit/edit.js @@ -16,13 +16,12 @@ import { PanelBody, ToggleControl } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; export default function Edit( { - attributes: { className, linkTarget, textAlign }, + attributes: { linkTarget, textAlign }, setAttributes, } ) { const blockProps = useBlockProps( { className: classnames( { [ `has-text-align-${ textAlign }` ]: textAlign, - className, } ), } );