Skip to content

Commit

Permalink
Add Transformation from Separator to Spacer (WordPress#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 WordPress#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 <talldanwp@git.wordpress.org>
Co-authored-by: rudrakshi-gupta <rudrakshigupta@git.wordpress.org>
  • Loading branch information
3 people authored and karthick-murugan committed Nov 13, 2024
1 parent 4934df0 commit e0e2353
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;

0 comments on commit e0e2353

Please sign in to comment.