-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Template part - add patterns placeholder selection. (#31155)
* component renders in expected states, shows expected patterns * onBlockPatternSelect override in pattern setup * use onBlockPatternSelect function to make 'choose' pattern work properly * use filterPatternsFn * refactor to separate components/files * remove unnecessary added newlines * update example patterns to now show for general case * Revert "update example patterns to now show for general case" This reverts commit 5dabb7b89987fe36a15058dea37e0e33bb0f7fe1. * move this to placeholder step and pre-creation * remove unnecessary blockName prop * use enum for pattern steps * lowercase enum props and set values as integers * remove example patterns Co-authored-by: ntsekouras <ntsekouras@outlook.com>
- Loading branch information
1 parent
d2da787
commit b8589ef
Showing
4 changed files
with
126 additions
and
63 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
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
33 changes: 33 additions & 0 deletions
33
packages/block-library/src/template-part/edit/placeholder/patterns-setup.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,33 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalBlockPatternSetup as BlockPatternSetup } from '@wordpress/block-editor'; | ||
import { useEffect } from '@wordpress/element'; | ||
|
||
export default function PatternsSetup( { area, clientId, onCreate } ) { | ||
const blockNameWithArea = area | ||
? `core/template-part/${ area }` | ||
: 'core/template-part'; | ||
|
||
return ( | ||
<BlockPatternSetup | ||
clientId={ clientId } | ||
startBlankComponent={ | ||
<StartBlankComponent onCreate={ onCreate } /> | ||
} | ||
onBlockPatternSelect={ onCreate } | ||
filterPatternsFn={ ( pattern ) => | ||
pattern?.blockTypes?.some?.( | ||
( blockType ) => blockType === blockNameWithArea | ||
) | ||
} | ||
/> | ||
); | ||
} | ||
|
||
function StartBlankComponent( { onCreate } ) { | ||
useEffect( () => { | ||
onCreate(); | ||
}, [] ); | ||
return null; | ||
} |