Skip to content

Commit

Permalink
Font Library: Add heading to user font and group fonts in lists
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed Feb 14, 2024
1 parent 24fcc49 commit b68a6f1
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,29 @@ function FontCollection( { slug } ) {
) }

{ ! renderConfirmDialog && ! selectedFont && (
<div className="font-library-modal__fonts-grid__main">
/*
* Disable reason: The `list` ARIA role is redundant but
* Safari+VoiceOver won't announce the list otherwise.
*/
/* eslint-disable jsx-a11y/no-redundant-roles */
<ul role="list" className="font-library-modal__fonts-list">
{ items.map( ( font ) => (
<FontCard
<li
key={ font.font_family_settings.slug }
font={ font.font_family_settings }
onClick={ () => {
setSelectedFont( font.font_family_settings );
} }
/>
className="font-library-modal__fonts-list-item"
>
<FontCard
font={ font.font_family_settings }
onClick={ () => {
setSelectedFont(
font.font_family_settings
);
} }
/>
</li>
) ) }
</div>
</ul>
/* eslint-enable jsx-a11y/no-redundant-roles */
) }
</TabPanelLayout>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import { __ } from '@wordpress/i18n';
import { useContext, useEffect, useState } from '@wordpress/element';
import {
privateApis as componentsPrivateApis,
__experimentalHStack as HStack,
__experimentalSpacer as Spacer,
__experimentalText as Text,
Button,
Spinner,
FlexItem,
__experimentalHStack as HStack,
__experimentalVStack as VStack,
__experimentalSpacer as Spacer,
} from '@wordpress/components';

/**
Expand Down Expand Up @@ -114,47 +113,72 @@ function InstalledFonts() {

{ ! libraryFontSelected && (
<>
{ isResolvingLibrary && (
<FlexItem>
<Spacer margin={ 2 } />
<Spinner />
<Spacer margin={ 2 } />
</FlexItem>
) }
{ baseCustomFonts.length > 0 && (
<>
{ baseCustomFonts.map( ( font ) => (
<LibraryFontCard
font={ font }
key={ font.slug }
onClick={ () => {
handleSelectFont( font );
} }
/>
) ) }
<Spacer margin={ 8 } />
</>
) }

{ baseThemeFonts.length > 0 && (
<>
<Text className="font-library-modal__subtitle">
{ __( 'Theme Fonts' ) }
</Text>

<Spacer margin={ 2 } />
{ baseThemeFonts.map( ( font ) => (
<LibraryFontCard
font={ font }
key={ font.slug }
onClick={ () => {
handleSelectFont( font );
} }
/>
) ) }
</>
) }
<Spacer margin={ 16 } />
<VStack spacing="4">
{ isResolvingLibrary && <Spinner /> }
{ baseCustomFonts.length > 0 && (
<VStack>
<h2 className="font-library-modal__fonts-title">
{ __( 'User Fonts' ) }
</h2>
{ /*
* Disable reason: The `list` ARIA role is redundant but
* Safari+VoiceOver won't announce the list otherwise.
*/
/* eslint-disable jsx-a11y/no-redundant-roles */ }
<ul
role="list"
className="font-library-modal__fonts-list"
>
{ baseCustomFonts.map( ( font ) => (
<li
key={ font.slug }
className="font-library-modal__fonts-list-item"
>
<LibraryFontCard
font={ font }
onClick={ () => {
handleSelectFont( font );
} }
/>
</li>
) ) }
</ul>
{ /* eslint-enable jsx-a11y/no-redundant-roles */ }
</VStack>
) }
{ baseThemeFonts.length > 0 && (
<VStack>
<h2 className="font-library-modal__fonts-title">
{ __( 'Theme Fonts' ) }
</h2>
{ /*
* Disable reason: The `list` ARIA role is redundant but
* Safari+VoiceOver won't announce the list otherwise.
*/
/* eslint-disable jsx-a11y/no-redundant-roles */ }
<ul
role="list"
className="font-library-modal__fonts-list"
>
{ baseThemeFonts.map( ( font ) => (
<li
key={ font.slug }
className="font-library-modal__fonts-list-item"
>
<LibraryFontCard
font={ font }
onClick={ () => {
handleSelectFont( font );
} }
/>
</li>
) ) }
</ul>
{ /* eslint-enable jsx-a11y/no-redundant-roles */ }
</VStack>
) }
</VStack>
<Spacer paddingY={ 8 } marginBottom={ 0 } />
</>
) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
.components-modal__content {
padding-top: 0;
}

.font-library-modal__subtitle {
text-transform: uppercase;
font-weight: 500;
font-size: 11px;
}
}

.font-library-modal__tabpanel-layout {
Expand All @@ -40,12 +34,29 @@
margin-bottom: 0;
}

.font-library-modal__fonts-title {
text-transform: uppercase;
font-size: 11px;
font-weight: 600;
margin-top: 0;
margin-bottom: 0;
}

.font-library-modal__fonts-list {
margin-top: 0;
margin-bottom: 0;
}

.font-library-modal__fonts-list-item {
margin-top: -1px; /* To collapse the margin with the previous element */
margin-bottom: 0;
}

.font-library-modal__font-card {
border: 1px solid $gray-200;
width: 100%;
height: auto;
padding: $grid-unit-20;
margin-top: -1px; /* To collapse the margin with the previous element */

.font-library-modal__font-card__name {
font-weight: bold;
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/site-editor/font-library.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ test.describe( 'Font Library', () => {
.click();
await expect( page.getByRole( 'dialog' ) ).toBeVisible();
await expect(
page.getByRole( 'heading', { name: 'Fonts' } )
page.getByRole( 'heading', { name: 'Fonts', exact: true } )
).toBeVisible();
} );

Expand Down

0 comments on commit b68a6f1

Please sign in to comment.