inspector-controls
3 years ago
BlockControls.js
3 years ago
InspectorAdvancedControls.js
2 years ago
InspectorControls.js
3 years ago
LayoutSelector.js
3 years ago
LoopRenderer.js
3 years ago
QueryLoopRenderer.js
2 years ago
utils.js
3 years ago
LayoutSelector.js
45 lines
| 1 | import { Placeholder, Button } from '@wordpress/components'; |
| 2 | import { __ } from '@wordpress/i18n'; |
| 3 | import templates from '../templates'; |
| 4 | import { createBlocksFromInnerBlocksTemplate } from '@wordpress/blocks'; |
| 5 | import { useDispatch } from '@wordpress/data'; |
| 6 | import getIcon from '../../../utils/get-icon'; |
| 7 | |
| 8 | export default ( { clientId, isDisabled } ) => { |
| 9 | if ( isDisabled ) { |
| 10 | return false; |
| 11 | } |
| 12 | |
| 13 | const { replaceInnerBlocks } = useDispatch( 'core/block-editor' ); |
| 14 | |
| 15 | return ( |
| 16 | <Placeholder |
| 17 | label={ __( 'Query Loop', 'generateblocks' ) } |
| 18 | icon={ getIcon( 'query-loop' ) } |
| 19 | instructions={ __( 'Choose a layout to start with.', 'generateblocks' ) } |
| 20 | className="gblocks-query-loop-layout-selector" |
| 21 | > |
| 22 | <div className="gblocks-query-loop-layout-selector__content"> |
| 23 | { templates.map( ( template ) => { |
| 24 | return ( |
| 25 | <Button |
| 26 | key={ `template-${ template.name }` } |
| 27 | onClick={ () => { |
| 28 | replaceInnerBlocks( |
| 29 | clientId, |
| 30 | createBlocksFromInnerBlocksTemplate( template.innerBlocks ) |
| 31 | ); |
| 32 | } } |
| 33 | > |
| 34 | { template.icon } |
| 35 | <p> |
| 36 | { template.title } |
| 37 | </p> |
| 38 | </Button> |
| 39 | ); |
| 40 | } ) } |
| 41 | </div> |
| 42 | </Placeholder> |
| 43 | ); |
| 44 | }; |
| 45 |