Skip to content

Commit

Permalink
Add/transform button to buttons (#20063)
Browse files Browse the repository at this point in the history
* Implements transform on buttons

* DEV: Makes buttons transform multi block

* Improves variable names

* Adds some comments & imporoves code readability
  • Loading branch information
Ringish authored Feb 7, 2020
1 parent fab9e02 commit 8e93c30
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
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;

0 comments on commit 8e93c30

Please sign in to comment.