Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global Styles: Try color and typography presets in Site View #59594

Merged
merged 8 commits into from
Mar 15, 2024
Prev Previous commit
Next Next commit
Filtering for settings before showing titles.
  • Loading branch information
ramonjd authored and scruffian committed Mar 15, 2024
commit cdf5af954672822306dbd2ae427f8251254f1333
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,14 @@ function SidebarNavigationScreenGlobalStylesContent() {

const colorVariations = useCurrentMergeThemeStyleVariationsWithUserConfig( {
property: 'color',
filter: ( variation ) => !! variation?.settings?.color,
Copy link
Member

Choose a reason for hiding this comment

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

To make things consistent, maybe the same should be applied to the global styles side bar:

diff --git a/packages/edit-site/src/components/global-styles/variations/variations-color.js b/packages/edit-site/src/components/global-styles/variations/variations-color.js
index 04b8c47696..8377029148 100644
--- a/packages/edit-site/src/components/global-styles/variations/variations-color.js
+++ b/packages/edit-site/src/components/global-styles/variations/variations-color.js
@@ -16,6 +16,7 @@ import { useCurrentMergeThemeStyleVariationsWithUserConfig } from '../../../hook
 export default function ColorVariations() {
 	const colorVariations = useCurrentMergeThemeStyleVariationsWithUserConfig( {
 		property: 'color',
+		filter: ( variation ) => !! variation?.settings?.color,
 	} );
 
 	if ( ! colorVariations?.length ) {
diff --git a/packages/edit-site/src/components/global-styles/variations/variations-typography.js b/packages/edit-site/src/components/global-styles/variations/variations-typography.js
index c59e9e872c..5526d06d13 100644
--- a/packages/edit-site/src/components/global-styles/variations/variations-typography.js
+++ b/packages/edit-site/src/components/global-styles/variations/variations-typography.js
@@ -26,6 +26,8 @@ export default function TypographyVariations() {
 	const typographyVariations =
 		useCurrentMergeThemeStyleVariationsWithUserConfig( {
 			property: 'typography',
+			filter: ( variation ) =>
+				!! variation?.settings?.typography?.fontFamilies,
 		} );
 
 	const { base } = useContext( GlobalStylesContext );

Or, maybe create an optional headingText/headingElement prop to these components so the heading renders with the component?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure we need to do this. There could be instances where the style variation doesn't introduce any new settings, but the style variation itself still changes the look of the site - for example look at how TT3 deal with typography - the setting all live in the parent variation, but each child uses them differently.

Copy link
Member

Choose a reason for hiding this comment

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

Fair point. Then we could revert a30eb5b. Still, it would be good to have a way to show variations without settings to avoid a blank area. 🤔

Maybe a fallback preview icon or something?

} );

const typographyVariations =
useCurrentMergeThemeStyleVariationsWithUserConfig( {
property: 'typography',
filter: ( variation ) =>
!! variation?.settings?.typography?.fontFamilies,
} );

// Wrap in a BlockEditorProvider to ensure that the Iframe's dependencies are
Expand All @@ -100,15 +103,15 @@ function SidebarNavigationScreenGlobalStylesContent() {
className="edit-site-global-styles-variation-container"
>
<StyleVariationsContainer />
{ colorVariations && (
{ colorVariations?.length && (
<div>
<h3 className="edit-site-global-styles-variation-title">
{ __( 'Colors' ) }
</h3>
<ColorVariations />
</div>
) }
{ typographyVariations && (
{ typographyVariations?.length && (
<div>
<h3 className="edit-site-global-styles-variation-title">
{ __( 'Typography' ) }
Expand Down
Loading