Skip to content

Commit

Permalink
Components: replace TabPanel with Tabs in the Block Inspector (#5…
Browse files Browse the repository at this point in the history
…6995)

* implement `Tabs`

* focusable false

* add `show-icon-labels` support

* address feedback
  • Loading branch information
chad1008 authored and artemiomorales committed Jan 4, 2024
1 parent ac57369 commit 8a64580
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/**
* WordPress dependencies
*/
import { TabPanel } from '@wordpress/components';
import {
Button,
privateApis as componentsPrivateApis,
} from '@wordpress/components';

/**
* Internal dependencies
Expand All @@ -11,6 +14,9 @@ import SettingsTab from './settings-tab';
import StylesTab from './styles-tab';
import InspectorControls from '../inspector-controls';
import useIsListViewTabDisabled from './use-is-list-view-tab-disabled';
import { unlock } from '../../lock-unlock';

const { Tabs } = unlock( componentsPrivateApis );

export default function InspectorControlsTabs( {
blockName,
Expand All @@ -26,34 +32,39 @@ export default function InspectorControlsTabs( {
const initialTabName = ! useIsListViewTabDisabled( blockName )
? TAB_LIST_VIEW.name
: undefined;
return (
<TabPanel
className="block-editor-block-inspector__tabs"
tabs={ tabs }
initialTabName={ initialTabName }
key={ clientId }
>
{ ( tab ) => {
if ( tab.name === TAB_SETTINGS.name ) {
return (
<SettingsTab showAdvancedControls={ !! blockName } />
);
}

if ( tab.name === TAB_STYLES.name ) {
return (
<StylesTab
blockName={ blockName }
clientId={ clientId }
hasBlockStyles={ hasBlockStyles }
return (
<div className="block-editor-block-inspector__tabs">
<Tabs initialTabId={ initialTabName } key={ clientId }>
<Tabs.TabList>
{ tabs.map( ( tab ) => (
<Tabs.Tab
key={ tab.name }
tabId={ tab.name }
render={
<Button
icon={ tab.icon }
label={ tab.title }
className={ tab.className }
/>
}
/>
);
}

if ( tab.name === TAB_LIST_VIEW.name ) {
return <InspectorControls.Slot group="list" />;
}
} }
</TabPanel>
) ) }
</Tabs.TabList>
<Tabs.TabPanel tabId={ TAB_SETTINGS.name } focusable={ false }>
<SettingsTab showAdvancedControls={ !! blockName } />
</Tabs.TabPanel>
<Tabs.TabPanel tabId={ TAB_STYLES.name } focusable={ false }>
<StylesTab
blockName={ blockName }
clientId={ clientId }
hasBlockStyles={ hasBlockStyles }
/>
</Tabs.TabPanel>
<Tabs.TabPanel tabId={ TAB_LIST_VIEW.name } focusable={ false }>
<InspectorControls.Slot group="list" />
</Tabs.TabPanel>
</Tabs>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.show-icon-labels {
.block-editor-block-inspector__tabs .components-tab-panel__tabs {
.block-editor-block-inspector__tabs [role="tablist"] {
.components-button.has-icon {
// Hide the button icons when labels are set to display...
svg {
Expand Down

0 comments on commit 8a64580

Please sign in to comment.