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/transform button to buttons #20063

Merged
merged 5 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/block-library/src/buttons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { button as icon } from '@wordpress/icons';
/**
* Internal dependencies
*/
import transforms from './transforms';
import edit from './edit';
import metadata from './block.json';
import save from './save';
Expand All @@ -26,6 +27,7 @@ export const settings = {
align: true,
alignWide: false,
},
transforms,
edit,
save,
};
32 changes: 32 additions & 0 deletions packages/block-library/src/buttons/transforms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* WordPress dependencies
*/
import { createBlock } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import { name } from './block.json';

const transforms = {
from: [
{
type: 'block',
isMultiBlock: true,
blocks: [ 'core/button' ],
transform: ( buttons ) =>
// Creates the buttons block
createBlock(
name,
{},
// Loop the selected buttons
buttons.map( ( attributes ) =>
// Create singular button in the buttons block
createBlock( 'core/button', attributes )
)
),
},
],
};

export default transforms;