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 <[email protected]>
Co-authored-by: ajlende <[email protected]>
Co-authored-by: hbhalodia <[email protected]>
Co-authored-by: draganescu <[email protected]>
Co-authored-by: richtabor <[email protected]>
  • Loading branch information
6 people authored Jun 14, 2024
1 parent 0658187 commit 4d1aa40
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

1 comment on commit 4d1aa40

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 4d1aa40.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9521370718
📝 Reported issues:

Please sign in to comment.