import * as React from 'react' import cx from 'classnames' import { createContext, useContext, } from '@wordpress/element' import { ColorIndicator as WPColorIndicator, } from '@wordpress/components' import type { ColorIndicatorProps as WPColorIndicatorProps, } from '@wordpress/components/build-types/color-indicator/types' import './style.scss' const transform = (value?: ColorIndicatorProps['colorValue']) => value export const ColorIndicatorContext = createContext<{ transformColorValue: typeof transform, }>({ transformColorValue: transform, }) export type ColorIndicatorProps = { colorValue?: string className?: string } & Omit const ColorIndicator: React.FC = ({ colorValue, className, ...props }) => { const { transformColorValue, } = useContext(ColorIndicatorContext) let cssColorValue = transformColorValue(colorValue) if(cssColorValue && cssColorValue.startsWith('(--') && cssColorValue.endsWith(')')) { // E.g. `(--wc-secondary)` -> `var(--wc-secondary)`. cssColorValue = `var${cssColorValue}` } return ( ) } export default ColorIndicator