Skip to content

Commit

Permalink
Global Styles: Don't apply the background and text colors to typograp…
Browse files Browse the repository at this point in the history
…hy previews (#62578)

Co-authored-by: scruffian <scruffian@git.wordpress.org>
Co-authored-by: ajlende <ajlende@git.wordpress.org>
Co-authored-by: hbhalodia <hbhalodia@git.wordpress.org>
Co-authored-by: draganescu <andraganescu@git.wordpress.org>
Co-authored-by: richtabor <richtabor@git.wordpress.org>
  • Loading branch information
6 people authored and ellatrix committed Jun 18, 2024
1 parent e811b72 commit d4ed28c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,30 @@ 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 );
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 );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ export default function ColorVariations( { title, gap = 2 } ) {
{ title && <Subtitle level={ 3 }>{ title }</Subtitle> }
<Grid spacing={ gap }>
{ colorVariations.map( ( variation, index ) => (
<Variation key={ index } variation={ variation } isPill>
<Variation
key={ index }
variation={ variation }
isPill
property="color"
>
{ () => <StylesPreviewColors /> }
</Variation>
) ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export default function TypographyVariations( { title, gap = 2 } ) {
{ typographyVariations &&
typographyVariations.length &&
typographyVariations.map( ( variation, index ) => (
<Variation key={ index } variation={ variation }>
<Variation
key={ index }
variation={ variation }
property="typography"
>
{ ( isFocused ) => (
<PreviewIframe
label={ variation?.title }
Expand Down

0 comments on commit d4ed28c

Please sign in to comment.