Skip to content

GradientControl Component

Josh_soporte edited this page Jul 15, 2020 · 2 revisions

Include gradient options on Inspector Control for the Block.

Files path

/src/components/gradient-control

Usage

Renders gradient control on Inspector Control:

const { __ } = wp.i18n;
const { InspectorControls } = wp.blockEditor;
const { registerBlockType } = wp.blocks;

#Component
import GradientControl from '../components/gradient-control/';

registerBlockType( 'maxi-blocks/example-block', {
    title: __('Example block', 'maxi-blocks'),
    icon: icon,
    category: 'maxi-blocks',
    attributes: {
        gradient: {
            type: 'string'
        },
        defaultGradient: {
            type: 'string',
            default: ''
        }
        gradientAboveBackground: {
            type: 'boolean',
            deafult: false
        }
    },
    edit: (props) => {
        return (
            <InspectorControls>
                <ColorControl
                    label={__('Some label', 'gutenberg-extra')}
                    gradient={props.attributes.gradient}
                    defaultGradient={props.attributes.defaultGradient}
                    onGradientChange={value => props.setAttributes({ props.attributes.gradient: value })}
                    gradientAboveBackground={props.attributes.gradientAboveBackground}
                    onGradientAboveBackgroundChange={value => props.setAttributes({ props.attributes.gradientAboveBackground: value })}
                />
            </InspectorControls>
        )
    }
    save: () => {
        return null;
    }
} );

Props

Name Type Default Required Description
label string none Y Component title to show on the block
className string maxi-shadow-control N Classes for the component
gradient string none Y Block property saved value (linear-gradient)
defaultgradient string '' N Gradient to retrieve in case of reseting
onGradientChange function undefined Y Retrieve input value to be saved
disableGradientAboveBackground boolean false Display/hive gradientAboveBackground
gradientAboveBackground boolean false Y Block property saved value
onGradientAboveBackgroundChange function none Y Retrieve input value to be saved
Clone this wiki locally