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

Color controls: take labels from block supports #29155

Closed
wants to merge 2 commits into from
Closed
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
14 changes: 10 additions & 4 deletions packages/block-editor/src/hooks/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ const getLinkColorFromAttributeValue = ( colors, value ) => {
* @return {WPElement} Color edit element.
*/
export function ColorEdit( props ) {
const { name: blockName, attributes } = props;
const { name: blockName, attributes, colorLabels } = props;
const isLinkColorEnabled = useEditorFeature( 'color.link' );
const colors = useEditorFeature( 'color.palette' ) || EMPTY_ARRAY;
const gradients = useEditorFeature( 'color.gradients' ) || EMPTY_ARRAY;
Expand Down Expand Up @@ -327,7 +327,9 @@ export function ColorEdit( props ) {
...( hasTextColorSupport( blockName )
? [
{
label: __( 'Text Color' ),
label:
colorLabels?.textColorLabel ||
__( 'Text Color' ),
onColorChange: onChangeColor( 'text' ),
colorValue: getColorObjectByAttributeValues(
colors,
Expand All @@ -340,7 +342,9 @@ export function ColorEdit( props ) {
...( hasBackground || hasGradient
? [
{
label: __( 'Background Color' ),
label:
colorLabels?.backgroundColorLabel ||
__( 'Background Color' ),
onColorChange: hasBackground
? onChangeColor( 'background' )
: undefined,
Expand All @@ -359,7 +363,9 @@ export function ColorEdit( props ) {
...( isLinkColorEnabled && hasLinkColorSupport( blockName )
? [
{
label: __( 'Link Color' ),
label:
colorLabels?.linkColorLabel ||
__( 'Link Color' ),
onColorChange: onChangeLinkColor,
colorValue: getLinkColorFromAttributeValue(
colors,
Expand Down
11 changes: 10 additions & 1 deletion packages/block-editor/src/hooks/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { capitalize, has, get, startsWith } from 'lodash';
*/
import { addFilter } from '@wordpress/hooks';
import {
getBlockSupport,
hasBlockSupport,
__EXPERIMENTAL_STYLE_PROPERTY as STYLE_PROPERTY,
} from '@wordpress/blocks';
Expand Down Expand Up @@ -159,10 +160,18 @@ export const withBlockControls = createHigherOrderComponent(
SPACING_SUPPORT_KEY
);

const colorSupport = getBlockSupport( blockName, COLOR_SUPPORT_KEY );
const colorLabels = {
backgroundColorLabel:
colorSupport?.__experimentalBackgroundColorLabel,
linkColorLabel: colorSupport?.__experimentalLinkColorLabel,
textColorLabel: colorSupport?.__experimentalTextColorLabel,
};

return [
<TypographyPanel key="typography" { ...props } />,
<BorderPanel key="border" { ...props } />,
<ColorEdit key="colors" { ...props } />,
<ColorEdit key="colors" { ...{ ...props, colorLabels } } />,
<BlockEdit key="edit" { ...props } />,
hasSpacingSupport && (
<SpacingPanelControl key="spacing">
Expand Down