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

Components: replace TabPanel with Tabs in the Font Library Modal #57181

Merged
merged 5 commits into from
Jan 4, 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { search, closeSmall } from '@wordpress/icons';
/**
* Internal dependencies
*/
import TabLayout from './tab-layout';
import TabPanelLayout from './tab-panel-layout';
import { FontLibraryContext } from './context';
import FontsGrid from './fonts-grid';
import FontCard from './font-card';
Expand Down Expand Up @@ -156,7 +156,7 @@ function FontCollection( { id } ) {
};

return (
<TabLayout
<TabPanelLayout
title={
! selectedFont ? selectedCollection.name : selectedFont.name
}
Expand Down Expand Up @@ -270,7 +270,7 @@ function FontCollection( { id } ) {
) ) }
</FontsGrid>
) }
</TabLayout>
</TabPanelLayout>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Modal, TabPanel } from '@wordpress/components';
import {
Modal,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { useContext } from '@wordpress/element';

/**
Expand All @@ -12,33 +15,33 @@ import InstalledFonts from './installed-fonts';
import FontCollection from './font-collection';
import UploadFonts from './upload-fonts';
import { FontLibraryContext } from './context';
import { unlock } from '../../../lock-unlock';

const { Tabs } = unlock( componentsPrivateApis );

const DEFAULT_TABS = [
{
name: 'installed-fonts',
id: 'installed-fonts',
title: __( 'Library' ),
className: 'installed-fonts',
},
{
name: 'upload-fonts',
id: 'upload-fonts',
title: __( 'Upload' ),
className: 'upload-fonts',
},
];

const tabsFromCollections = ( collections ) =>
collections.map( ( { id, name } ) => ( {
name: id,
id,
title:
collections.length === 1 && id === 'default-font-collection'
? __( 'Install Fonts' )
: name,
className: 'collection',
} ) );

function FontLibraryModal( {
onRequestClose,
initialTabName = 'installed-fonts',
initialTabId = 'installed-fonts',
} ) {
const { collections } = useContext( FontLibraryContext );

Expand All @@ -54,22 +57,39 @@ function FontLibraryModal( {
isFullScreen
className="font-library-modal"
>
<TabPanel
className="font-library-modal__tab-panel"
initialTabName={ initialTabName }
tabs={ tabs }
>
{ ( tab ) => {
switch ( tab.name ) {
case 'upload-fonts':
return <UploadFonts />;
case 'installed-fonts':
return <InstalledFonts />;
default:
return <FontCollection id={ tab.name } />;
}
} }
</TabPanel>
<div className="font-library-modal__tabs">
<Tabs initialTabId={ initialTabId }>
<Tabs.TabList>
{ tabs.map( ( { id, title } ) => (
<Tabs.Tab key={ id } tabId={ id }>
{ title }
</Tabs.Tab>
) ) }
</Tabs.TabList>
{ tabs.map( ( { id } ) => {
let contents;
switch ( id ) {
case 'upload-fonts':
contents = <UploadFonts />;
break;
case 'installed-fonts':
contents = <InstalledFonts />;
break;
default:
contents = <FontCollection id={ id } />;
}
return (
<Tabs.TabPanel
key={ id }
tabId={ id }
focusable={ false }
>
{ contents }
</Tabs.TabPanel>
);
} ) }
</Tabs>
</div>
</Modal>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
/**
* Internal dependencies
*/
import TabLayout from './tab-layout';
import TabPanelLayout from './tab-panel-layout';
import { FontLibraryContext } from './context';
import FontsGrid from './fonts-grid';
import LibraryFontDetails from './library-font-details';
Expand Down Expand Up @@ -92,7 +92,7 @@ function InstalledFonts() {
}, [ notice ] );

return (
<TabLayout
<TabPanelLayout
title={ libraryFontSelected?.name || '' }
description={ tabDescription }
handleBack={ !! libraryFontSelected && handleUnselectFont }
Expand Down Expand Up @@ -173,7 +173,7 @@ function InstalledFonts() {
handleCancelUninstall={ handleCancelUninstall }
/>
) }
</TabLayout>
</TabPanelLayout>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}
}

.font-library-modal__tab-layout {
.font-library-modal__tabpanel-layout {

main {
padding-bottom: 4rem;
Expand Down Expand Up @@ -75,7 +75,7 @@
padding-bottom: 1rem;
}

.font-library-modal__tab-panel {
.font-library-modal__tabs {
[role="tablist"] {
position: sticky;
top: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ import {
} from '@wordpress/components';
import { chevronLeft } from '@wordpress/icons';

function TabLayout( { title, description, handleBack, children, footer } ) {
function TabPanelLayout( {
title,
description,
handleBack,
children,
footer,
} ) {
return (
<div className="font-library-modal__tab-layout">
<div className="font-library-modal__tabpanel-layout">
<Spacer margin={ 4 } />
<VStack spacing={ 4 } justify="space-between">
<header>
Expand Down Expand Up @@ -47,4 +53,4 @@ function TabLayout( { title, description, handleBack, children, footer } ) {
);
}

export default TabLayout;
export default TabPanelLayout;
Loading