/** * WordPress dependencies */ import { __experimentalHStack as HStack } from '@wordpress/components'; import { useContext } from '@wordpress/element'; import { getStyle } from '@wordpress/global-styles-engine'; import type { Color } from '@wordpress/global-styles-engine'; /** * Internal dependencies */ import { GlobalStylesContext } from './context'; export function ColorPreview() { const { merged } = useContext( GlobalStylesContext ); // Extract main colors from the global styles const backgroundColor = getStyle( merged, 'color.background' ) || '#ffffff'; const textColor = getStyle( merged, 'color.text' ) || '#000000'; // Get color palette - handle both array and object formats const palette = merged?.settings?.color?.palette; let paletteColors: Color[] = []; if ( Array.isArray( palette ) ) { paletteColors = palette; } else if ( palette && typeof palette === 'object' ) { paletteColors = palette.theme || palette.custom || []; } // Get first few colors from palette for preview const previewColors = paletteColors.slice( 0, 4 ); return ( { /* Background color swatch */ }
{ /* Text color swatch */ }
{ /* Palette colors */ } { previewColors .slice( 0, 2 ) .map( ( color: Color, index: number ) => (
) ) } ); }