Skip to content

Commit

Permalink
update tab-panel component with tabs component
Browse files Browse the repository at this point in the history
  • Loading branch information
madhusudhand committed Nov 7, 2023
1 parent ce3ef3e commit f5dfaa2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
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,6 +15,9 @@ 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 = [
{
Expand Down Expand Up @@ -54,22 +60,26 @@ 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>
<Tabs initialTabId={ initialTabName }>
<Tabs.TabList className="font-library-modal__tab-list">
{ tabs.map( ( tab ) => (
<Tabs.Tab key={ tab.name } id={ tab.name }>
{ tab.title }
</Tabs.Tab>
) ) }
</Tabs.TabList>
<Tabs.TabPanel id={ 'installed-fonts' }>
<InstalledFonts />
</Tabs.TabPanel>
<Tabs.TabPanel id={ 'upload-fonts' }>
<UploadFonts />
</Tabs.TabPanel>
{ tabsFromCollections( collections || [] ).map( ( tab ) => (
<Tabs.TabPanel key={ tab.name } id={ tab.name }>
<FontCollection id={ tab.name } />
</Tabs.TabPanel>
) ) }
</Tabs>
</Modal>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
padding-bottom: 1rem;
}

.font-library-modal__tab-panel {
[role="tablist"] {
.font-library-modal__tab-list {
&[role="tablist"] {
position: sticky;
top: 0;
width: calc(100% + 64px);
Expand Down

0 comments on commit f5dfaa2

Please sign in to comment.