Skip to content

Commit

Permalink
Block library: Refactor Quote block to use class names for text align (
Browse files Browse the repository at this point in the history
…#16779)

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

* Refactor CSS theme styles to use new text align classes
  • Loading branch information
gziolo committed Aug 29, 2019
1 parent e1e924c commit ce58b88
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 6 deletions.
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
8 changes: 4 additions & 4 deletions packages/block-library/src/quote/theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
font-style: normal;
}

&[style*="text-align:right"],
&[style*="text-align: right"] {
&.has-text-align-right,
&.has-text-align-right {
border-left: none;
border-right: 4px solid $black;
padding-left: 0;
padding-right: 1em;
}

&[style*="text-align:center"],
&[style*="text-align: center"] {
&.has-text-align-center,
&.has-text-align-center {
border: none;
padding-left: 0;
}
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 -->

0 comments on commit ce58b88

Please sign in to comment.