From 78089c8ab98c96ef41c512cfc9034a9e2b50baba Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Wed, 23 Mar 2022 14:16:02 +0100 Subject: [PATCH] Fix focus, add weight and remove text color --- .../src/components/global-styles/preview.js | 26 ++++++++++++++----- .../global-styles/screen-style-variations.js | 10 +++++-- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/packages/edit-site/src/components/global-styles/preview.js b/packages/edit-site/src/components/global-styles/preview.js index 9ea5eb53f12559..8f383655a7907c 100644 --- a/packages/edit-site/src/components/global-styles/preview.js +++ b/packages/edit-site/src/components/global-styles/preview.js @@ -43,11 +43,15 @@ const secondFrame = { const normalizedWidth = 250; -const StylesPreview = ( { label } ) => { +const StylesPreview = ( { label, isFocused } ) => { + const [ fontWeight ] = useStyle( 'typography.fontWeight' ); const [ fontFamily = 'serif' ] = useStyle( 'typography.fontFamily' ); const [ headingFontFamily = fontFamily ] = useStyle( 'elements.h1.typography.fontFamily' ); + const [ headingFontWeight = fontWeight ] = useStyle( + 'elements.h1.typography.fontWeight' + ); const [ textColor = 'black' ] = useStyle( 'color.text' ); const [ headingColor = textColor ] = useStyle( 'elements.h1.color.text' ); const [ linkColor = 'blue' ] = useStyle( 'elements.link.color.text' ); @@ -55,10 +59,10 @@ const StylesPreview = ( { label } ) => { const [ gradientValue ] = useStyle( 'color.gradient' ); const [ styles ] = useGlobalStylesOutput(); const disableMotion = useReducedMotion(); - const [ isHovered, setIsHovered ] = useState( false ); const [ coreColors ] = useSetting( 'color.palette.core' ); const [ themeColors ] = useSetting( 'color.palette.theme' ); const [ customColors ] = useSetting( 'color.palette.custom' ); + const [ isHovered, setIsHovered ] = useState( false ); const [ containerResizeListener, { width } ] = useResizeObserver(); const ratio = width ? width / normalizedWidth : 1; @@ -66,7 +70,10 @@ const StylesPreview = ( { label } ) => { .concat( customColors ?? [] ) .concat( coreColors ?? [] ); const highlightedColors = paletteColors - .filter( ( { color } ) => color !== backgroundColor ) + .filter( + // we exclude these two colors because they are already visible in the preview. + ( { color } ) => color !== backgroundColor && color !== headingColor + ) .slice( 0, 2 ); return ( @@ -79,6 +86,7 @@ const StylesPreview = ( { label } ) => { } } onMouseEnter={ () => setIsHovered( true ) } onMouseLeave={ () => setIsHovered( false ) } + tabIndex={ -1 } > { containerResizeListener } { cursor: 'pointer', } } initial="start" - animate={ isHovered && ! disableMotion ? 'hover' : 'start' } + animate={ + ( isHovered || isFocused ) && ! disableMotion + ? 'hover' + : 'start' + } > { fontFamily: headingFontFamily, fontSize: 65 * ratio, color: headingColor, + fontWeight: headingFontWeight, } } > Aa - { highlightedColors.map( ( { color } ) => ( + { highlightedColors.map( ( { slug, color } ) => (
{ fontSize: 35 * ratio, fontFamily: headingFontFamily, color: headingColor, + fontWeight: headingFontWeight, lineHeight: '1em', } } > diff --git a/packages/edit-site/src/components/global-styles/screen-style-variations.js b/packages/edit-site/src/components/global-styles/screen-style-variations.js index a86e9aa7222ffb..a9bff967050413 100644 --- a/packages/edit-site/src/components/global-styles/screen-style-variations.js +++ b/packages/edit-site/src/components/global-styles/screen-style-variations.js @@ -9,7 +9,7 @@ import classnames from 'classnames'; */ import { store as coreStore } from '@wordpress/core-data'; import { useSelect } from '@wordpress/data'; -import { useMemo, useContext } from '@wordpress/element'; +import { useMemo, useContext, useState } from '@wordpress/element'; import { ENTER } from '@wordpress/keycodes'; import { __experimentalGrid as Grid, @@ -31,6 +31,7 @@ function compareVariations( a, b ) { } function Variation( { variation } ) { + const [ isFocused, setIsFocused ] = useState( false ); const { base, user, setUserConfig } = useContext( GlobalStylesContext ); const context = useMemo( () => { return { @@ -78,9 +79,14 @@ function Variation( { variation } ) { onKeyDown={ selectOnEnter } tabIndex="0" aria-label={ variation?.name } + onFocus={ () => setIsFocused( true ) } + onBlur={ () => setIsFocused( false ) } >
- +