I've registered a custom block that's basically a wrapper for other content with some background color options.
Here's my registration code on the backend:
function mytheme_register_box_block() {
register_block_type( 'mytheme/box', array(
'attributes' => array(
'className' => array(
'type' => 'string',
'default' => '',
),
),
'supports' => array(
'customClassName' => false,
),
'editor_script' => 'mytheme-editor',
) );
}
add_action( 'init', 'mytheme_register_box_block' );
Here is the code for my block that's imported by my editor script:
const { InnerBlocks } = wp.editor;
export default {
title: 'Box',
description: 'Wrap content within an area to apply a colorscheme to.',
icon: 'grid-view',
category: 'layout',
attributes: {
className: {
type: 'string',
},
},
styles: [
{
name: 'default',
label: 'Grey',
isDefault: true,
},
{
name: 'green',
label: 'Green',
},
{
name: 'orange',
label: 'Orange',
},
{
name: 'blue',
label: 'Blue',
},
{
name: 'cyan',
label: 'Cyan',
},
],
edit: props => {
return (
<div className={ props.className }>
{ ( typeof props.insertBlocksAfter !== 'undefined' ) ? <InnerBlocks /> : <div>Lorem ipsum dolor sit amet.</div> }
</div>
)
},
save: ( { className } ) => {
return (
<div className={ className }>
<InnerBlocks.Content />
</div>
)
},
};
In Gutenberg the block renders fine and applies the styling, but when it's printed out on the frontend, it's simply rendered without the styling applied.
<div class="wp-block-mytheme-box">...</div>
The attributes
list I have in the register_block_type call I just added to try and get it to work, but to no avail. I'm not sure what I'm missing.