Skip to content

Commit

Permalink
Show the default empty variation as well as the other presets
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed Mar 15, 2024
1 parent d9326f0 commit ef3645b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,35 @@ export default function TypographyVariations() {
columns={ 3 }
className="edit-site-global-styles-style-variations-container"
>
{ typographyVariations && typographyVariations.length
? typographyVariations.map( ( variation, index ) => (
<Variation key={ index } variation={ variation }>
{ ( isFocused ) => (
<PreviewIframe
label={ variation?.title }
isFocused={ isFocused }
>
{ ( { ratio, key } ) => (
<HStack
key={ key }
spacing={ 10 * ratio }
justify="center"
style={ {
height: '100%',
overflow: 'hidden',
} }
>
<TypographyExample
variation={ variation }
fontSize={ 85 * ratio }
/>
</HStack>
) }
</PreviewIframe>
) }
</Variation>
) )
: null }
{ typographyVariations &&
typographyVariations.length &&
typographyVariations.map( ( variation, index ) => (
<Variation key={ index } variation={ variation }>
{ ( isFocused ) => (
<PreviewIframe
label={ variation?.title }
isFocused={ isFocused }
>
{ ( { ratio, key } ) => (
<HStack
key={ key }
spacing={ 10 * ratio }
justify="center"
style={ {
height: '100%',
overflow: 'hidden',
} }
>
<TypographyExample
variation={ variation }
fontSize={ 85 * ratio }
/>
</HStack>
) }
</PreviewIframe>
) }
</Variation>
) ) }
</Grid>
</VStack>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { useContext, useMemo } from '@wordpress/element';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
Expand Down Expand Up @@ -54,13 +55,29 @@ export function useCurrentMergeThemeStyleVariationsWithUserConfig( {
property,
filter,
} ) {
const variations = useSelect( ( select ) => {
return select(
coreStore
).__experimentalGetCurrentThemeGlobalStylesVariations();
const { variationsFromTheme } = useSelect( ( select ) => {
const _variationsFromTheme =
select(
coreStore
).__experimentalGetCurrentThemeGlobalStylesVariations();

return {
variationsFromTheme: _variationsFromTheme || [],
};
}, [] );
const { user: baseVariation } = useContext( GlobalStylesContext );

const variations = useMemo( () => {
return [
{
title: __( 'Default' ),
settings: {},
styles: {},
},
...variationsFromTheme,
];
}, [ variationsFromTheme ] );

return useThemeStyleVariationsByProperty( {
variations,
property,
Expand Down

0 comments on commit ef3645b

Please sign in to comment.