diff --git a/packages/components/src/mobile/global-styles-context/test/utils.native.js b/packages/components/src/mobile/global-styles-context/test/utils.native.js index c1f968de24e48..6144b9a13ae89 100644 --- a/packages/components/src/mobile/global-styles-context/test/utils.native.js +++ b/packages/components/src/mobile/global-styles-context/test/utils.native.js @@ -108,6 +108,28 @@ describe( 'parseStylesVariables', () => { expect.objectContaining( PARSED_GLOBAL_STYLES ) ); } ); + + it( 'returns the parsed custom color values correctly', () => { + const defaultStyles = { + ...DEFAULT_GLOBAL_STYLES, + color: { + text: 'var(--wp--custom--color--blue)', + background: 'var(--wp--custom--color--green)', + }, + }; + const customValues = parseStylesVariables( + JSON.stringify( RAW_FEATURES.custom ), + MAPPED_VALUES + ); + const styles = parseStylesVariables( + JSON.stringify( defaultStyles ), + MAPPED_VALUES, + customValues + ); + expect( styles ).toEqual( + expect.objectContaining( PARSED_GLOBAL_STYLES ) + ); + } ); } ); describe( 'getGlobalStyles', () => { diff --git a/packages/components/src/mobile/global-styles-context/utils.native.js b/packages/components/src/mobile/global-styles-context/utils.native.js index f2cbcae9c3f3e..b56e28da46207 100644 --- a/packages/components/src/mobile/global-styles-context/utils.native.js +++ b/packages/components/src/mobile/global-styles-context/utils.native.js @@ -248,6 +248,20 @@ export function parseStylesVariables( styles, mappedValues, customValues ) { const customValuesData = customValues ?? JSON.parse( stylesBase ); stylesBase = stylesBase.replace( regex, ( _$1, $2 ) => { const path = $2.split( '--' ); + + // Supports cases for variables like var(--wp--custom--color--background) + if ( path[ 0 ] === 'color' ) { + const colorKey = path[ path.length - 1 ]; + if ( mappedValues?.color ) { + const matchedValue = mappedValues.color?.values?.find( + ( { slug } ) => slug === colorKey + ); + if ( matchedValue ) { + return `${ matchedValue?.color }`; + } + } + } + if ( path.reduce( ( prev, curr ) => prev && prev[ curr ],