-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Block library: Refactor Heading block to use class names for text ali…
…gn (#16035) * Block library: Refactor Heading block to use class names for text align * Fix Heading icon in the collapsed mode * Add missing label for the level dropdown menu * Block library: Revert attribute name change for text align * Remove code which moves text alignment control to the block toolbar
- Loading branch information
Showing
17 changed files
with
156 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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