Skip to content

Commit cb8cdcf

Browse files
committed
Add inner block limit example block
1 parent 672d88f commit cb8cdcf

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
});

0 commit comments

Comments
 (0)