Skip to content

Commit

Permalink
Try enforcing global styles separator color
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Nov 25, 2024
1 parent b1b77f3 commit 3aae7d5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
15 changes: 15 additions & 0 deletions lib/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,21 @@ public static function get_user_data() {
}
}

/*
* The Separator block uses different CSS properties for its color depending
* on how it is being rendered e.g. as "content" for the Dots style, or
* as a border etc.
*

Check failure on line 570 in lib/class-wp-theme-json-resolver-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Whitespace found at end of line
* Uses are only presented with a single color control for background. Any
* selection of a background color should be applied to the other paths
* so it can be honoured.
*/
$separator_color = $config['styles']['blocks']['core/separator']['color']['background'] ?? null;

Check failure on line 575 in lib/class-wp-theme-json-resolver-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 space after "="; 2 found
if ( $separator_color ) {
_wp_array_set( $config, array( 'styles', 'blocks', 'core/separator', 'color', 'text' ), $separator_color );
_wp_array_set( $config, array( 'styles', 'blocks', 'core/separator', 'border', 'color' ), $separator_color );
}

/** This filter is documented in wp-includes/class-wp-theme-json-resolver.php */
$theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data_Gutenberg( $config, 'custom' ) );
static::$user = $theme_json->get_theme_json();
Expand Down
24 changes: 23 additions & 1 deletion packages/editor/src/components/global-styles-provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const { GlobalStylesContext, cleanEmptyObject } = unlock(
);

export function mergeBaseAndUserConfigs( base, user ) {
return deepmerge( base, user, {
const mergedConfig = deepmerge( base, user, {
/*
* We only pass as arrays the presets,
* in which case we want the new array of values
Expand All @@ -41,6 +41,28 @@ export function mergeBaseAndUserConfigs( base, user ) {
return undefined;
},
} );

/*
* The Separator block uses different CSS properties for its color depending
* on how it is being rendered e.g. as "content" for the Dots style, or
* as a border etc.
*
* Uses are only presented with a single color control for background. Any
* selection of a background color should be applied to the other paths
* so it can be honoured.
*/
const separatorColor =
user.styles?.blocks?.[ 'core/separator' ]?.color?.background;
if ( separatorColor ) {
mergedConfig.styles.blocks[ 'core/separator' ].color.text =
separatorColor;
mergedConfig.styles.blocks[ 'core/separator' ].border = {
...mergedConfig.styles.blocks[ 'core/separator' ].border,
color: separatorColor,
};
}

return mergedConfig;
}

function useGlobalStylesUserConfig() {
Expand Down

0 comments on commit 3aae7d5

Please sign in to comment.