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 Block Inspector #56995

Merged
merged 4 commits into from
Dec 19, 2023
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
@@ -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
Loading