File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed
example/src/blocks/inner-blocks-limit Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "name" : " example/inner-block-limit" ,
3+ "apiVersion" : 3 ,
4+ "title" : " Inner Block Limit - Example" ,
5+ "description" : " Example Block to show the usage of the useRenderAppenderWithLimit hook" ,
6+ "icon" : " smiley" ,
7+ "category" : " common" ,
8+ "example" : {},
9+ "supports" : {
10+ "html" : false
11+ },
12+ "attributes" : {},
13+ "allowedBlocks" : [
14+ " example/hello-world"
15+ ],
16+ "editorScript" : " file:./index.ts"
17+ }
Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+ import { useBlockProps , useInnerBlocksProps } from '@wordpress/block-editor' ;
3+ import { useRenderAppenderWithLimit } from '@10up/block-components' ;
4+
5+ const TEMPLATE = [
6+ [
7+ 'example/hello-world' ,
8+ { } ,
9+ ] ,
10+ ] ;
11+
12+ export const BlockEdit = ( ) => {
13+ const renderAppender = useRenderAppenderWithLimit ( 4 ) ;
14+ const blockProps = useBlockProps ( ) ;
15+
16+ const innerBlocksProps = useInnerBlocksProps (
17+ { } ,
18+ {
19+ template : TEMPLATE ,
20+ renderAppender,
21+ } ,
22+ ) ;
23+
24+ return (
25+ < div { ...blockProps } >
26+ < div { ...innerBlocksProps } />
27+ </ div >
28+ ) ;
29+ } ;
Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+ import { registerBlockType } from '@wordpress/blocks' ;
3+ import { InnerBlocks } from '@wordpress/block-editor' ;
4+ import { __ } from '@wordpress/i18n' ;
5+
6+ import { BlockEdit } from './edit' ;
7+ import metadata from './block.json' ;
8+
9+ registerBlockType ( metadata , {
10+ edit : BlockEdit ,
11+ save : ( ) => < InnerBlocks . Content />
12+ } ) ;
You can’t perform that action at this time.
0 commit comments