From 352f568d3adb2028ff448b112ce48032b96cd02f Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Tue, 2 Jul 2024 11:54:14 +0100 Subject: [PATCH] Global Styles: Make a shared component for typography and color preview (#62829) * Global Styles: Make a shared component for typography and color preview * remove null check that has already happened Co-authored-by: scruffian Co-authored-by: MaggieCabrera Co-authored-by: jeryj --- .../global-styles/preview-typography.js | 39 +++++++++++++++++++ .../variations/variations-typography.js | 39 +++++-------------- 2 files changed, 48 insertions(+), 30 deletions(-) create mode 100644 packages/edit-site/src/components/global-styles/preview-typography.js diff --git a/packages/edit-site/src/components/global-styles/preview-typography.js b/packages/edit-site/src/components/global-styles/preview-typography.js new file mode 100644 index 00000000000000..26ae13eaa09083 --- /dev/null +++ b/packages/edit-site/src/components/global-styles/preview-typography.js @@ -0,0 +1,39 @@ +/** + * WordPress dependencies + */ +import { __experimentalHStack as HStack } from '@wordpress/components'; + +/** + * Internal dependencies + */ +import TypographyExample from './typography-example'; +import PreviewIframe from './preview-iframe'; + +const StylesPreviewTypography = ( { variation, isFocused, withHoverView } ) => { + return ( + + { ( { ratio, key } ) => ( + + + + ) } + + ); +}; + +export default StylesPreviewTypography; 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 2aa5aaf80ee1f5..87a83a648e3a8f 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 @@ -3,22 +3,19 @@ */ import { __experimentalGrid as Grid, - __experimentalVStack as HStack, __experimentalVStack as VStack, } from '@wordpress/components'; /** * Internal dependencies */ +import StylesPreviewTypography from '../preview-typography'; import { useTypographyVariations } from '../hooks'; -import TypographyExample from '../typography-example'; -import PreviewIframe from '../preview-iframe'; import Variation from './variation'; import Subtitle from '../subtitle'; export default function TypographyVariations( { title, gap = 2 } ) { const typographyVariations = useTypographyVariations(); - // Return null if there is only one variation (the default). if ( typographyVariations?.length <= 1 ) { return null; @@ -32,40 +29,22 @@ export default function TypographyVariations( { title, gap = 2 } ) { gap={ gap } className="edit-site-global-styles-style-variations-container" > - { typographyVariations && - typographyVariations.length && - typographyVariations.map( ( variation, index ) => ( + { typographyVariations.map( ( variation, index ) => { + return ( - { ( isFocused ) => ( - - { ( { ratio, key } ) => ( - - - - ) } - + { () => ( + ) } - ) ) } + ); + } ) } );