From 2e657089928b291d15d06e5bd602ed2eb20d74f3 Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Wed, 3 Jul 2024 12:17:24 +0100 Subject: [PATCH] Global Styles: Don't display browse styles unless the theme has full styles available --- .../components/global-styles/screen-root.js | 17 +++++------- .../style-variations-container.js | 27 ++++--------------- packages/edit-site/src/hooks/index.js | 23 ++++++++++++++++ 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/packages/edit-site/src/components/global-styles/screen-root.js b/packages/edit-site/src/components/global-styles/screen-root.js index 4146b32b57e3db..20ef59f74cc9fe 100644 --- a/packages/edit-site/src/components/global-styles/screen-root.js +++ b/packages/edit-site/src/components/global-styles/screen-root.js @@ -25,6 +25,7 @@ import { IconWithCurrentColor } from './icon-with-current-color'; import { NavigationButtonAsItem } from './navigation-button'; import RootMenu from './root-menu'; import PreviewStyles from './preview-styles'; +import { useThemeStyles } from '../../hooks'; import { unlock } from '../../lock-unlock'; const { useGlobalStyle } = unlock( blockEditorPrivateApis ); @@ -32,12 +33,9 @@ const { useGlobalStyle } = unlock( blockEditorPrivateApis ); function ScreenRoot() { const [ customCSS ] = useGlobalStyle( 'css' ); - const { hasVariations, canEditCSS } = useSelect( ( select ) => { - const { - getEntityRecord, - __experimentalGetCurrentGlobalStylesId, - __experimentalGetCurrentThemeGlobalStylesVariations, - } = select( coreStore ); + const { canEditCSS } = useSelect( ( select ) => { + const { getEntityRecord, __experimentalGetCurrentGlobalStylesId } = + select( coreStore ); const globalStylesId = __experimentalGetCurrentGlobalStylesId(); const globalStyles = globalStylesId @@ -45,13 +43,12 @@ function ScreenRoot() { : undefined; return { - hasVariations: - !! __experimentalGetCurrentThemeGlobalStylesVariations() - ?.length, canEditCSS: !! globalStyles?._links?.[ 'wp:action-edit-css' ], }; }, [] ); + const themeStyles = useThemeStyles(); + return ( @@ -61,7 +58,7 @@ function ScreenRoot() { - { hasVariations && ( + { themeStyles?.length && ( { - return select( - coreStore - ).__experimentalGetCurrentThemeGlobalStylesVariations(); - }, [] ); - - // Filter out variations that are color or typography variations. - const fullStyleVariations = variations?.filter( ( variation ) => { - return ( - ! isVariationWithProperties( variation, [ 'color' ] ) && - ! isVariationWithProperties( variation, [ - 'typography', - 'spacing', - ] ) - ); - } ); - + const themeStyles = useThemeStyles(); const themeVariations = useMemo( () => { const withEmptyVariation = [ { @@ -51,8 +33,9 @@ export default function StyleVariationsContainer( { gap = 2 } ) { settings: {}, styles: {}, }, - ...( fullStyleVariations ?? [] ), + ...( themeStyles ?? [] ), ]; + return [ ...withEmptyVariation.map( ( variation ) => { const blockStyles = { ...variation?.styles?.blocks } || {}; @@ -108,7 +91,7 @@ export default function StyleVariationsContainer( { gap = 2 } ) { }; } ), ]; - }, [ fullStyleVariations, userStyles?.blocks, userStyles?.css ] ); + }, [ themeStyles, userStyles?.blocks, userStyles?.css ] ); return ( { + return select( + coreStore + ).__experimentalGetCurrentThemeGlobalStylesVariations(); + }, [] ); + + // Filter out variations that are of single property type, i.e. color or typography variations. + return variations?.filter( ( variation ) => { + return ( + ! isVariationWithProperties( variation, [ 'color' ] ) && + ! isVariationWithProperties( variation, [ 'typography' ] ) + ); + } ); +}