@tinypixelco/wp-react-hooks
Overview
Block
Post
Editor
useColorsBasicsList colorsaddColorsetColorsuseFontSizesuseSettings
Data

useColors

The useColors hook provides an interface for consuming and modifying the block editor color palette.

Basics

Import

import {useColors} from '@tinypixelco/wp-react-hooks'

Use

const {colors, setColors, addColor} = useColors()

The colors array is made up of objects that are shaped like this

{
name: "Primary",
slug: "primary",
color: "#0073a8",
}

List colors

List all the colors registered with WordPress.

import {useColors} from '@tinypixelco/wp-react-hooks'
const component = () => {
const [colors] = useColors()
return (
<div>
{colors && JSON.stringify(colors)}
</div>
)
}

addColor

Add a color to the palette.

{addColor} = useColors()
addColor({
name: "New",
slug: "new",
color: "#0073a8",
})

setColors

Replace the palette with a new one, or otherwise process the array and return what you like.

{setColors} = useColors()
setColors([
{name: 'black', slug: 'black', color: '#000000'},
{name: 'white', slug: 'white', color: '#ffffff'},
])