Skip to content
58 changes: 32 additions & 26 deletions packages/block-editor/src/components/global-styles/color-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,13 @@ export function useHasBackgroundColorPanel( settings ) {
);
}

function ColorToolsPanel( {
export function ColorToolsPanel( {
resetAllFilter,
onChange,
value,
panelId,
children,
label,
} ) {
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
const resetAll = () => {
Expand All @@ -126,7 +127,7 @@ function ColorToolsPanel( {

return (
<ToolsPanel
label={ __( 'Elements' ) }
label={ label || __( 'Elements' ) }
resetAll={ resetAll }
panelId={ panelId }
hasInnerWrapper
Expand Down Expand Up @@ -326,6 +327,7 @@ export default function ColorPanel( {
settings,
panelId,
defaultControls = DEFAULT_CONTROLS,
label,
children,
} ) {
const colors = useColorsPerOrigin( settings );
Expand Down Expand Up @@ -511,31 +513,34 @@ export default function ColorPanel( {
},
];

const resetAllFilter = useCallback( ( previousValue ) => {
return {
...previousValue,
color: undefined,
elements: {
...previousValue?.elements,
link: {
...previousValue?.elements?.link,
color: undefined,
':hover': {
const resetAllFilter = useCallback(
( previousValue ) => {
return {
...previousValue,
color: undefined,
elements: {
...previousValue?.elements,
link: {
...previousValue?.elements?.link,
color: undefined,
},
},
...elements.reduce( ( acc, element ) => {
return {
...acc,
[ element.name ]: {
...previousValue?.elements?.[ element.name ],
':hover': {
color: undefined,
},
};
}, {} ),
},
};
}, [] );
},
...elements.reduce( ( acc, element ) => {
return {
...acc,
[ element.name ]: {
...previousValue?.elements?.[ element.name ],
color: undefined,
},
};
}, {} ),
},
};
},
[ elements ]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Linting

);

const items = [
showTextPanel && {
Expand Down Expand Up @@ -606,7 +611,7 @@ export default function ColorPanel( {
},
].filter( Boolean );

elements.forEach( ( { name, label, showPanel } ) => {
elements.forEach( ( { name, label: elementLabel, showPanel } ) => {
if ( ! showPanel ) {
return;
}
Expand Down Expand Up @@ -680,7 +685,7 @@ export default function ColorPanel( {

items.push( {
key: name,
label,
label: elementLabel,
hasValue: hasElement,
resetValue: resetElement,
isShownByDefault: defaultControls[ name ],
Expand Down Expand Up @@ -731,6 +736,7 @@ export default function ColorPanel( {
value={ value }
onChange={ onChange }
panelId={ panelId }
label={ label }
>
{ items.map( ( item ) => {
const { key, ...restItem } = item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default function InspectorControlsTabs( {
clientId={ clientId }
hasBlockStyles={ hasBlockStyles }
isSectionBlock={ isSectionBlock }
contentClientIds={ contentClientIds }
/>
</Tabs.TabPanel>
<Tabs.TabPanel tabId={ TAB_CONTENT.name } focusable={ false }>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,69 @@
*/
import { PanelBody } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useDispatch, useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import BlockStyles from '../block-styles';
import InspectorControls from '../inspector-controls';
import { useBorderPanelLabel } from '../../hooks/border';
import { useBlockSettings } from '../../hooks/utils';
import { store as blockEditorStore } from '../../store';
import { ColorEdit } from '../../hooks/color';
import { ColorToolsPanel } from '../global-styles/color-panel';

function SectionBlockColorControls( {
blockName,
clientId,
contentClientIds,
} ) {
const settings = useBlockSettings( blockName );
const { updateBlockAttributes } = useDispatch( blockEditorStore );

const { hasButton, hasHeading } = useSelect(
Copy link
Member

Choose a reason for hiding this comment

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

Nice touch. I was initially thinking to just show a defined subset, but it's fancier to detect the block!

( select ) => {
const blockNames =
select( blockEditorStore ).getBlockNamesByClientId(
contentClientIds
);
return {
hasButton: blockNames.includes( 'core/button' ),
hasHeading: blockNames.includes( 'core/heading' ),
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about removing the control and the style when the element is deleted?

From what I can see, if the element is deleted inside the pattern, the style control persists when a value is set.

Kapture.2025-10-24.at.11.02.48.mp4

I'm not sure it's a huge problem, so more of a UX question.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we should be allowing deletion of elements in contentOnly!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure we should be allowing deletion of elements in contentOnly!

My understanding was also that things wouldn't be able to be deleted.

if the element is deleted inside the pattern, the style control persists when a value is set.

Either way, if we can delete, we should be able to undo to add it back. If we remove the set value, then they undo the change, I'd want the style to still be applied. So, I think leaving the value set is fine rather than removing it in this case.

};
},
[ contentClientIds ]
);

const setAttributes = ( newAttributes ) => {
updateBlockAttributes( clientId, newAttributes );
};

return (
<ColorEdit
clientId={ clientId }
name={ blockName }
settings={ settings }
setAttributes={ setAttributes }
asWrapper={ ColorToolsPanel }
label={ __( 'Color' ) }
defaultControls={ {
text: true,
background: true,
button: hasButton,
heading: hasHeading,
} }
/>
);
}

const StylesTab = ( {
blockName,
clientId,
hasBlockStyles,
isSectionBlock,
contentClientIds,
} ) => {
const borderPanelLabel = useBorderPanelLabel( { blockName } );

Expand All @@ -28,6 +78,14 @@ const StylesTab = ( {
</PanelBody>
</div>
) }
{ isSectionBlock &&
window?.__experimentalContentOnlyPatternInsertion && (
<SectionBlockColorControls
blockName={ blockName }
clientId={ clientId }
contentClientIds={ contentClientIds }
/>
) }
{ ! isSectionBlock && (
<>
<InspectorControls.Slot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ export default function useInspectorControlsTabs(
tabs.push( TAB_SETTINGS );
}

if ( isSectionBlock ? hasBlockStyles : hasStyleFills ) {
if (
hasBlockStyles ||
hasStyleFills ||
window?.__experimentalContentOnlyPatternInsertion
) {
tabs.push( TAB_STYLES );
}

Expand Down
27 changes: 21 additions & 6 deletions packages/block-editor/src/hooks/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,17 @@ function ColorInspectorControl( { children, resetAllFilter } ) {
);
}

export function ColorEdit( { clientId, name, setAttributes, settings } ) {
export function ColorEdit( {
clientId,
name,
setAttributes,
settings,
asWrapper,
label,
defaultControls,
} ) {
const isEnabled = useHasColorPanel( settings );

function selector( select ) {
const { style, textColor, backgroundColor, gradient } =
select( blockEditorStore ).getBlockAttributes( clientId ) || {};
Expand All @@ -288,10 +297,12 @@ export function ColorEdit( { clientId, name, setAttributes, settings } ) {
return null;
}

const defaultControls = getBlockSupport( name, [
COLOR_SUPPORT_KEY,
'__experimentalDefaultControls',
] );
defaultControls = defaultControls
? defaultControls
: getBlockSupport( name, [
COLOR_SUPPORT_KEY,
'__experimentalDefaultControls',
] );

const enableContrastChecking =
Platform.OS === 'web' &&
Expand All @@ -306,14 +317,18 @@ export function ColorEdit( { clientId, name, setAttributes, settings } ) {
'enableContrastChecker',
] );

// Use provided wrapper or default to ColorInspectorControl
const Wrapper = asWrapper || ColorInspectorControl;

return (
<StylesColorPanel
as={ ColorInspectorControl }
as={ Wrapper }
panelId={ clientId }
settings={ settings }
value={ value }
onChange={ onChange }
defaultControls={ defaultControls }
label={ label }
enableContrastChecker={
false !==
getBlockSupport( name, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"isValid": true,
"attributes": {
"tagName": "div",
"className": "wp-block-comments-query-loop comments-post-extra",
"textColor": "luminous-vivid-orange"
"textColor": "luminous-vivid-orange",
"className": "wp-block-comments-query-loop comments-post-extra"
Comment on lines +7 to +8
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These values all match, but are reordered. I'm not sure what caused this to be different.

},
"innerBlocks": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- wp:comments {"className":"wp-block-comments-query-loop comments-post-extra","textColor":"luminous-vivid-orange"} -->
<!-- wp:comments {"textColor":"luminous-vivid-orange","className":"wp-block-comments-query-loop comments-post-extra"} -->
<div class="wp-block-comments wp-block-comments-query-loop comments-post-extra has-luminous-vivid-orange-color has-text-color"><!-- wp:comments-title /-->

<!-- wp:comment-template -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"isValid": true,
"attributes": {
"tagName": "div",
"align": "full",
"backgroundColor": "secondary",
"align": "full",
"layout": {
"type": "constrained"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- wp:group {"align":"full","backgroundColor":"secondary","layout":{"type":"constrained"}} -->
<!-- wp:group {"backgroundColor":"secondary","align":"full","layout":{"type":"constrained"}} -->
<div class="wp-block-group alignfull has-secondary-background-color has-background"><!-- wp:paragraph -->
<p>This is a group block.</p>
<!-- /wp:paragraph -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"isValid": true,
"attributes": {
"tagName": "div",
"align": "full",
"backgroundColor": "secondary",
"align": "full",
"layout": {
"inherit": true,
"type": "constrained"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- wp:group {"align":"full","backgroundColor":"secondary","layout":{"inherit":true,"type":"constrained"}} -->
<!-- wp:group {"backgroundColor":"secondary","align":"full","layout":{"inherit":true,"type":"constrained"}} -->
<div class="wp-block-group alignfull has-secondary-background-color has-background"><!-- wp:paragraph -->
<p>This is a group block.</p>
<!-- /wp:paragraph -->
Expand Down
2 changes: 1 addition & 1 deletion test/integration/fixtures/blocks/core__group.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"isValid": true,
"attributes": {
"tagName": "div",
"align": "full",
"backgroundColor": "secondary",
"align": "full",
"layout": {
"type": "default"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- wp:group {"align":"full","backgroundColor":"secondary","layout":{"type":"default"}} -->
<!-- wp:group {"backgroundColor":"secondary","align":"full","layout":{"type":"default"}} -->
<div class="wp-block-group alignfull has-secondary-background-color has-background"><!-- wp:paragraph -->
<p>This is a group block.</p>
<!-- /wp:paragraph -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"isValid": true,
"attributes": {
"tagName": "div",
"align": "full",
"backgroundColor": "secondary"
"backgroundColor": "secondary",
"align": "full"
},
"innerBlocks": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- wp:group {"align":"full","backgroundColor":"secondary"} -->
<!-- wp:group {"backgroundColor":"secondary","align":"full"} -->
<div class="wp-block-group alignfull has-secondary-background-color has-background"><!-- wp:paragraph -->
<p>This is a group block.</p>
<!-- /wp:paragraph -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"isValid": true,
"attributes": {
"tagName": "div",
"align": "full",
"backgroundColor": "secondary"
"backgroundColor": "secondary",
"align": "full"
},
"innerBlocks": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- wp:group {"align":"full","backgroundColor":"secondary"} -->
<!-- wp:group {"backgroundColor":"secondary","align":"full"} -->
<div class="wp-block-group alignfull has-secondary-background-color has-background"><!-- wp:paragraph -->
<p>This is a group block.</p>
<!-- /wp:paragraph -->
Expand Down
4 changes: 2 additions & 2 deletions test/integration/fixtures/blocks/core__group__deprecated.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"isValid": true,
"attributes": {
"tagName": "div",
"backgroundColor": "lighter-blue",
"align": "full",
"anchor": "test-id",
"backgroundColor": "lighter-blue"
"anchor": "test-id"
},
"innerBlocks": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- wp:group {"align":"full","backgroundColor":"lighter-blue"} -->
<!-- wp:group {"backgroundColor":"lighter-blue","align":"full"} -->
<div class="wp-block-group alignfull has-lighter-blue-background-color has-background" id="test-id"><!-- wp:paragraph -->
<p>test</p>
<!-- /wp:paragraph --></div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- wp:pullquote {"className":"has-background is-style-default","textColor":"subtle-background","style":{"border":{"color":"#2207d0"}}} -->
<!-- wp:pullquote {"textColor":"subtle-background","className":"has-background is-style-default","style":{"border":{"color":"#2207d0"}}} -->
<figure class="wp-block-pullquote has-background is-style-default has-border-color has-subtle-background-color has-text-color" style="border-color:#2207d0"><blockquote><p>Pullquote custom color</p><cite>my citation</cite></blockquote></figure>
<!-- /wp:pullquote -->
Loading
Loading