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 4 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 @@ -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',
chad1008 marked this conversation as resolved.
Show resolved Hide resolved
} ) );

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 @@ -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
chad1008 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { chevronLeft } from '@wordpress/icons';

function TabLayout( { 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
Loading