Skip to content

Commit

Permalink
Fixed a bug to better support BOTH font FAMILIES as well as font FACE…
Browse files Browse the repository at this point in the history
…S in the Font Demo component.
  • Loading branch information
pbking committed Feb 21, 2024
1 parent 5e01a2d commit 196a4bf
Showing 1 changed file with 9 additions and 1 deletion.
Expand Up @@ -23,6 +23,12 @@ function getPreviewUrl( fontFace ) {
}

function getDisplayFontFace( font ) {
// if this IS a font face return it
if ( font.fontStyle || font.fontWeight ) {
return font;
}
// if this is a font family with a collection of font faces
// return the first one that is normal and 400 OR just the first one
if ( font.fontFace && font.fontFace.length ) {
return (
font.fontFace.find(
Expand All @@ -31,6 +37,8 @@ function getDisplayFontFace( font ) {
) || font.fontFace[ 0 ]
);
}
// This must be a font family with no font faces
// return a fake font face
return {
fontStyle: 'normal',
fontWeight: '400',
Expand Down Expand Up @@ -60,8 +68,8 @@ function FontDemo( { font, text } ) {
fontSize: '18px',
lineHeight: 1,
opacity: isAssetLoaded ? '1' : '0',
...faceStyles,
...style,
...faceStyles,
};

useEffect( () => {
Expand Down

0 comments on commit 196a4bf

Please sign in to comment.