-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Global Styles: Add a typesets section to Typography
Only show typesets if there are fonts
- Loading branch information
Showing
5 changed files
with
175 additions
and
2 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
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,33 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { __experimentalVStack as VStack } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import TypographyVariations from './variations/variations-typography'; | ||
import ScreenHeader from './header'; | ||
import Typeset from './typeset'; | ||
|
||
function ScreenTypeset() { | ||
return ( | ||
<> | ||
<ScreenHeader | ||
title={ __( 'Typesets' ) } | ||
description={ __( | ||
'Font pairings and typographic styling applied across the site.' | ||
) } | ||
/> | ||
<div className="edit-site-global-styles-screen"> | ||
<VStack spacing={ 7 }> | ||
<Typeset /> | ||
<TypographyVariations title={ __( 'Presets' ) } /> | ||
</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
68 changes: 68 additions & 0 deletions
68
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,68 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { isRTL, __ } from '@wordpress/i18n'; | ||
import { | ||
__experimentalItemGroup as ItemGroup, | ||
__experimentalVStack as VStack, | ||
__experimentalHStack as HStack, | ||
FlexItem, | ||
} from '@wordpress/components'; | ||
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; | ||
import { privateApis as editorPrivateApis } from '@wordpress/editor'; | ||
import { 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'; | ||
|
||
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; | ||
|
||
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> | ||
{ allFontFamilies | ||
.map( ( font ) => font.name ) | ||
.join( ', ' ) } | ||
</FlexItem> | ||
<Icon | ||
icon={ isRTL() ? chevronLeft : chevronRight } | ||
/> | ||
</HStack> | ||
</NavigationButtonAsItem> | ||
</ItemGroup> | ||
</VStack> | ||
) | ||
); | ||
} | ||
|
||
export default ( { ...props } ) => ( | ||
<FontLibraryProvider> | ||
<TypesetButton { ...props } /> | ||
</FontLibraryProvider> | ||
); |
67 changes: 67 additions & 0 deletions
67
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,67 @@ | ||
/** | ||
* 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 } | ||
/> | ||
) } | ||
|
||
<VStack spacing={ 2 }> | ||
<HStack justify="space-between"> | ||
<Subtitle level={ 3 }>{ __( 'Typeset' ) }</Subtitle> | ||
</HStack> | ||
<ItemGroup isBordered isSeparated> | ||
{ allFontFamilies.map( ( 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