Skip to content

Commit 78089c8

Browse files
committed
Fix focus, add weight and remove text color
1 parent 0d1fbe3 commit 78089c8

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

packages/edit-site/src/components/global-styles/preview.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,37 @@ const secondFrame = {
4343

4444
const normalizedWidth = 250;
4545

46-
const StylesPreview = ( { label } ) => {
46+
const StylesPreview = ( { label, isFocused } ) => {
47+
const [ fontWeight ] = useStyle( 'typography.fontWeight' );
4748
const [ fontFamily = 'serif' ] = useStyle( 'typography.fontFamily' );
4849
const [ headingFontFamily = fontFamily ] = useStyle(
4950
'elements.h1.typography.fontFamily'
5051
);
52+
const [ headingFontWeight = fontWeight ] = useStyle(
53+
'elements.h1.typography.fontWeight'
54+
);
5155
const [ textColor = 'black' ] = useStyle( 'color.text' );
5256
const [ headingColor = textColor ] = useStyle( 'elements.h1.color.text' );
5357
const [ linkColor = 'blue' ] = useStyle( 'elements.link.color.text' );
5458
const [ backgroundColor = 'white' ] = useStyle( 'color.background' );
5559
const [ gradientValue ] = useStyle( 'color.gradient' );
5660
const [ styles ] = useGlobalStylesOutput();
5761
const disableMotion = useReducedMotion();
58-
const [ isHovered, setIsHovered ] = useState( false );
5962
const [ coreColors ] = useSetting( 'color.palette.core' );
6063
const [ themeColors ] = useSetting( 'color.palette.theme' );
6164
const [ customColors ] = useSetting( 'color.palette.custom' );
65+
const [ isHovered, setIsHovered ] = useState( false );
6266
const [ containerResizeListener, { width } ] = useResizeObserver();
6367
const ratio = width ? width / normalizedWidth : 1;
6468

6569
const paletteColors = ( themeColors ?? [] )
6670
.concat( customColors ?? [] )
6771
.concat( coreColors ?? [] );
6872
const highlightedColors = paletteColors
69-
.filter( ( { color } ) => color !== backgroundColor )
73+
.filter(
74+
// we exclude these two colors because they are already visible in the preview.
75+
( { color } ) => color !== backgroundColor && color !== headingColor
76+
)
7077
.slice( 0, 2 );
7178

7279
return (
@@ -79,6 +86,7 @@ const StylesPreview = ( { label } ) => {
7986
} }
8087
onMouseEnter={ () => setIsHovered( true ) }
8188
onMouseLeave={ () => setIsHovered( false ) }
89+
tabIndex={ -1 }
8290
>
8391
{ containerResizeListener }
8492
<motion.div
@@ -89,7 +97,11 @@ const StylesPreview = ( { label } ) => {
8997
cursor: 'pointer',
9098
} }
9199
initial="start"
92-
animate={ isHovered && ! disableMotion ? 'hover' : 'start' }
100+
animate={
101+
( isHovered || isFocused ) && ! disableMotion
102+
? 'hover'
103+
: 'start'
104+
}
93105
>
94106
<motion.div
95107
variants={ firstFrame }
@@ -111,14 +123,15 @@ const StylesPreview = ( { label } ) => {
111123
fontFamily: headingFontFamily,
112124
fontSize: 65 * ratio,
113125
color: headingColor,
126+
fontWeight: headingFontWeight,
114127
} }
115128
>
116129
Aa
117130
</div>
118131
<VStack spacing={ 2 * ratio }>
119-
{ highlightedColors.map( ( { color } ) => (
132+
{ highlightedColors.map( ( { slug, color } ) => (
120133
<div
121-
key={ color }
134+
key={ slug }
122135
style={ {
123136
height: 30 * ratio,
124137
width: 30 * ratio,
@@ -153,6 +166,7 @@ const StylesPreview = ( { label } ) => {
153166
fontSize: 35 * ratio,
154167
fontFamily: headingFontFamily,
155168
color: headingColor,
169+
fontWeight: headingFontWeight,
156170
lineHeight: '1em',
157171
} }
158172
>

packages/edit-site/src/components/global-styles/screen-style-variations.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import classnames from 'classnames';
99
*/
1010
import { store as coreStore } from '@wordpress/core-data';
1111
import { useSelect } from '@wordpress/data';
12-
import { useMemo, useContext } from '@wordpress/element';
12+
import { useMemo, useContext, useState } from '@wordpress/element';
1313
import { ENTER } from '@wordpress/keycodes';
1414
import {
1515
__experimentalGrid as Grid,
@@ -31,6 +31,7 @@ function compareVariations( a, b ) {
3131
}
3232

3333
function Variation( { variation } ) {
34+
const [ isFocused, setIsFocused ] = useState( false );
3435
const { base, user, setUserConfig } = useContext( GlobalStylesContext );
3536
const context = useMemo( () => {
3637
return {
@@ -78,9 +79,14 @@ function Variation( { variation } ) {
7879
onKeyDown={ selectOnEnter }
7980
tabIndex="0"
8081
aria-label={ variation?.name }
82+
onFocus={ () => setIsFocused( true ) }
83+
onBlur={ () => setIsFocused( false ) }
8184
>
8285
<div className="edit-site-global-styles-variations_item-preview">
83-
<StylesPreview label={ variation?.name } />
86+
<StylesPreview
87+
label={ variation?.name }
88+
isFocused={ isFocused }
89+
/>
8490
</div>
8591
</div>
8692
</GlobalStylesContext.Provider>

0 commit comments

Comments
 (0)