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

Use NavigatorProvider in Font Library Modal #59036

Merged
merged 15 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
* Internal dependencies
*/
import { getFontFaceVariantName } from './utils';
import FontFaceDemo from './font-demo';
import FontDemo from './font-demo';
import { unlock } from '../../../lock-unlock';

function CollectionFontVariant( {
Expand All @@ -35,7 +35,7 @@ function CollectionFontVariant( {
);

return (
<div className="font-library-modal__library-font-variant">
<div className="font-library-modal__font-card">
<Flex justify="flex-start" align="center" gap="1rem">
<CheckboxControl
checked={ selected }
Expand All @@ -44,8 +44,8 @@ function CollectionFontVariant( {
id={ checkboxId }
/>
<label htmlFor={ checkboxId }>
<FontFaceDemo
fontFace={ face }
<FontDemo
font={ face }
text={ displayName }
onClick={ handleToggleActivation }
/>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { _n, sprintf } from '@wordpress/i18n';
import {
__experimentalUseNavigator as useNavigator,
__experimentalText as Text,
Button,
Flex,
Expand All @@ -14,46 +15,30 @@ import {
* Internal dependencies
*/
import FontDemo from './font-demo';
import { getFamilyPreviewStyle } from './utils/preview-styles';
import { chevronRight } from '@wordpress/icons';

function FontCard( { font, onClick, variantsText } ) {
const fakeFontFace = {
fontStyle: 'normal',
fontWeight: '400',
fontFamily: font.fontFamily,
fake: true,
};

const displayFontFace =
font.fontFace && font.fontFace.length
? font?.fontFace?.find(
( face ) =>
face.fontStyle === 'normal' && face.fontWeight === '400'
) || font.fontFace[ 0 ]
: fakeFontFace;

const demoStyle = getFamilyPreviewStyle( font );

function FontCard( { font, onClick, variantsText, navigatorPath } ) {
const variantsCount = font.fontFace?.length || 1;

const style = {
cursor: !! onClick ? 'pointer' : 'default',
};

const navigator = useNavigator();

return (
<Button
onClick={ onClick }
onClick={ () => {
onClick();
if ( navigatorPath ) {
navigator.goTo( navigatorPath );
}
} }
style={ style }
className="font-library-modal__font-card"
>
<Flex justify="space-between" wrap={ false }>
<FontDemo
customPreviewUrl={ font.preview }
fontFace={ displayFontFace }
text={ font.name }
style={ demoStyle }
/>
<FontDemo font={ font } />
<Flex justify="flex-end">
<FlexItem>
<Text className="font-library-modal__font-card__count">
Expand Down
Loading
Loading