Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quote v2: add align feature to have feature parity with v1 #39876

Merged
merged 1 commit into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions packages/block-library/src/quote/v2/edit.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
/**
* External dependencies
*/
import classNames from 'classnames';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import {
AlignmentControl,
BlockControls,
RichText,
useBlockProps,
useInnerBlocksProps,
Expand Down Expand Up @@ -66,8 +73,9 @@ export default function QuoteEdit( {
isSelected,
insertBlocksAfter,
clientId,
className,
} ) {
const { citation } = attributes;
const { citation, align } = attributes;

useMigrateOnLoad( attributes, clientId );

Expand All @@ -76,14 +84,26 @@ export default function QuoteEdit( {
);
const hasSelection = isSelected || isAncestorOfSelectedBlock;

const blockProps = useBlockProps();
const blockProps = useBlockProps( {
className: classNames( className, {
[ `has-text-align-${ align }` ]: align,
} ),
} );
const innerBlocksProps = useInnerBlocksProps( blockProps, {
template: TEMPLATE,
templateInsertUpdatesSelection: true,
} );

return (
<>
<BlockControls group="block">
<AlignmentControl
value={ align }
onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
} }
/>
</BlockControls>
<BlockQuotation { ...innerBlocksProps }>
{ innerBlocksProps.children }
{ ( ! RichText.isEmpty( citation ) || hasSelection ) && (
Expand Down
13 changes: 11 additions & 2 deletions packages/block-library/src/quote/v2/save.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
/**
* External dependencies
*/
import classNames from 'classnames';

/**
* WordPress dependencies
*/
import { InnerBlocks, RichText, useBlockProps } from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { citation } = attributes;
const blockProps = useBlockProps.save();
const { align, citation } = attributes;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's so bad that this attribute is called "align" instead of "textAlign" as "align" is also a reserved attribute for the block alignments hook. But I guess that's probably not limited to v2 of quote and may exist in other blocks too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is a v1 attribute so I didn't want to change now that we're focused on bringing the minimum changes possible to v2.

const blockProps = useBlockProps.save( {
className: classNames( {
[ `has-text-align-${ align }` ]: align,
} ),
} );
return (
<blockquote { ...blockProps }>
<InnerBlocks.Content />
Expand Down