Skip to content

Commit

Permalink
Also passing the style color value to getClassnames so it will add …
Browse files Browse the repository at this point in the history
…the generic class name if required.

Regenerating fixtures due to the re-ordering of color classnames.
  • Loading branch information
ramonjd committed May 9, 2022
1 parent 393fac4 commit cb36e10
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
22 changes: 12 additions & 10 deletions packages/block-editor/src/hooks/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,20 +262,22 @@ export function addSaveProps( props, blockType, attributes ) {
// Primary color classes must come before the `has-text-color`,
// `has-background` and `has-link-color` classes to maintain backwards
// compatibility and avoid block invalidations.
if ( textColor && shouldSerialize( 'text' ) ) {
colorStyles.text = `var:preset|color|${ textColor }`;
if ( shouldSerialize( 'text' ) ) {
colorStyles.text = textColor
? `var:preset|color|${ textColor }`
: style?.color?.text;
}

if (
gradient &&
shouldSerialize( 'gradients' ) &&
hasGradientSupport( blockType )
) {
colorStyles.gradient = `var:preset|gradient|${ gradient }`;
if ( shouldSerialize( 'gradients' ) && hasGradientSupport( blockType ) ) {
colorStyles.gradient = gradient
? `var:preset|gradient|${ gradient }`
: style?.color?.gradient;
}

if ( backgroundColor && shouldSerialize( 'background' ) ) {
colorStyles.background = `var:preset|color|${ backgroundColor }`;
if ( shouldSerialize( 'background' ) ) {
colorStyles.background = backgroundColor
? `var:preset|color|${ backgroundColor }`
: style?.color?.background;
}

const newClassName = classnames(
Expand Down
2 changes: 1 addition & 1 deletion packages/style-engine/src/styles/color/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import background from './background';
import gradient from './gradient';
import text from './text';

export default [ background, gradient, text ];
export default [ text, gradient, background ];
10 changes: 5 additions & 5 deletions packages/style-engine/src/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe( 'generate', () => {
},
} )
).toEqual(
'background-color: #222222; background: linear-gradient(135deg,rgb(6,147,227) 0%,rgb(143,47,47) 49%,rgb(155,81,224) 100%); color: #f1f1f1; margin: 12px; padding: 10px;'
'color: #f1f1f1; background: linear-gradient(135deg,rgb(6,147,227) 0%,rgb(143,47,47) 49%,rgb(155,81,224) 100%); background-color: #222222; margin: 12px; padding: 10px;'
);
} );

Expand Down Expand Up @@ -164,7 +164,7 @@ describe( 'getClassnames', () => {
spacing: { padding: '10px', margin: '12px' },
color: { text: '#381515', background: '#000000' },
} )
).toEqual( [ 'has-background', 'has-text-color' ] );
).toEqual( [ 'has-text-color', 'has-background' ] );
} );

it( 'should generate classnames for eligible preset values', () => {
Expand All @@ -178,11 +178,11 @@ describe( 'getClassnames', () => {
},
} )
).toEqual( [
'has-mustard-pickles-background-color',
'has-background',
'has-hairy-orange-gradient-background',
'has-white-as-show-color',
'has-text-color',
'has-hairy-orange-gradient-background',
'has-background',
'has-mustard-pickles-background-color',
] );
} );
} );
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- wp:button {"style":{"border":{"radius":0},"color":{"text":"#1b9b6c","background":"#aa5a20"}}} -->
<div class="wp-block-button"><a class="wp-block-button__link has-text-color has-background no-border-radius" style="background-color:#aa5a20;color:#1b9b6c">My button</a></div>
<div class="wp-block-button"><a class="wp-block-button__link has-text-color has-background no-border-radius" style="color:#1b9b6c;background-color:#aa5a20">My button</a></div>
<!-- /wp:button -->
2 changes: 1 addition & 1 deletion test/integration/fixtures/blocks/core__post-terms.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"name": "core/post-terms",
"isValid": true,
"attributes": {
"prefix": "",
"separator": ", ",
"prefix": "",
"suffix": ""
},
"innerBlocks": []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- wp:pullquote {"textAlign":"right","className":"is-style-default","style":{"color":{"background":"#3486aa","text":"#ffefef"},"border":{"color":"#045679"}}} -->
<figure class="wp-block-pullquote has-text-align-right is-style-default has-border-color has-text-color has-background" style="border-color:#045679;background-color:#3486aa;color:#ffefef"><blockquote><p>pullquote</p><cite>citation</cite></blockquote></figure>
<figure class="wp-block-pullquote has-text-align-right is-style-default has-border-color has-text-color has-background" style="border-color:#045679;color:#ffefef;background-color:#3486aa"><blockquote><p>pullquote</p><cite>citation</cite></blockquote></figure>
<!-- /wp:pullquote -->
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- wp:pullquote {"textAlign":"left","className":"is-style-solid-color","backgroundColor":"black","textColor":"white"} -->
<figure class="wp-block-pullquote has-text-align-left is-style-solid-color has-white-color has-black-background-color has-text-color has-background"><blockquote><p>pullquote</p><cite>before block supports</cite></blockquote></figure>
<figure class="wp-block-pullquote has-text-align-left is-style-solid-color has-white-color has-text-color has-black-background-color has-background"><blockquote><p>pullquote</p><cite>before block supports</cite></blockquote></figure>
<!-- /wp:pullquote -->

0 comments on commit cb36e10

Please sign in to comment.