Adding a control to a custom attribute

To add a control for a custom attribute you can use Gutenberg filters. Remember to remove the control if you deprecate the attribute.

Here is an example of adding a control:

const { __ } = wp.i18n;
const { Fragment } = wp.element;
const { InspectorControls } = wp.blockEditor;
const { PanelBody, RadioControl } = wp.components;

const withMyAttributeControl = wp.compose.createHigherOrderComponent(BlockEdit => {
    return props => {
        if (props.name !== "my-plugin/my-block") {
            return <BlockEdit {...props} />;
        }

        const { setAttributes, attributes } = props;

        return (
            <Fragment>
                <InspectorControls>
                    <PanelBody title={__("My Panel")}>
                        <RadioControl
                            label={__("My attribute")}
                            selected={attributes.custom.example_attribute_name}
                            options={[
                                {
                                    value: "value_A",
                                    label: "Value A"
                                },
                                {
                                    value: "value_B",
                                    label: "Value B"
                                }
                            ]}
                            onChange={value =>
                                setAttributes({
                                    custom: {
                                        // It's important to pass the object.
                                        ...attributes.custom,
                                        example_attribute_name: value
                                    }
                                })
                            }
                        />
                    </PanelBody>
                </InspectorControls>
                <BlockEdit {...props} />
            </Fragment>
        );
    };
}, "withMyAttributeControl");

wp.hooks.addFilter(
    "editor.BlockEdit",
    "my-plugin/my-filter",
    withMyAttributeControl
);
JavaScript