Skip to content

Commit

Permalink
Add Transformation from Separator to Spacer (#66230)
Browse files Browse the repository at this point in the history
* Add a transform from the Separator block to the Spacer block

* Add a transform from the Separator block to the Spacer block

Feat #65492

* Add transformation from spacer to separator

- Remove the default height of 50px after transformation to default 100px that of Spacer
- Update the transform of blocks so that it retains anchor attribute

* Add new transformation block titles in Test

* Add new transformation block titles in Test

* Add new transformation block titles in Test and resolve linting problem

* Add new transformation block titles in Test and resolve linting problem

* Update test suite snapshot for test [mobile] to pass successfully

---------

Co-authored-by: talldan <[email protected]>
Co-authored-by: rudrakshi-gupta <[email protected]>
  • Loading branch information
3 people authored Oct 24, 2024
1 parent 0d91946 commit 5b7ac9e
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ exports[`Separator block transforms to Group block 1`] = `
<!-- /wp:separator --></div>
<!-- /wp:group -->"
`;

exports[`Separator block transforms to Spacer block 1`] = `
"<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const initialHtml = `
<!-- /wp:separator -->`;

const transformsWithInnerBlocks = [ 'Columns', 'Group' ];
const blockTransforms = [ ...transformsWithInnerBlocks ];
const blockTransforms = [ 'Spacer', ...transformsWithInnerBlocks ];

setupCoreBlocks();

Expand Down
11 changes: 11 additions & 0 deletions packages/block-library/src/separator/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ const transforms = {
},
},
],
to: [
{
type: 'block',
blocks: [ 'core/spacer' ], // Transform to Spacer.
transform: ( { anchor } ) => {
return createBlock( 'core/spacer', {
anchor: anchor || '',
} );
},
},
],
};

export default transforms;
2 changes: 2 additions & 0 deletions packages/block-library/src/spacer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import initBlock from '../utils/init-block';
import deprecated from './deprecated';
import edit from './edit';
import metadata from './block.json';
import transforms from './transforms';
import save from './save';

const { name } = metadata;
Expand All @@ -18,6 +19,7 @@ export { metadata, name };

export const settings = {
icon,
transforms,
edit,
save,
deprecated,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ exports[`Spacer block transforms to Group block 1`] = `
<!-- /wp:spacer --></div>
<!-- /wp:group -->"
`;

exports[`Spacer block transforms to Separator block 1`] = `
"<!-- wp:separator -->
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<!-- /wp:separator -->"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const initialHtml = `
<!-- /wp:spacer -->`;

const transformsWithInnerBlocks = [ 'Columns', 'Group' ];
const blockTransforms = [ ...transformsWithInnerBlocks ];
const blockTransforms = [ 'Separator', ...transformsWithInnerBlocks ];

setupCoreBlocks();

Expand Down
20 changes: 20 additions & 0 deletions packages/block-library/src/spacer/transforms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* WordPress dependencies
*/
import { createBlock } from '@wordpress/blocks';

const transforms = {
to: [
{
type: 'block',
blocks: [ 'core/separator' ], // Transform to Separator.
transform: ( { anchor } ) => {
return createBlock( 'core/separator', {
anchor: anchor || '',
} );
},
},
],
};

export default transforms;

1 comment on commit 5b7ac9e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 5b7ac9e.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11496803755
📝 Reported issues:

Please sign in to comment.