From da1ad4f7e97039a5aba9333a8f436f8bd56a160b Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Fri, 26 Jul 2019 20:36:21 +0200 Subject: [PATCH] Block library: Refactor Quote block to use class names for text align --- .../block-library/src/quote/deprecated.js | 13 +++++++++++ packages/block-library/src/quote/edit.js | 12 +++++++++- packages/block-library/src/quote/save.js | 11 +++++++++- .../blocks/core__quote__deprecated-2.html | 6 +++++ .../blocks/core__quote__deprecated-2.json | 14 ++++++++++++ .../core__quote__deprecated-2.parsed.json | 22 +++++++++++++++++++ .../core__quote__deprecated-2.serialized.html | 3 +++ 7 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 packages/e2e-tests/fixtures/blocks/core__quote__deprecated-2.html create mode 100644 packages/e2e-tests/fixtures/blocks/core__quote__deprecated-2.json create mode 100644 packages/e2e-tests/fixtures/blocks/core__quote__deprecated-2.parsed.json create mode 100644 packages/e2e-tests/fixtures/blocks/core__quote__deprecated-2.serialized.html diff --git a/packages/block-library/src/quote/deprecated.js b/packages/block-library/src/quote/deprecated.js index 61024ff336aed..5b8637138a2ae 100644 --- a/packages/block-library/src/quote/deprecated.js +++ b/packages/block-library/src/quote/deprecated.js @@ -28,6 +28,19 @@ const blockAttributes = { }; const deprecated = [ + { + attributes: blockAttributes, + save( { attributes } ) { + const { align, value, citation } = attributes; + + return ( +
+ + { ! RichText.isEmpty( citation ) && } +
+ ); + }, + }, { attributes: { ...blockAttributes, diff --git a/packages/block-library/src/quote/edit.js b/packages/block-library/src/quote/edit.js index 079db78e86493..9210230f2ba02 100644 --- a/packages/block-library/src/quote/edit.js +++ b/packages/block-library/src/quote/edit.js @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; + /** * WordPress dependencies */ @@ -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 ( <> @@ -17,7 +23,11 @@ export default function QuoteEdit( { attributes, setAttributes, isSelected, merg } } /> - + +
{ ! RichText.isEmpty( citation ) && }
diff --git a/packages/e2e-tests/fixtures/blocks/core__quote__deprecated-2.html b/packages/e2e-tests/fixtures/blocks/core__quote__deprecated-2.html new file mode 100644 index 0000000000000..1aa27ba31ca7e --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__quote__deprecated-2.html @@ -0,0 +1,6 @@ + +
+

Testing deprecated quote block...

+ ...with a caption +
+ diff --git a/packages/e2e-tests/fixtures/blocks/core__quote__deprecated-2.json b/packages/e2e-tests/fixtures/blocks/core__quote__deprecated-2.json new file mode 100644 index 0000000000000..7270825d5ea7e --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__quote__deprecated-2.json @@ -0,0 +1,14 @@ +[ + { + "clientId": "_clientId_0", + "name": "core/quote", + "isValid": true, + "attributes": { + "value": "

Testing deprecated quote block...

", + "citation": "...with a caption", + "align": "right" + }, + "innerBlocks": [], + "originalContent": "
\n\t

Testing deprecated quote block...

\n\t...with a caption\n
" + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__quote__deprecated-2.parsed.json b/packages/e2e-tests/fixtures/blocks/core__quote__deprecated-2.parsed.json new file mode 100644 index 0000000000000..37bd661148aca --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__quote__deprecated-2.parsed.json @@ -0,0 +1,22 @@ +[ + { + "blockName": "core/quote", + "attrs": { + "align": "right" + }, + "innerBlocks": [], + "innerHTML": "\n
\n\t

Testing deprecated quote block...

\n\t...with a caption\n
\n", + "innerContent": [ + "\n
\n\t

Testing deprecated quote block...

\n\t...with a caption\n
\n" + ] + }, + { + "blockName": null, + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n", + "innerContent": [ + "\n" + ] + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__quote__deprecated-2.serialized.html b/packages/e2e-tests/fixtures/blocks/core__quote__deprecated-2.serialized.html new file mode 100644 index 0000000000000..08271ab418b33 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__quote__deprecated-2.serialized.html @@ -0,0 +1,3 @@ + +

Testing deprecated quote block...

...with a caption
+