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
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ export default function PreviewIframe( {
<Iframe
className="edit-site-global-styles-preview__iframe"
style={ {
width: '100%',
height: normalizedHeight * ratio,
} }
onMouseEnter={ () => setIsHovered( true ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function ScreenColors() {
) }
/>
<div className="edit-site-global-styles-screen-colors">
<VStack spacing={ 3 }>
<VStack spacing={ 6 }>
<ColorVariations />
<Palette />
<StylesColorPanel
Expand Down
5 changes: 4 additions & 1 deletion packages/edit-site/src/components/global-styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
}

.edit-site-global-styles-preview__iframe {
max-width: 100%;
border-radius: $radius-block-ui;
display: block;
max-width: 100%;
width: 100%;
}

.edit-site-typography-preview {
Expand Down Expand Up @@ -165,3 +167,4 @@
.edit-site-global-styles-sidebar__panel .block-editor-block-icon svg {
fill: currentColor;
}

Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ export default function PreviewTypography( { fontSize, variation } ) {
type: 'tween',
} }
style={ {
fontSize: '22px',
lineHeight: '44px',
textAlign: 'center',
} }
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { useContext } from '@wordpress/element';
import {
__experimentalGrid as Grid,
__experimentalVStack as HStack,
__experimentalVStack as VStack,
} from '@wordpress/components';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
Expand Down Expand Up @@ -74,11 +75,21 @@ export default function TypographyVariations() {
label={ variation?.title }
isFocused={ isFocused }
>
{ ( { key } ) => (
<TypographyExample
{ ( { ratio, key } ) => (
<HStack
key={ key }
variation={ variation }
/>
spacing={ 10 * ratio }
justify="center"
style={ {
height: '100%',
overflow: 'hidden',
} }
>
<TypographyExample
variation={ variation }
fontSize={ 85 * ratio }
/>
</HStack>
) }
</PreviewIframe>
) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { __ } from '@wordpress/i18n';
import { edit, seen } from '@wordpress/icons';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { __experimentalNavigatorButton as NavigatorButton } from '@wordpress/components';
import {
__experimentalNavigatorButton as NavigatorButton,
__experimentalVStack as VStack,
} from '@wordpress/components';
import { useViewportMatch } from '@wordpress/compose';
import { BlockEditorProvider } from '@wordpress/block-editor';
import { useCallback } from '@wordpress/element';
Expand All @@ -24,6 +27,9 @@ import SidebarNavigationItem from '../sidebar-navigation-item';
import StyleBook from '../style-book';
import useGlobalStylesRevisions from '../global-styles/screen-revisions/use-global-styles-revisions';
import SidebarNavigationScreenDetailsFooter from '../sidebar-navigation-screen-details-footer';
import ColorVariations from '../global-styles/variations/variations-color';
import TypographyVariations from '../global-styles/variations/variations-typography';
import { useCurrentMergeThemeStyleVariationsWithUserConfig } from '../../hooks/use-theme-style-variations/use-theme-style-variations-by-property';

const noop = () => {};

Expand Down Expand Up @@ -69,6 +75,18 @@ 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
// loaded. This is necessary because the Iframe component waits until
// the block editor store's `__internalIsInitialized` is true before
Expand All @@ -80,7 +98,28 @@ function SidebarNavigationScreenGlobalStylesContent() {
onChange={ noop }
onInput={ noop }
>
<StyleVariationsContainer />
<VStack
spacing={ 10 }
className="edit-site-global-styles-variation-container"
>
<StyleVariationsContainer />
{ colorVariations?.length && (
<div>
<h3 className="edit-site-global-styles-variation-title">
{ __( 'Colors' ) }
</h3>
<ColorVariations />
</div>
) }
{ typographyVariations?.length && (
<div>
<h3 className="edit-site-global-styles-variation-title">
{ __( 'Typography' ) }
</h3>
<TypographyVariations />
</div>
) }
</VStack>
</BlockEditorProvider>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
flex-shrink: 0;
}

.edit-site-sidebar-navigation-screen__content .edit-site-global-styles-style-variations-container {
.edit-site-sidebar-navigation-screen__content .edit-site-global-styles-variation-container {
@include break-medium() {
// Safari does not currently support `scrollbar-gutter: stable`, so at
// particular viewport sizes it's possible for previews to render prior to a
Expand All @@ -90,7 +90,16 @@
// See: https://github.com/WordPress/gutenberg/issues/55112
max-width: 292px;
}
}

.edit-site-global-styles-variation-title {
color: $gray-300;
font-size: 11px;
text-transform: uppercase;
font-weight: 500;
}

.edit-site-sidebar-navigation-screen__content .edit-site-global-styles-style-variations-container {
.edit-site-global-styles-variations_item-preview {
box-shadow: 0 0 0 $border-width $gray-900;
}
Expand Down
Loading