From 11862cf7fe251ebb64993c76aa828f2557e745ed Mon Sep 17 00:00:00 2001
From: Chad Chadbourne <13856531+chad1008@users.noreply.github.com>
Date: Fri, 8 Dec 2023 09:32:02 -0500
Subject: [PATCH] Components: replace `TabPanel` with `Tabs` in the editor's
`ColorPanel` (#56878)
* replace `TabPanel` with `Tabs`
* implement initial tab to track current value
* focusable false
* defer unlock call
---
.../components/global-styles/color-panel.js | 59 +++++++++++--------
1 file changed, 34 insertions(+), 25 deletions(-)
diff --git a/packages/block-editor/src/components/global-styles/color-panel.js b/packages/block-editor/src/components/global-styles/color-panel.js
index 3b55ec36fc91db..99a5519e9dd008 100644
--- a/packages/block-editor/src/components/global-styles/color-panel.js
+++ b/packages/block-editor/src/components/global-styles/color-panel.js
@@ -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';
@@ -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 );
@@ -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 (
) }
{ tabs.length > 1 && (
-
- { ( tab ) => {
- const selectedTab = tabs.find(
- ( t ) => t.key === tab.name
- );
-
- if ( ! selectedTab ) {
- return null;
- }
-
+
+
+ { tabs.map( ( tab ) => (
+
+ { tab.label }
+
+ ) ) }
+
+
+ { tabs.map( ( tab ) => {
return (
-
+
+
+
);
- } }
-
+ } ) }
+
) }