-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Query block setup with block patterns integration (#28891)
* first stab * first iterations from design Keyboard navigation, style changes, refactor LayoutStep, create `usePostTypes` util hook * remove duplicate imports from rebase * design iteration part 2 + keyboard navigation * Matching block patterns API v1 * change API * move and change block patterns * Polish * __experimentalGetScopedBlockPatterns doc and tests * jsdoc usePostTypes * show start empty at the end * Improve thumbnails. * fix empty variation * Polish the labels. Co-authored-by: jasmussen <[email protected]>
- Loading branch information
1 parent
f8f2c13
commit 68caf86
Showing
12 changed files
with
669 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* Block patterns registration. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
// Initial Query block patterns. | ||
register_block_pattern( | ||
'query/large-posts', | ||
array( | ||
'title' => __( 'Large', 'gutenberg' ), | ||
'scope' => array( | ||
'inserter' => false, | ||
'block' => array( 'core/query' ), | ||
), | ||
'content' => '<!-- wp:post-title {"isLink":true} /--> | ||
<!-- wp:post-featured-image {"isLink":true,"align":"wide"} /--> | ||
<!-- wp:post-excerpt /--> | ||
<!-- wp:separator --> | ||
<hr class="wp-block-separator"/> | ||
<!-- /wp:separator --> | ||
<!-- wp:post-date /-->', | ||
) | ||
); | ||
|
||
register_block_pattern( | ||
'query/medium-posts', | ||
array( | ||
'title' => __( 'Medium', 'gutenberg' ), | ||
'scope' => array( | ||
'inserter' => false, | ||
'block' => array( 'core/query' ), | ||
), | ||
'content' => '<!-- wp:columns {"align":"wide"} --> | ||
<div class="wp-block-columns alignwide"><!-- wp:column {"width":"66.66%"} --> | ||
<div class="wp-block-column" style="flex-basis:66.66%"><!-- wp:post-featured-image {"isLink":true} /--></div> | ||
<!-- /wp:column --> | ||
<!-- wp:column {"width":"33.33%"} --> | ||
<div class="wp-block-column" style="flex-basis:33.33%"><!-- wp:post-title {"isLink":true} /--> | ||
<!-- wp:post-excerpt /--></div> | ||
<!-- /wp:column --></div> | ||
<!-- /wp:columns -->', | ||
) | ||
); | ||
|
||
register_block_pattern( | ||
'query/small-posts', | ||
array( | ||
'title' => __( 'Small', 'gutenberg' ), | ||
'scope' => array( | ||
'inserter' => false, | ||
'block' => array( 'core/query' ), | ||
), | ||
'content' => '<!-- wp:columns {"verticalAlignment":"center"} --> | ||
<div class="wp-block-columns are-vertically-aligned-center"><!-- wp:column {"verticalAlignment":"center","width":"25%"} --> | ||
<div class="wp-block-column is-vertically-aligned-center" style="flex-basis:25%"><!-- wp:post-featured-image {"isLink":true} /--></div> | ||
<!-- /wp:column --> | ||
<!-- wp:column {"verticalAlignment":"center","width":"75%"} --> | ||
<div class="wp-block-column is-vertically-aligned-center" style="flex-basis:75%"><!-- wp:post-title {"isLink":true} /--></div> | ||
<!-- /wp:column --></div> | ||
<!-- /wp:columns -->', | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/block-library/src/query/edit/block-setup/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
import { store as blocksStore } from '@wordpress/blocks'; | ||
import { Placeholder } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import LayoutSetupStep from './layout-step'; | ||
|
||
const BlockSetup = ( { | ||
blockName, | ||
useLayoutSetup, | ||
onVariationSelect = () => {}, | ||
onBlockPatternSelect = () => {}, | ||
children, | ||
} ) => { | ||
const { blockType } = useSelect( | ||
( select ) => { | ||
const { getBlockType } = select( blocksStore ); | ||
return { blockType: getBlockType( blockName ) }; | ||
}, | ||
[ blockName ] | ||
); | ||
const blockProps = useBlockProps(); | ||
return ( | ||
<div { ...blockProps }> | ||
<Placeholder | ||
icon={ blockType?.icon?.src } | ||
label={ blockType?.title } | ||
isColumnLayout | ||
> | ||
{ useLayoutSetup && ( | ||
<LayoutSetupStep | ||
blockType={ blockType } | ||
onVariationSelect={ onVariationSelect } | ||
onBlockPatternSelect={ onBlockPatternSelect } | ||
/> | ||
) } | ||
{ children } | ||
</Placeholder> | ||
</div> | ||
); | ||
}; | ||
|
||
export default BlockSetup; |
Oops, something went wrong.