From 4d1aa40f02c6a46e08b1496f74c66a059611b0a2 Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Fri, 14 Jun 2024 20:28:14 +0100 Subject: [PATCH] Global Styles: Don't apply the background and text colors to typography previews (#62578) Co-authored-by: scruffian Co-authored-by: ajlende Co-authored-by: hbhalodia Co-authored-by: draganescu Co-authored-by: richtabor --- .../global-styles/variations/variation.js | 19 ++++++++++++------- .../variations/variations-color.js | 7 ++++++- .../variations/variations-typography.js | 6 +++++- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/packages/edit-site/src/components/global-styles/variations/variation.js b/packages/edit-site/src/components/global-styles/variations/variation.js index 8e74020ec8da3f..1c1418a54931f8 100644 --- a/packages/edit-site/src/components/global-styles/variations/variation.js +++ b/packages/edit-site/src/components/global-styles/variations/variation.js @@ -15,6 +15,7 @@ import { privateApis as editorPrivateApis } from '@wordpress/editor'; /** * Internal dependencies */ +import { filterObjectByProperty } from '../../../hooks/use-theme-style-variations/use-theme-style-variations-by-property'; import { unlock } from '../../../lock-unlock'; const { mergeBaseAndUserConfigs } = unlock( editorPrivateApis ); @@ -22,18 +23,22 @@ const { GlobalStylesContext, areGlobalStyleConfigsEqual } = unlock( blockEditorPrivateApis ); -export default function Variation( { variation, children, isPill } ) { +export default function Variation( { variation, children, isPill, property } ) { const [ isFocused, setIsFocused ] = useState( false ); const { base, user, setUserConfig } = useContext( GlobalStylesContext ); - const context = useMemo( - () => ( { + + const context = useMemo( () => { + let merged = mergeBaseAndUserConfigs( base, variation ); + if ( property ) { + merged = filterObjectByProperty( merged, property ); + } + return { user: variation, base, - merged: mergeBaseAndUserConfigs( base, variation ), + merged, setUserConfig: () => {}, - } ), - [ variation, base ] - ); + }; + }, [ variation, base, property ] ); const selectVariation = () => setUserConfig( variation ); diff --git a/packages/edit-site/src/components/global-styles/variations/variations-color.js b/packages/edit-site/src/components/global-styles/variations/variations-color.js index 88361afcc58f8f..e84145afe2858e 100644 --- a/packages/edit-site/src/components/global-styles/variations/variations-color.js +++ b/packages/edit-site/src/components/global-styles/variations/variations-color.js @@ -27,7 +27,12 @@ export default function ColorVariations( { title, gap = 2 } ) { { title && { title } } { colorVariations.map( ( variation, index ) => ( - + { () => } ) ) } diff --git a/packages/edit-site/src/components/global-styles/variations/variations-typography.js b/packages/edit-site/src/components/global-styles/variations/variations-typography.js index 208ed822b5a6f6..689340cee9bd8e 100644 --- a/packages/edit-site/src/components/global-styles/variations/variations-typography.js +++ b/packages/edit-site/src/components/global-styles/variations/variations-typography.js @@ -35,7 +35,11 @@ export default function TypographyVariations( { title, gap = 2 } ) { { typographyVariations && typographyVariations.length && typographyVariations.map( ( variation, index ) => ( - + { ( isFocused ) => (