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 1 commit
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
26 changes: 25 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,19 @@ function useHasLetterSpacingControl( { supports, name } ) {
);
}

function mergeWithoutDuplicateFontFamilies( firstList, secondList ) {
const fontFamilies = [ ...firstList, ...secondList ];
const mergedFonts = fontFamilies.reduce( ( mergedList, font ) => {
if ( ! mergedList[ font.slug ] ) {
mergedList[ font.slug ] = font;
}

return mergedList;
}, {} );

return Object.values( mergedFonts );
}

export default function TypographyPanel( {
context: { supports, name },
getStyle,
Expand All @@ -61,7 +74,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