Skip to content

Instantly share code, notes, and snippets.

@tlovett1
Created March 24, 2021 22:51
Show Gist options
  • Save tlovett1/7a6ffcf994f85d41821e9469c35fdea4 to your computer and use it in GitHub Desktop.
Save tlovett1/7a6ffcf994f85d41821e9469c35fdea4 to your computer and use it in GitHub Desktop.
const { registerBlockType } = wp.blocks;
const { InnerBlocks, Inserter } = wp.blockEditor;
const { Button } = wp.components;
const { Fragment } = wp.element;
const { withSelect } = wp.data;
registerBlockType('test/test-inner-container', {
title: 'Test Inner Container',
icon: 'editor-table',
parent: ['test/test-container'],
edit: withSelect((select) => {
const { hasSelectedInnerBlock, getSelectedBlockClientId } = select('core/block-editor');
return { hasSelectedInnerBlock, selectedBlock: getSelectedBlockClientId() };
})(({ className, hasSelectedInnerBlock, clientId }) => {
return (
<div className={className} style={{ border: '1px solid #555', padding: '10px' }}>
<p>{clientId}</p>
{hasSelectedInnerBlock(clientId, true) ? (
<p>
<strong>Inner block selected!</strong>
</p>
) : null}
<InnerBlocks />
</div>
);
}),
save: () => {
return null;
},
});
registerBlockType('test/test-container', {
title: 'Test Block',
icon: 'editor-table',
edit: ({ className, clientId }) => {
return (
<div className={className} style={{ border: '1px solid #ff0000', padding: '10px' }}>
<InnerBlocks
allowedBlocks={['test/test-inner-container']}
template={[['test/test-inner-container']]}
renderAppender={() => {
return (
<Inserter
isAppender
rootClientId={clientId}
renderToggle={({ onToggle, disabled }) => (
<Fragment>
<Button
onClick={onToggle}
disabled={disabled}
className="components-button is-secondary"
>
Insert Container
</Button>
</Fragment>
)}
/>
);
}}
/>
</div>
);
},
save: () => {
return null;
},
});
@Johnklein94
Copy link

Interesting code, but more fun can be had at bitcoin casino online. You can work even more efficiently after the fun.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment