-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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: Add a typesets section to Typography #62539
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f14e4c5
Global Styles: Add a typesets section to Typography
scruffian 4a6d43f
update typesets to contain font families
scruffian e147702
add variation name to typesets
scruffian 79868db
add variation name to typesets
scruffian 883f52a
use variation titles for typeset button
scruffian 31a0996
Update packages/edit-site/src/components/global-styles/typeset-button.js
scruffian de2dd63
Update packages/edit-site/src/components/global-styles/typeset-button.js
scruffian 3b6000a
Update packages/edit-site/src/components/global-styles/typeset-button.js
scruffian 312dc1f
Add fontLibraryEnabled to ScreenTypography
mikachan 8566c93
Remove window.__experimentalDisableFontLibrary
mikachan 6d65aab
Check for themeFontFamilies and customFontFamilies
mikachan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
packages/edit-site/src/components/global-styles/screen-typeset.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* 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 FontFamilies from './font-families'; | ||
|
||
function ScreenTypeset() { | ||
const fontLibraryEnabled = useSelect( | ||
( select ) => | ||
select( editorStore ).getEditorSettings().fontLibraryEnabled, | ||
[] | ||
); | ||
|
||
return ( | ||
<> | ||
<ScreenHeader | ||
title={ __( 'Typesets' ) } | ||
description={ __( | ||
'Fonts and typographic styling applied across the site.' | ||
) } | ||
/> | ||
<div className="edit-site-global-styles-screen"> | ||
<VStack spacing={ 7 }> | ||
<TypographyVariations /> | ||
|
||
{ fontLibraryEnabled && <FontFamilies /> } | ||
</VStack> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
export default ScreenTypeset; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
packages/edit-site/src/components/global-styles/typeset-button.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { isRTL, __ } from '@wordpress/i18n'; | ||
import { | ||
__experimentalItemGroup as ItemGroup, | ||
__experimentalVStack as VStack, | ||
__experimentalHStack as HStack, | ||
FlexItem, | ||
} from '@wordpress/components'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; | ||
import { privateApis as editorPrivateApis } from '@wordpress/editor'; | ||
import { useMemo, useContext } from '@wordpress/element'; | ||
import { Icon, chevronLeft, chevronRight } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import FontLibraryProvider from './font-library-modal/context'; | ||
import { getFontFamilies } from './utils'; | ||
import { NavigationButtonAsItem } from './navigation-button'; | ||
import Subtitle from './subtitle'; | ||
import { unlock } from '../../lock-unlock'; | ||
import { filterObjectByProperties } from '../../hooks/use-theme-style-variations/use-theme-style-variations-by-property'; | ||
|
||
const { GlobalStylesContext } = unlock( blockEditorPrivateApis ); | ||
const { mergeBaseAndUserConfigs } = unlock( editorPrivateApis ); | ||
|
||
function TypesetButton() { | ||
const { base } = useContext( GlobalStylesContext ); | ||
const { user: userConfig } = useContext( GlobalStylesContext ); | ||
const config = mergeBaseAndUserConfigs( base, userConfig ); | ||
const allFontFamilies = getFontFamilies( config ); | ||
const hasFonts = | ||
allFontFamilies.filter( ( font ) => font !== null ).length > 0; | ||
const variations = useSelect( ( select ) => { | ||
return select( | ||
coreStore | ||
).__experimentalGetCurrentThemeGlobalStylesVariations(); | ||
}, [] ); | ||
const userTypographyConfig = filterObjectByProperties( | ||
userConfig, | ||
'typography' | ||
); | ||
|
||
const title = useMemo( () => { | ||
if ( Object.keys( userTypographyConfig ).length === 0 ) { | ||
return __( 'Default' ); | ||
} | ||
const activeVariation = variations.find( ( variation ) => { | ||
return ( | ||
JSON.stringify( | ||
filterObjectByProperties( variation, 'typography' ) | ||
) === JSON.stringify( userTypographyConfig ) | ||
); | ||
} ); | ||
if ( activeVariation ) { | ||
return activeVariation.title; | ||
} | ||
return allFontFamilies.map( ( font ) => font?.name ).join( ', ' ); | ||
}, [ userTypographyConfig, variations ] ); | ||
|
||
return ( | ||
hasFonts && ( | ||
<VStack spacing={ 2 }> | ||
<HStack justify="space-between"> | ||
<Subtitle level={ 3 }>{ __( 'Typeset' ) }</Subtitle> | ||
</HStack> | ||
<ItemGroup isBordered isSeparated> | ||
<NavigationButtonAsItem | ||
path="/typography/typeset" | ||
aria-label={ __( 'Typeset' ) } | ||
> | ||
<HStack direction="row"> | ||
<FlexItem>{ title }</FlexItem> | ||
<Icon | ||
icon={ isRTL() ? chevronLeft : chevronRight } | ||
/> | ||
</HStack> | ||
</NavigationButtonAsItem> | ||
</ItemGroup> | ||
</VStack> | ||
) | ||
); | ||
} | ||
|
||
export default ( { ...props } ) => ( | ||
<FontLibraryProvider> | ||
<TypesetButton { ...props } /> | ||
</FontLibraryProvider> | ||
); |
73 changes: 73 additions & 0 deletions
73
packages/edit-site/src/components/global-styles/typeset.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
__experimentalItemGroup as ItemGroup, | ||
__experimentalVStack as VStack, | ||
__experimentalHStack as HStack, | ||
} from '@wordpress/components'; | ||
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; | ||
import { privateApis as editorPrivateApis } from '@wordpress/editor'; | ||
import { useContext } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import FontLibraryProvider, { | ||
FontLibraryContext, | ||
} from './font-library-modal/context'; | ||
import FontLibraryModal from './font-library-modal'; | ||
import FontFamilyItem from './font-family-item'; | ||
import Subtitle from './subtitle'; | ||
import { getFontFamilies } from './utils'; | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
const { GlobalStylesContext } = unlock( blockEditorPrivateApis ); | ||
const { mergeBaseAndUserConfigs } = unlock( editorPrivateApis ); | ||
|
||
function Typesets() { | ||
const { modalTabOpen, setModalTabOpen } = useContext( FontLibraryContext ); | ||
const { base } = useContext( GlobalStylesContext ); | ||
const { user: userConfig } = useContext( GlobalStylesContext ); | ||
const config = mergeBaseAndUserConfigs( base, userConfig ); | ||
const allFontFamilies = getFontFamilies( config ); | ||
const hasFonts = | ||
allFontFamilies.filter( ( font ) => font !== null ).length > 0; | ||
|
||
return ( | ||
hasFonts && ( | ||
<> | ||
{ !! modalTabOpen && ( | ||
<FontLibraryModal | ||
onRequestClose={ () => setModalTabOpen( null ) } | ||
defaultTabId={ modalTabOpen } | ||
/> | ||
) } | ||
Comment on lines
+41
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking these may work better below the typesets, so when a typeset has more fonts it does not displace the typesets UI. And you decide on a typeset here, not necessarily the fonts for each. |
||
|
||
<VStack spacing={ 2 }> | ||
<HStack justify="space-between"> | ||
<Subtitle level={ 3 }>{ __( 'Fonts' ) }</Subtitle> | ||
</HStack> | ||
<ItemGroup isBordered isSeparated> | ||
{ allFontFamilies.map( | ||
( font ) => | ||
font && ( | ||
<FontFamilyItem | ||
key={ font.slug } | ||
font={ font } | ||
/> | ||
) | ||
) } | ||
</ItemGroup> | ||
</VStack> | ||
</> | ||
) | ||
); | ||
} | ||
|
||
export default ( { ...props } ) => ( | ||
<FontLibraryProvider> | ||
<Typesets { ...props } /> | ||
</FontLibraryProvider> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For here, and line 45, let's use "Fonts" as these are the fonts applied within the typeset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@richtabor Has this change been covered? Was it to change "Typeset" to "Fonts"?