Skip to content

Commit

Permalink
update typesets to contain font families
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed Jun 19, 2024
1 parent fc682e8 commit 09b9d32
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
18 changes: 14 additions & 4 deletions packages/edit-site/src/components/global-styles/screen-typeset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,38 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';
import { __experimentalVStack as VStack } from '@wordpress/components';

/**
* Internal dependencies
*/
import TypographyVariations from './variations/variations-typography';
import ScreenHeader from './header';
import Typeset from './typeset';
import FontFamilies from './font-families';

function ScreenTypeset() {
const fontLibraryEnabled = useSelect(
( select ) =>
select( editorStore ).getEditorSettings().fontLibraryEnabled,
[]
);

return (
<>
<ScreenHeader
title={ __( 'Typesets' ) }
description={ __(
'Font pairings and typographic styling applied across the site.'
'Fonts and typographic styling applied across the site.'
) }
/>
<div className="edit-site-global-styles-screen">
<VStack spacing={ 7 }>
<Typeset />
<TypographyVariations title={ __( 'Presets' ) } />
<TypographyVariations />

{ ! window.__experimentalDisableFontLibrary &&
fontLibraryEnabled && <FontFamilies /> }
</VStack>
</div>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,15 @@
*/
import { __ } from '@wordpress/i18n';
import { __experimentalVStack as VStack } from '@wordpress/components';
import { store as editorStore } from '@wordpress/editor';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import TypographyElements from './typography-elements';
import FontFamilies from './font-families';
import ScreenHeader from './header';
import TypesetButton from './typeset-button';

function ScreenTypography() {
const fontLibraryEnabled = useSelect(
( select ) =>
select( editorStore ).getEditorSettings().fontLibraryEnabled,
[]
);

return (
<>
<ScreenHeader
Expand All @@ -32,8 +23,6 @@ function ScreenTypography() {
<div className="edit-site-global-styles-screen">
<VStack spacing={ 7 }>
<TypesetButton />
{ ! window.__experimentalDisableFontLibrary &&
fontLibraryEnabled && <FontFamilies /> }
<TypographyElements />
</VStack>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function TypesetButton() {
<HStack direction="row">
<FlexItem>
{ allFontFamilies
.map( ( font ) => font.name )
.map( ( font ) => font?.name )
.join( ', ' ) }
</FlexItem>
<Icon
Expand Down
14 changes: 10 additions & 4 deletions packages/edit-site/src/components/global-styles/typeset.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@ function Typesets() {

<VStack spacing={ 2 }>
<HStack justify="space-between">
<Subtitle level={ 3 }>{ __( 'Typeset' ) }</Subtitle>
<Subtitle level={ 3 }>{ __( 'Fonts' ) }</Subtitle>
</HStack>
<ItemGroup isBordered isSeparated>
{ allFontFamilies.map( ( font ) => (
<FontFamilyItem key={ font.slug } font={ font } />
) ) }
{ allFontFamilies.map(
( font ) =>
font && (
<FontFamilyItem
key={ font.slug }
font={ font }
/>
)
) }
</ItemGroup>
</VStack>
</>
Expand Down
10 changes: 9 additions & 1 deletion packages/edit-site/src/components/global-styles/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ function getFontFamilyFromSetting( fontFamilies, setting ) {
}

export function getFontFamilies( themeJson ) {
const fontFamilies = themeJson?.settings?.typography?.fontFamilies?.theme; // TODO this could not be under theme.
const themeFontFamilies =
themeJson?.settings?.typography?.fontFamilies?.theme;
const customFontFamilies =
themeJson?.settings?.typography?.fontFamilies?.custom;

let fontFamilies = themeFontFamilies;
if ( customFontFamilies ) {
fontFamilies = [ ...themeFontFamilies, ...customFontFamilies ];
}
const bodyFontFamilySetting = themeJson?.styles?.typography?.fontFamily;
const bodyFontFamily = getFontFamilyFromSetting(
fontFamilies,
Expand Down

0 comments on commit 09b9d32

Please sign in to comment.