-
Notifications
You must be signed in to change notification settings - Fork 8
ColorControl Component
Josh_soporte edited this page Jul 15, 2020
·
6 revisions
Include color options on Inspector Control for the Block.
/src/components/color-control
Renders color control on Inspector Control:
const { __ } = wp.i18n;
const { InspectorControls } = wp.blockEditor;
const { registerBlockType } = wp.blocks;
#Component
import ColorControl from '../components/color-control/';
registerBlockType( 'maxi-blocks/example-block', {
title: __('Example block', 'maxi-blocks'),
icon: icon,
category: 'maxi-blocks',
attributes: {
color: {
type: 'string'
},
defaultColor: {
type: 'string',
default: ''
}
gradient: {
type: 'string'
},
defaultGradient: {
type: 'string',
default: ''
}
gradientAboveBackground: {
type: 'boolean',
deafult: false
}
},
edit: (props) => {
return (
<InspectorControls>
<ColorControl
label={__('Some label', 'gutenberg-extra')}
color={props.attributes.color}
defaultColor={props.attributes.defaultColor}
onColorChange={value => props.setAttributes({props.attributes.color: value})}
/>
</InspectorControls>
)
}
save: () => {
return null;
}
} );
Name | Type | Default | Required | Description |
---|---|---|---|---|
className | string |
"maxi-colorcontrol" |
N | Defines the class to show on the element |
label | string |
none |
Y | Component title to show on the block |
color | string |
none |
Y | Block property saved value (RGBA) |
defaultColor | string |
'' |
N | Color to retrieve in case of reseting |
onColorChange | function |
none |
Y | Retrieve input value to be saved |