Skip to content

Commit

Permalink
Cover the case in which the theme does not provide any color
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed May 19, 2021
1 parent 5d96f8b commit b7050eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 7 additions & 5 deletions packages/block-editor/src/components/use-setting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,18 @@ const deprecatedFlags = {
'spacing.customPadding': ( settings ) => settings.enableCustomSpacing,
};

const filterColorsFromCoreOrigin = ( path, colors ) => {
const filterColorsFromCoreOrigin = ( path, setting ) => {
if ( path !== 'color.palette' && path !== 'color.gradients' ) {
return colors;
return setting;
}

if ( ! Array.isArray( colors ) ) {
return colors;
if ( ! Array.isArray( setting ) ) {
return setting;
}

return colors.filter( ( color ) => color?.origin !== 'core' );
const colors = setting.filter( ( color ) => color?.origin !== 'core' );

return colors.length > 0 ? colors : setting;
};

/**
Expand Down
12 changes: 7 additions & 5 deletions packages/edit-site/src/components/editor/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,18 @@ function getPresetMetadataFromStyleProperty( styleProperty ) {
export const LINK_COLOR = '--wp--style--color--link';
export const LINK_COLOR_DECLARATION = `a { color: var(${ LINK_COLOR }, #00e); }`;

const filterColorsFromCoreOrigin = ( path, colors ) => {
const filterColorsFromCoreOrigin = ( path, setting ) => {
if ( path !== 'color.palette' && path !== 'color.gradients' ) {
return colors;
return setting;
}

if ( ! Array.isArray( colors ) ) {
return colors;
if ( ! Array.isArray( setting ) ) {
return setting;
}

return colors.filter( ( color ) => color?.origin !== 'core' );
const colors = setting.filter( ( color ) => color?.origin !== 'core' );

return colors.length > 0 ? colors : setting;
};

export function useSetting( path, blockName = '' ) {
Expand Down

0 comments on commit b7050eb

Please sign in to comment.