Skip to content
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
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