Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve theme colors array inside Javascsipt

I am 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 cannot 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 have set inside php using the function getColorObjectByColorValue(themeColorsArray, callbackValueHexColor).

like image 919
tobiasegli Avatar asked Apr 02 '19 08:04

tobiasegli


1 Answers

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 } ) }
    />
like image 195
Sjaak Wish Avatar answered Nov 15 '22 02:11

Sjaak Wish