Skip to content

Commit

Permalink
Components: replace TabPanel with Tabs in the editor's `ColorGrad…
Browse files Browse the repository at this point in the history
…ientControl` (#56351)

Co-authored-by: Marco Ciampini <[email protected]>
  • Loading branch information
chad1008 and ciampo authored Dec 6, 2023
1 parent a2d1d37 commit 29e52a1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 36 deletions.
79 changes: 49 additions & 30 deletions packages/block-editor/src/components/colors-gradients/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ import { __ } from '@wordpress/i18n';
import {
BaseControl,
__experimentalVStack as VStack,
TabPanel,
ColorPalette,
GradientPicker,
privateApis as componentsPrivateApis,
} from '@wordpress/components';

/**
* Internal dependencies
*/
import { useSettings } from '../use-settings';
import { unlock } from '../../lock-unlock';

const colorsAndGradientKeys = [
'colors',
Expand All @@ -27,18 +28,7 @@ const colorsAndGradientKeys = [
'disableCustomGradients',
];

const TAB_COLOR = {
name: 'color',
title: __( 'Solid' ),
value: 'color',
};
const TAB_GRADIENT = {
name: 'gradient',
title: __( 'Gradient' ),
value: 'gradient',
};

const TABS_SETTINGS = [ TAB_COLOR, TAB_GRADIENT ];
const TAB_IDS = { color: 'color', gradient: 'gradient' };

function ColorGradientControlInner( {
colors,
Expand Down Expand Up @@ -69,7 +59,7 @@ function ColorGradientControlInner( {
}

const tabPanels = {
[ TAB_COLOR.value ]: (
[ TAB_IDS.color ]: (
<ColorPalette
value={ colorValue }
onChange={
Expand All @@ -89,7 +79,7 @@ function ColorGradientControlInner( {
headingLevel={ headingLevel }
/>
),
[ TAB_GRADIENT.value ]: (
[ TAB_IDS.gradient ]: (
<GradientPicker
__nextHasNoMargin
value={ gradientValue }
Expand Down Expand Up @@ -117,6 +107,11 @@ function ColorGradientControlInner( {
</div>
);

// 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 (
<BaseControl
__nextHasNoMarginBottom
Expand All @@ -137,22 +132,46 @@ function ColorGradientControlInner( {
</legend>
) }
{ canChooseAColor && canChooseAGradient && (
<TabPanel
className="block-editor-color-gradient-control__tabs"
tabs={ TABS_SETTINGS }
initialTabName={
gradientValue
? TAB_GRADIENT.value
: !! canChooseAColor && TAB_COLOR.value
}
>
{ ( tab ) => renderPanelType( tab.value ) }
</TabPanel>
<div>
<Tabs
initialTabId={
gradientValue
? TAB_IDS.gradient
: !! canChooseAColor && TAB_IDS.color
}
>
<Tabs.TabList>
<Tabs.Tab id={ TAB_IDS.color }>
{ __( 'Solid' ) }
</Tabs.Tab>
<Tabs.Tab id={ TAB_IDS.gradient }>
{ __( 'Gradient' ) }
</Tabs.Tab>
</Tabs.TabList>
<Tabs.TabPanel
id={ TAB_IDS.color }
className={
'block-editor-color-gradient-control__panel'
}
focusable={ false }
>
{ tabPanels.color }
</Tabs.TabPanel>
<Tabs.TabPanel
id={ TAB_IDS.gradient }
className={
'block-editor-color-gradient-control__panel'
}
focusable={ false }
>
{ tabPanels.gradient }
</Tabs.TabPanel>
</Tabs>
</div>
) }
{ ! canChooseAGradient &&
renderPanelType( TAB_COLOR.value ) }
{ ! canChooseAColor &&
renderPanelType( TAB_GRADIENT.value ) }

{ ! canChooseAGradient && renderPanelType( TAB_IDS.color ) }
{ ! canChooseAColor && renderPanelType( TAB_IDS.gradient ) }
</VStack>
</fieldset>
</BaseControl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ $swatch-gap: 12px;
min-width: 0;
}

.block-editor-color-gradient-control__tabs {
.block-editor-color-gradient-control__panel {
padding: $grid-unit-20;
}
}

.block-editor-panel-color-gradient-settings.block-editor-panel-color-gradient-settings {
&,
& > div:not(:first-of-type) {
Expand Down

1 comment on commit 29e52a1

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 29e52a1.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7116450811
📝 Reported issues:

Please sign in to comment.