Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global Styles: Display font families from theme, core, and user in font family picker #33889

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion packages/edit-site/src/components/sidebar/typography-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ function useHasLetterSpacingControl( { supports, name } ) {
);
}

function mergeWithoutDuplicateFontFamilies( ...fontLists ) {
const allFonts = fontLists.reduce( ( mergedList, fontList ) => {
return fontList ? mergedList.concat( ...fontList ) : mergedList;
}, [] );

const uniqueFonts = allFonts.reduce( ( uniqueList, font ) => {
if ( ! uniqueList[ font.slug ] ) {
uniqueList[ font.slug ] = font;
}

return uniqueList;
}, {} );

return Object.values( uniqueFonts );
}

export default function TypographyPanel( {
context: { supports, name },
getStyle,
Expand All @@ -61,7 +77,18 @@ export default function TypographyPanel( {
'typography.customFontSize',
name
);
const fontFamilies = useSetting( 'typography.fontFamilies', name );
const coreFontFamilies = useSetting( 'typography.fontFamilies.core', name );
const userFontFamilies = useSetting( 'typography.fontFamilies.user', name );
const themeFontFamilies = useSetting(
'typography.fontFamilies.theme',
name
);
const fontFamilies = mergeWithoutDuplicateFontFamilies(
themeFontFamilies,
userFontFamilies,
coreFontFamilies
);
Comment on lines +86 to +90
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I think we can use _.unionBy(themeFontFamilies, userFontFamilies, coreFontFamilies, 'slug'); here.


const hasFontStyles =
useSetting( 'typography.customFontStyle', name ) &&
supports.includes( 'fontStyle' );
Expand Down