Skip to content
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

Add Transformation from Separator to Spacer #66230

Merged
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;
Loading