Skip to content

Commit

Permalink
List all the font families from all the theme.json origins in the fon…
Browse files Browse the repository at this point in the history
…t picker (#51488)
  • Loading branch information
matiasbenedetto authored Jun 15, 2023
1 parent 12a01d5 commit 595b1e8
Showing 1 changed file with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,22 @@ export function useHasTypographyPanel( settings ) {
function useHasFontSizeControl( settings ) {
const disableCustomFontSizes = ! settings?.typography?.customFontSize;
const fontSizesPerOrigin = settings?.typography?.fontSizes ?? {};
const fontSizes =
fontSizesPerOrigin?.custom ??
fontSizesPerOrigin?.theme ??
fontSizesPerOrigin.default;
const fontSizes = []
.concat( fontSizesPerOrigin?.custom ?? [] )
.concat( fontSizesPerOrigin?.theme ?? [] )
.concat( fontSizesPerOrigin.default ?? [] );
return !! fontSizes?.length || ! disableCustomFontSizes;
}

function useHasFontFamilyControl( settings ) {
const fontFamiliesPerOrigin = settings?.typography?.fontFamilies;
const fontFamilies =
fontFamiliesPerOrigin?.custom ??
fontFamiliesPerOrigin?.theme ??
fontFamiliesPerOrigin?.default;
const fontFamilies = []
.concat( fontFamiliesPerOrigin?.custom ?? [] )
.concat( fontFamiliesPerOrigin?.theme ?? [] )
.concat( fontFamiliesPerOrigin?.default ?? [] )
.sort( ( a, b ) =>
( a?.name || a?.slug ).localeCompare( b?.name || a?.slug )
);
return !! fontFamilies?.length;
}

Expand Down Expand Up @@ -153,10 +156,10 @@ export default function TypographyPanel( {
// Font Family
const hasFontFamilyEnabled = useHasFontFamilyControl( settings );
const fontFamiliesPerOrigin = settings?.typography?.fontFamilies;
const fontFamilies =
fontFamiliesPerOrigin?.custom ??
fontFamiliesPerOrigin?.theme ??
fontFamiliesPerOrigin?.default;
const fontFamilies = []
.concat( fontFamiliesPerOrigin?.custom ?? [] )
.concat( fontFamiliesPerOrigin?.theme ?? [] )
.concat( fontFamiliesPerOrigin?.default ?? [] );
const fontFamily = decodeValue( inheritedValue?.typography?.fontFamily );
const setFontFamily = ( newValue ) => {
const slug = fontFamilies?.find(
Expand All @@ -179,10 +182,10 @@ export default function TypographyPanel( {
const hasFontSizeEnabled = useHasFontSizeControl( settings );
const disableCustomFontSizes = ! settings?.typography?.customFontSize;
const fontSizesPerOrigin = settings?.typography?.fontSizes ?? {};
const fontSizes =
fontSizesPerOrigin?.custom ??
fontSizesPerOrigin?.theme ??
fontSizesPerOrigin.default;
const fontSizes = []
.concat( fontSizesPerOrigin?.custom ?? [] )
.concat( fontSizesPerOrigin?.theme ?? [] )
.concat( fontSizesPerOrigin.default ?? [] );
const fontSize = decodeValue( inheritedValue?.typography?.fontSize );
const setFontSize = ( newValue, metadata ) => {
const actualValue = !! metadata?.slug
Expand Down

1 comment on commit 595b1e8

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 595b1e8.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5278323926
📝 Reported issues:

Please sign in to comment.