I added the setting to the latest version of the plugin which is out.
For a code example on how you could do this here is what it could look like:
const {
Fragment,
} = wp.element;
const {
InspectorControls,
} = wp.editor;
const {
PanelBody,
ToggleControl,
} = wp.components;
const { createHigherOrderComponent } = wp.compose;
const { __ } = wp.i18n;
const { addFilter } = wp.hooks;
import assign from 'lodash/assign';
/**
* Add attribute to the block
*
* @param {Object} settings blocks settings.
* @param {String} name blocks name.
* @return {Object} the block settings.
*/
export function prefixAddAttribute( settings, name ) {
if ( name !== 'kadence/advancedbtn' ) {
return settings;
}
settings.attributes = assign( settings.attributes, {
btnFullwidth: {
type: 'bool',
default: false,
},
} );
return settings;
}
addFilter( 'blocks.registerBlockType', 'prefix/editbutton', prefixAddAttribute );
/**
* Build setting.
*/
const prefixAddControl = createHigherOrderComponent( ( BlockEdit ) => {
return ( props ) => {
if ( props.name === 'kadence/advancedbtn' && props.isSelected ) {
const { attributes: { btnFullwidth }, setAttributes } = props;
return (
<Fragment>
<BlockEdit { ...props } />
<InspectorControls>
<PanelBody
title={ __( 'Fullwidth Button' ) }
initialOpen={ false }
>
<ToggleControl
label={ __( 'Set button to fullwidth?' ) }
checked={ ( undefined !== btnFullwidth ? btnFullwidth : false ) }
onChange={ ( value ) => setAttributes( { btnFullwidth: value } ) }
/>
</PanelBody>
</InspectorControls>
</Fragment>
);
}
return <BlockEdit { ...props } />;
};
}, 'withInspectorControl' );
addFilter( 'editor.BlockEdit', 'prefix/editbutton', prefixAddControl );
function prefixAddData( props, blockType, attributes ) {
if ( blockType === 'kadence/advancedbtn' && attributes.btnFullwidth ) {
assign( props, { 'class': ( attributes.btnFullwidth ? 'class-button-is-fullwidth' : undefined } );
}
return props;
}
addFilter( 'blocks.getSaveContent.extraProps', 'prefix/editbutton', prefixAddData );
There are three steps. First you add in the attribute to the block, then you add in the settings so they show when using the block and finally you add in an extra class if the toggle is checked. Using that you just load the css on the front end that would allow you to style the block based on the added class.
I hope that helps,
Ben