5

I'm looking for a way to retrieve the array of color objects you can set in the theme using add_theme_support('editor-color-palette', [...]);

Somehow I can not find any information in the documentation on how to retrieve the theme colors inside a custom block.

<ColorPalette
    onChange={ value => onChange(index, 'color', value) }
/>

I need the array of colors inside the onChange callback to convert a hex color to the slug color name I've set inside php using the function getColorObjectByColorValue(themeColorsArray, callbackValueHexColor)

Thanks alot for your help!

Edit: Found the solution. There is a function inside wp.core called select. With this funciton you can retrieve the editor core object. To get the color do as followed:

wp.data.select( "core/editor" ).getEditorSettings().colors
tobiasegli
  • 51
  • 3

1 Answers1

0

just for future readers, thanks for the answer @tobiasegli

 <ColorPalette
    colors={wp.data.select( "core/editor" ).getEditorSettings().colors }
    label={'bg color'}
    value={ color }
    onChange={ ( color ) => setState( { color } ) }
    />
Sjaak Wish
  • 185
  • 1
  • 5