Skip to content

Instantly share code, notes, and snippets.

@BeardedGinger
Created January 1, 2023 05:21
Show Gist options
  • Save BeardedGinger/cb0ce495e063060523a9341d2a41e967 to your computer and use it in GitHub Desktop.
Save BeardedGinger/cb0ce495e063060523a9341d2a41e967 to your computer and use it in GitHub Desktop.
Color Palette Example
import { InspectorControls, useSetting } from '@wordpress/block-editor';
import { PanelBody, PanelRow, ColorPalette } from '@wordpress/components';
const Edit = () => {
const { bgColor } = attributes;
const colors = useSetting( 'color.palette' ) || [];
return (
<>
<InspectorControls>
<PanelBody title='Background Options' initialOpen>
<PanelRow>
<ColorPalette
colors={ colors }
value={ bgColor }
onChange={ ( value ) => { setAttributes( { bgColor: value } ) } }
/>
</PanelRow>
</PanelBody>
</InspectorControls>
</>
);
}
export default Edit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment