useRootColors Get Cerberus colors from the document root.
import { useRootColors } from ' @cerberus/react '
This hook allows you to access Cerberus colors from the document root which is useful when you want to use Cerberus colors within a canvas
element.
This is adding data-viz colors to a canvas element.
If you need to get the latest colors when a user changes the color mode or theme, you can use the refetch
function to get the latest colors from the document root.
import { useRootColors , useTheme } from ' @cerberus/react '
import { useEffect , useState } from ' react '
const initialSettings = { ... stuffFromXChartLibrary }
const [ settings , setOptions ] = useState ( initialSettings )
const { theme } = useTheme ()
const { colors , refetch } = useRootColors ( colorList )
// We need to wait for the theme to be applied to the root element
const start = colors [ colorList [ 0 ]]
image : ` radial-gradient(75% 82% at 52% 100%, ${ start } 40 0%, transparent 100%) ` ,
< SomeChartLib settings = { settings } />
export interface RootColorsResult {
colors : Record < string , string >
define function useRootColors ( colors : string [] = [] ) : RootColorsResult
The useRootColors
hook accepts the following optional arguments:
Name Default Description colors An array of Cerberus color keys to retrieve. refetch A function to refetch the colors from the root.
The useRootColors
hook returns a memoized object with the same properties as the options object passed in.
' dataViz.diverging.50 ' : ' #F7F7F7 ' ,
' dataViz.diverging.100 ' : ' #E5E5E5 ' ,
' dataViz.diverging.200 ' : ' #C6C6C6 ' ,