Skip to content

Commit

Permalink
Address deprecation issues from Buttons flex layout PR. (#36192)
Browse files Browse the repository at this point in the history
* Address deprecation issues from Buttons flex layout PR.

* Simplify migration logic.

* update fixtures

Co-authored-by: ntsekouras <[email protected]>
  • Loading branch information
tellthemachines and ntsekouras authored Nov 10, 2021
1 parent 3606ae5 commit 216df9e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 28 deletions.
19 changes: 11 additions & 8 deletions packages/block-library/src/buttons/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ const migrateWithLayout = ( attributes ) => {
return attributes;
}

const { contentJustification, orientation } = attributes;

const updatedAttributes = {
...attributes,
};
const {
contentJustification,
orientation,
...updatedAttributes
} = attributes;

if ( contentJustification || orientation ) {
Object.assign( updatedAttributes, {
layout: {
type: 'flex',
justifyContent: contentJustification || 'left',
orientation: orientation || 'horizontal',
...( contentJustification && {
justifyContent: contentJustification,
} ),
...( orientation && { orientation } ),
},
} );
}
Expand Down Expand Up @@ -57,7 +59,8 @@ const deprecated = [
},
},
},
isEligible: ( { layout } ) => ! layout,
isEligible: ( { contentJustification, orientation } ) =>
!! contentJustification || !! orientation,
migrate: migrateWithLayout,
save( { attributes: { contentJustification, orientation } } ) {
return (
Expand Down
5 changes: 0 additions & 5 deletions packages/block-library/src/buttons/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* WordPress dependencies
*/
import {
BlockControls,
useBlockProps,
useInnerBlocksProps,
store as blockEditorStore,
Expand Down Expand Up @@ -39,10 +38,6 @@ function ButtonsEdit( { attributes: { layout = {} } } ) {

return (
<>
<BlockControls
group="block"
__experimentalShareWithChildBlocks
></BlockControls>
<div { ...innerBlocksProps } />
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
"name": "core/buttons",
"isValid": true,
"attributes": {
"contentJustification": "center",
"layout": {
"type": "flex",
"justifyContent": "center",
"orientation": "horizontal"
"justifyContent": "center"
}
},
"innerBlocks": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- wp:buttons {"layout":{"type":"flex","justifyContent":"center","orientation":"horizontal"}} -->
<!-- wp:buttons {"layout":{"type":"flex","justifyContent":"center"}} -->
<div class="wp-block-buttons"><!-- wp:button -->
<div class="wp-block-button"><a class="wp-block-button__link">My button 1</a></div>
<!-- /wp:button -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
"name": "core/buttons",
"isValid": true,
"attributes": {
"contentJustification": "center",
"orientation": "horizontal",
"align": "wide",
"layout": {
"type": "flex",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@
"clientId": "_clientId_0",
"name": "core/buttons",
"isValid": true,
"attributes": {
"orientation": "horizontal",
"layout": {
"type": "flex",
"justifyContent": "left",
"orientation": "horizontal"
}
},
"attributes": {},
"innerBlocks": [
{
"clientId": "_clientId_0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- wp:buttons {"layout":{"type":"flex","justifyContent":"left","orientation":"horizontal"}} -->
<!-- wp:buttons -->
<div class="wp-block-buttons"><!-- wp:button -->
<div class="wp-block-button"><a class="wp-block-button__link">My button 1</a></div>
<!-- /wp:button -->
Expand Down

0 comments on commit 216df9e

Please sign in to comment.