Created
March 24, 2021 22:51
-
-
Save tlovett1/7a6ffcf994f85d41821e9469c35fdea4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting code, but more fun can be had at bitcoin casino online. You can work even more efficiently after the fun.