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

Block library: Refactor Quote block to use class names for text align #16779

Merged
merged 2 commits into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Block library: Refactor Quote block to use class names for text align
  • Loading branch information
gziolo committed Aug 8, 2019
commit 569f09f7d3d37c34d8a1123e2c8e00bdf1238d77
13 changes: 13 additions & 0 deletions packages/block-library/src/quote/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ const blockAttributes = {
};

const deprecated = [
{
attributes: blockAttributes,
save( { attributes } ) {
const { align, value, citation } = attributes;

return (
<blockquote style={ { textAlign: align ? align : null } }>
<RichText.Content multiline value={ value } />
{ ! RichText.isEmpty( citation ) && <RichText.Content tagName="cite" value={ citation } /> }
</blockquote>
);
},
},
{
attributes: {
...blockAttributes,
Expand Down
12 changes: 11 additions & 1 deletion packages/block-library/src/quote/edit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
Expand All @@ -7,6 +12,7 @@ import { BlockQuotation } from '@wordpress/components';

export default function QuoteEdit( { attributes, setAttributes, isSelected, mergeBlocks, onReplace, className } ) {
const { align, value, citation } = attributes;

return (
<>
<BlockControls>
Expand All @@ -17,7 +23,11 @@ export default function QuoteEdit( { attributes, setAttributes, isSelected, merg
} }
/>
</BlockControls>
<BlockQuotation className={ className } style={ { textAlign: align } }>
<BlockQuotation
className={ classnames( className, {
[ `has-text-align-${ align }` ]: align,
} ) }
>
<RichText
identifier="value"
multiline
Expand Down
11 changes: 10 additions & 1 deletion packages/block-library/src/quote/save.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
Expand All @@ -6,8 +11,12 @@ import { RichText } from '@wordpress/block-editor';
export default function save( { attributes } ) {
const { align, value, citation } = attributes;

const className = classnames( {
[ `has-text-align-${ align }` ]: align,
} );

return (
<blockquote style={ { textAlign: align ? align : null } }>
<blockquote className={ className }>
<RichText.Content multiline value={ value } />
{ ! RichText.isEmpty( citation ) && <RichText.Content tagName="cite" value={ citation } /> }
</blockquote>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!-- wp:core/quote {"align":"right"} -->
<blockquote style="text-align:right" class="wp-block-quote">
<p>Testing deprecated quote block...</p>
<cite>...with a caption</cite>
</blockquote>
<!-- /wp:core/quote -->
14 changes: 14 additions & 0 deletions packages/e2e-tests/fixtures/blocks/core__quote__deprecated-2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"clientId": "_clientId_0",
"name": "core/quote",
"isValid": true,
"attributes": {
"value": "<p>Testing deprecated quote block...</p>",
"citation": "...with a caption",
"align": "right"
},
"innerBlocks": [],
"originalContent": "<blockquote style=\"text-align:right\" class=\"wp-block-quote\">\n\t<p>Testing deprecated quote block...</p>\n\t<cite>...with a caption</cite>\n</blockquote>"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"blockName": "core/quote",
"attrs": {
"align": "right"
},
"innerBlocks": [],
"innerHTML": "\n<blockquote style=\"text-align:right\" class=\"wp-block-quote\">\n\t<p>Testing deprecated quote block...</p>\n\t<cite>...with a caption</cite>\n</blockquote>\n",
"innerContent": [
"\n<blockquote style=\"text-align:right\" class=\"wp-block-quote\">\n\t<p>Testing deprecated quote block...</p>\n\t<cite>...with a caption</cite>\n</blockquote>\n"
]
},
{
"blockName": null,
"attrs": {},
"innerBlocks": [],
"innerHTML": "\n",
"innerContent": [
"\n"
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:quote {"align":"right"} -->
<blockquote class="wp-block-quote has-text-align-right"><p>Testing deprecated quote block...</p><cite>...with a caption</cite></blockquote>
<!-- /wp:quote -->