PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.7.2
GenerateBlocks v1.7.2
2.4.1 2.4.0 trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / extend / template-selector / index.js
generateblocks / src / extend / template-selector Last commit date
editor.scss 3 years ago index.js 3 years ago templateContext.js 3 years ago
index.js
43 lines
1 import './editor.scss';
2 import { Button, Placeholder } from '@wordpress/components';
3 import { useContext } from '@wordpress/element';
4 import TemplateContext from './templateContext';
5 import { createBlocksFromInnerBlocksTemplate } from '@wordpress/blocks';
6 import { useDispatch } from '@wordpress/data';
7
8 export default function TemplateSelector( { clientId, setAttributes } ) {
9 const { label, instructions, templates } = useContext( TemplateContext );
10 const { replaceInnerBlocks } = useDispatch( 'core/block-editor' );
11
12 return (
13 <div className="wp-block">
14 <Placeholder
15 label={ label }
16 instructions={ instructions }
17 className="gb-select-layout"
18 >
19 <div className="gb-templates-wrapper">
20 { templates && templates.map( ( template ) => (
21 <Button
22 key={ `template-${ template.id }` }
23 className="gb-template-selector-button"
24 onClick={ () => {
25 replaceInnerBlocks(
26 clientId,
27 createBlocksFromInnerBlocksTemplate( template.innerBlocks )
28 );
29
30 if ( template.attributes ) {
31 setAttributes( template.attributes );
32 }
33 } }
34 >
35 { template.icon }<span>{ template.label }</span>
36 </Button>
37 ) ) }
38 </div>
39 </Placeholder>
40 </div>
41 );
42 }
43