-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Block library: Refactor Heading block to use class names for text align #16035
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c0ffdbf
Block library: Refactor Heading block to use class names for text align
gziolo 3aee04b
Fix Heading icon in the collapsed mode
gziolo 19d3f9b
Add missing label for the level dropdown menu
gziolo 02020b2
Block library: Revert attribute name change for text align
gziolo 2f0a325
Remove code which moves text alignment control to the block toolbar
gziolo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import classnames from 'classnames'; | ||
|
|
||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { | ||
| getColorClassName, | ||
| RichText, | ||
| } from '@wordpress/block-editor'; | ||
|
|
||
| const blockSupports = { | ||
| className: false, | ||
| anchor: true, | ||
| }; | ||
|
|
||
| const blockAttributes = { | ||
| align: { | ||
| type: 'string', | ||
| }, | ||
| content: { | ||
| type: 'string', | ||
| source: 'html', | ||
| selector: 'h1,h2,h3,h4,h5,h6', | ||
| default: '', | ||
| }, | ||
| level: { | ||
| type: 'number', | ||
| default: 2, | ||
| }, | ||
| placeholder: { | ||
| type: 'string', | ||
| }, | ||
| textColor: { | ||
| type: 'string', | ||
| }, | ||
| customTextColor: { | ||
| type: 'string', | ||
| }, | ||
| }; | ||
|
|
||
| const deprecated = [ | ||
| { | ||
| supports: blockSupports, | ||
| attributes: blockAttributes, | ||
| save( { attributes } ) { | ||
| const { | ||
| align, | ||
| level, | ||
| content, | ||
| textColor, | ||
| customTextColor, | ||
| } = attributes; | ||
| const tagName = 'h' + level; | ||
|
|
||
| const textClass = getColorClassName( 'color', textColor ); | ||
|
|
||
| const className = classnames( { | ||
| [ textClass ]: textClass, | ||
| } ); | ||
|
|
||
| return ( | ||
| <RichText.Content | ||
| className={ className ? className : undefined } | ||
| tagName={ tagName } | ||
| style={ { | ||
| textAlign: align, | ||
| color: textClass ? undefined : customTextColor, | ||
| } } | ||
| value={ content } | ||
| /> | ||
| ); | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
| export default deprecated; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/e2e-tests/fixtures/blocks/core__heading__deprecated-1.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <!-- wp:core/heading {"align":"right","level":3} --> | ||
| <h3 style="text-align:right">A picture is worth a thousand words, or so the saying goes</h3> | ||
| <!-- /wp:core/heading --> |
14 changes: 14 additions & 0 deletions
14
packages/e2e-tests/fixtures/blocks/core__heading__deprecated-1.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [ | ||
| { | ||
| "clientId": "_clientId_0", | ||
| "name": "core/heading", | ||
| "isValid": true, | ||
| "attributes": { | ||
| "align": "right", | ||
| "content": "A picture is worth a thousand words, or so the saying goes", | ||
| "level": 3 | ||
| }, | ||
| "innerBlocks": [], | ||
| "originalContent": "<h3 style=\"text-align:right\">A picture is worth a thousand words, or so the saying goes</h3>" | ||
| } | ||
| ] |
23 changes: 23 additions & 0 deletions
23
packages/e2e-tests/fixtures/blocks/core__heading__deprecated-1.parsed.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| [ | ||
| { | ||
| "blockName": "core/heading", | ||
| "attrs": { | ||
| "align": "right", | ||
| "level": 3 | ||
| }, | ||
| "innerBlocks": [], | ||
| "innerHTML": "\n<h3 style=\"text-align:right\">A picture is worth a thousand words, or so the saying goes</h3>\n", | ||
| "innerContent": [ | ||
| "\n<h3 style=\"text-align:right\">A picture is worth a thousand words, or so the saying goes</h3>\n" | ||
| ] | ||
| }, | ||
| { | ||
| "blockName": null, | ||
| "attrs": {}, | ||
| "innerBlocks": [], | ||
| "innerHTML": "\n", | ||
| "innerContent": [ | ||
| "\n" | ||
| ] | ||
| } | ||
| ] |
3 changes: 3 additions & 0 deletions
3
packages/e2e-tests/fixtures/blocks/core__heading__deprecated-1.serialized.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <!-- wp:heading {"align":"right","level":3} --> | ||
| <h3 class="has-text-align-right">A picture is worth a thousand words, or so the saying goes</h3> | ||
| <!-- /wp:heading --> |
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
packages/e2e-tests/fixtures/blocks/core__heading__h2-em.serialized.html
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <!-- wp:core/heading {"level":4} --> | ||
| <h4>The <em>Inserter</em> Tool</h4> | ||
| <!-- /wp:core/heading --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
...s/blocks/core__heading__h2-em.parsed.json → ...s/blocks/core__heading__h4-em.parsed.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/e2e-tests/fixtures/blocks/core__heading__h4-em.serialized.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <!-- wp:heading {"level":4} --> | ||
| <h4>The <em>Inserter</em> Tool</h4> | ||
| <!-- /wp:heading --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.