diff --git a/packages/edit-site/src/components/global-styles/color-palette-panel.js b/packages/edit-site/src/components/global-styles/color-palette-panel.js index 5d4cfe9e007b58..1a8b503581c999 100644 --- a/packages/edit-site/src/components/global-styles/color-palette-panel.js +++ b/packages/edit-site/src/components/global-styles/color-palette-panel.js @@ -49,6 +49,9 @@ export default function ColorPalettePanel( { name } ) { ); const colorVariations = useThemeStyleVariationsByProperty( { styleProperty: 'color', + filter: ( variation ) => + variation?.settings?.color && + Object.keys( variation?.settings?.color ).length, } ); const isMobileViewport = useViewportMatch( 'small', '<' ); const popoverProps = isMobileViewport ? mobilePopoverProps : undefined; @@ -94,7 +97,9 @@ export default function ColorPalettePanel( { name } ) { popoverProps={ popoverProps } /> { /* @TODO: pass down variations to component? */ } - { !! colorVariations.length && } + { !! colorVariations.length && ( + + ) } ); } diff --git a/packages/edit-site/src/components/global-styles/screen-typography.js b/packages/edit-site/src/components/global-styles/screen-typography.js index 1c940983875a0a..1383c6c5dfecba 100644 --- a/packages/edit-site/src/components/global-styles/screen-typography.js +++ b/packages/edit-site/src/components/global-styles/screen-typography.js @@ -30,7 +30,11 @@ function ScreenTypography() { ); const typographyVariations = useThemeStyleVariationsByProperty( { styleProperty: 'typography', + filter: ( variation ) => + variation?.settings?.typography?.fontFamilies && + Object.keys( variation?.settings?.typography?.fontFamilies ).length, } ); + return ( <> { const { GlobalStylesContext } = unlock( blockEditorPrivateApis ); -export default function useThemeStyleVariationsByProperty( { styleProperty } ) { +export default function useThemeStyleVariationsByProperty( { + styleProperty, + filter, +} ) { const variations = useSelect( ( select ) => { return select( coreStore @@ -107,12 +110,16 @@ export default function useThemeStyleVariationsByProperty( { styleProperty } ) { Test with 2022 - typography font families bork for some reason */ - const styleVariations = getVariationsByProperty( + let styleVariations = getVariationsByProperty( user, variations, styleProperty ); - return styleVariations.length ? styleVariations : []; - }, [ styleProperty, variations ] ); + if ( 'function' === typeof filter ) { + styleVariations = styleVariations.filter( filter ); + } + + return styleVariations; + }, [ styleProperty, variations, filter ] ); } diff --git a/packages/edit-site/src/components/global-styles/variations-color.js b/packages/edit-site/src/components/global-styles/variations-color.js index f6a04a41363af1..94c2e2c44aceae 100644 --- a/packages/edit-site/src/components/global-styles/variations-color.js +++ b/packages/edit-site/src/components/global-styles/variations-color.js @@ -24,7 +24,6 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; import { mergeBaseAndUserConfigs } from './global-styles-provider'; import { unlock } from '../../lock-unlock'; import ColorIndicatorWrapper from './color-indicator-wrapper'; -import useThemeStyleVariationsByProperty from './use-theme-style-variations-by-property'; import Subtitle from './subtitle'; const { GlobalStylesContext, areGlobalStyleConfigsEqual } = unlock( @@ -118,11 +117,7 @@ function ColorVariation( { variation } ) { ); } -export default function ColorVariations() { - const colorVariations = useThemeStyleVariationsByProperty( { - styleProperty: 'color', - } ); - +export default function ColorVariations( { variations } ) { return ( { __( 'Presets' ) } @@ -130,15 +125,11 @@ export default function ColorVariations() { columns={ 2 } className="edit-site-global-styles-color-variations" > - { colorVariations && - colorVariations.map( ( variation, index ) => { - return ( - - ); - } ) } + { variations.map( ( variation, index ) => { + return ( + + ); + } ) } ); diff --git a/packages/edit-site/src/components/global-styles/variations-typography.js b/packages/edit-site/src/components/global-styles/variations-typography.js index 505436d6ac6e60..8470db2870e973 100644 --- a/packages/edit-site/src/components/global-styles/variations-typography.js +++ b/packages/edit-site/src/components/global-styles/variations-typography.js @@ -168,6 +168,9 @@ function TypographyVariation( { variation } ) { export default function TypographyVariations() { const typographyVariations = useThemeStyleVariationsByProperty( { styleProperty: 'typography', + filter: ( variation ) => + variation?.settings?.typography?.fontFamilies && + Object.keys( variation?.settings?.typography?.fontFamilies ).length, } ); const { base } = useContext( GlobalStylesContext );