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 editor's ColorPanel #56878

Merged
merged 4 commits into from
Dec 8, 2023
Merged
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
59 changes: 34 additions & 25 deletions packages/block-editor/src/components/global-styles/color-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import {
__experimentalHStack as HStack,
__experimentalZStack as ZStack,
__experimentalDropdownContentWrapper as DropdownContentWrapper,
TabPanel,
ColorIndicator,
Flex,
FlexItem,
Dropdown,
Button,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { useCallback } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
Expand All @@ -29,6 +29,7 @@ import ColorGradientControl from '../colors-gradients/control';
import { useColorsPerOrigin, useGradientsPerOrigin } from './hooks';
import { getValueFromVariable } from './utils';
import { setImmutably } from '../../utils/object';
import { unlock } from '../../lock-unlock';

export function useHasColorPanel( settings ) {
const hasTextPanel = useHasTextPanel( settings );
Expand Down Expand Up @@ -203,12 +204,11 @@ function ColorPanelDropdown( {
colorGradientControlSettings,
panelId,
} ) {
const tabConfigs = tabs.map( ( { key, label: tabLabel } ) => {
return {
name: key,
title: tabLabel,
};
} );
const currentTab = tabs.find( ( tab ) => tab.userValue !== undefined );
// Unlocking `Tabs` too early causes the `unlock` method to receive an empty
// object, due to circular dependencies.
// See https://github.com/WordPress/gutenberg/issues/52692
const { Tabs } = unlock( componentsPrivateApis );

return (
<ToolsPanelItem
Expand Down Expand Up @@ -258,26 +258,35 @@ function ColorPanelDropdown( {
/>
) }
{ tabs.length > 1 && (
<TabPanel tabs={ tabConfigs }>
{ ( tab ) => {
const selectedTab = tabs.find(
( t ) => t.key === tab.name
);

if ( ! selectedTab ) {
return null;
}

<Tabs initialTabId={ currentTab?.key }>
<Tabs.TabList>
{ tabs.map( ( tab ) => (
<Tabs.Tab
key={ tab.key }
id={ tab.key }
>
{ tab.label }
</Tabs.Tab>
) ) }
</Tabs.TabList>

{ tabs.map( ( tab ) => {
return (
<ColorPanelTab
{ ...selectedTab }
colorGradientControlSettings={
colorGradientControlSettings
}
/>
<Tabs.TabPanel
key={ tab.key }
id={ tab.key }
focusable={ false }
>
<ColorPanelTab
{ ...tab }
colorGradientControlSettings={
colorGradientControlSettings
}
/>
</Tabs.TabPanel>
);
} }
</TabPanel>
} ) }
</Tabs>
) }
</div>
</DropdownContentWrapper>
Expand Down
Loading