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 Verse block to use class names for text align #16777

Merged
merged 1 commit into from
Jul 31, 2019
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
5 changes: 5 additions & 0 deletions packages/block-library/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Master (unreleased)

### Enhancements

- Heading block uses `has-text-align-*` class names rather than inline style for text alignment.
draganescu marked this conversation as resolved.
Show resolved Hide resolved
- Verse block uses `has-text-align-*` class names rather than inline style for text alignment.

### Bug Fixes

- Fixed insertion of columns in the table block, which now inserts columns for all table sections ([#16410](https://github.com/WordPress/gutenberg/pull/16410))
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@
}

.has-text-align-left {
/*rtl:ignore*/
text-align: left;
}

.has-text-align-right {
/*rtl:ignore*/
text-align: right;
}

Expand Down
35 changes: 35 additions & 0 deletions packages/block-library/src/verse/deprecated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';

const blockAttributes = {
content: {
type: 'string',
source: 'html',
selector: 'pre',
default: '',
},
textAlign: {
type: 'string',
},
};

const deprecated = [
{
attributes: blockAttributes,
save( { attributes } ) {
const { textAlign, content } = attributes;

return (
<RichText.Content
tagName="pre"
style={ { textAlign } }
value={ content }
/>
);
},
},
];

export default deprecated;
9 changes: 8 additions & 1 deletion packages/block-library/src/verse/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 Down Expand Up @@ -29,9 +34,11 @@ export default function VerseEdit( { attributes, setAttributes, className, merge
content: nextContent,
} );
} }
style={ { textAlign } }
placeholder={ __( 'Write…' ) }
wrapperClassName={ className }
className={ classnames( {
[ `has-text-align-${ textAlign }` ]: textAlign,
} ) }
onMerge={ mergeBlocks }
/>
</>
Expand Down
6 changes: 4 additions & 2 deletions packages/block-library/src/verse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import deprecated from './deprecated';
import edit from './edit';
import icon from './icon';
import metadata from './block.json';
Expand All @@ -22,11 +23,12 @@ export const settings = {
icon,
keywords: [ __( 'poetry' ) ],
transforms,
edit,
save,
deprecated,
merge( attributes, attributesToMerge ) {
return {
content: attributes.content + attributesToMerge.content,
};
},
edit,
save,
};
11 changes: 10 additions & 1 deletion packages/block-library/src/verse/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,10 +11,14 @@ import { RichText } from '@wordpress/block-editor';
export default function save( { attributes } ) {
const { textAlign, content } = attributes;

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

return (
<RichText.Content
tagName="pre"
style={ { textAlign } }
className={ className }
value={ content }
/>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:verse {"textAlign":"left"} -->
<pre style="text-align:left" class="wp-block-verse">A <em>verse</em>…<br>And more!</pre>
<!-- /wp:core/verse -->
13 changes: 13 additions & 0 deletions packages/e2e-tests/fixtures/blocks/core__verse__deprecated.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"clientId": "_clientId_0",
"name": "core/verse",
"isValid": true,
"attributes": {
"content": "A <em>verse</em>…<br>And more!",
"textAlign": "left"
},
"innerBlocks": [],
"originalContent": "<pre style=\"text-align:left\" class=\"wp-block-verse\">A <em>verse</em>…<br>And more!</pre>"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"blockName": "core/verse",
"attrs": {
"textAlign": "left"
},
"innerBlocks": [],
"innerHTML": "\n<pre style=\"text-align:left\" class=\"wp-block-verse\">A <em>verse</em>…<br>And more!</pre>\n",
"innerContent": [
"\n<pre style=\"text-align:left\" class=\"wp-block-verse\">A <em>verse</em>…<br>And more!</pre>\n"
]
},
{
"blockName": null,
"attrs": {},
"innerBlocks": [],
"innerHTML": "\n",
"innerContent": [
"\n"
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:verse {"textAlign":"left"} -->
<pre class="wp-block-verse has-text-align-left">A <em>verse</em>…<br>And more!</pre>
<!-- /wp:verse -->