-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,10 @@ import { createHigherOrderComponent } from '@wordpress/compose'; | |
* Internal dependencies | ||
*/ | ||
import { | ||
getColorClassName, | ||
getColorObjectByColorValue, | ||
getColorObjectByAttributeValues, | ||
} from '../components/colors'; | ||
import { | ||
__experimentalGetGradientClass, | ||
getGradientValueBySlug, | ||
getGradientSlugByValue, | ||
} from '../components/gradients'; | ||
|
@@ -34,6 +32,7 @@ import { | |
} from './utils'; | ||
import ColorPanel from './color-panel'; | ||
import useSetting from '../components/use-setting'; | ||
import { getClassnames } from '@wordpress/style-engine'; | ||
|
||
export const COLOR_SUPPORT_KEY = 'color'; | ||
|
||
|
@@ -252,52 +251,51 @@ export function addSaveProps( props, blockType, attributes ) { | |
return props; | ||
} | ||
|
||
const hasGradient = hasGradientSupport( blockType ); | ||
|
||
// I'd have preferred to avoid the "style" attribute usage here | ||
const { backgroundColor, textColor, gradient, style } = attributes; | ||
|
||
const shouldSerialize = ( feature ) => | ||
! shouldSkipSerialization( blockType, COLOR_SUPPORT_KEY, feature ); | ||
|
||
const colorStyles = {}; | ||
|
||
// Primary color classes must come before the `has-text-color`, | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ramonjd
Author
Member
|
||
// `has-background` and `has-link-color` classes to maintain backwards | ||
// compatibility and avoid block invalidations. | ||
const textClass = shouldSerialize( 'text' ) | ||
? getColorClassName( 'color', textColor ) | ||
: undefined; | ||
|
||
const gradientClass = shouldSerialize( 'gradients' ) | ||
? __experimentalGetGradientClass( gradient ) | ||
: undefined; | ||
if ( textColor && shouldSerialize( 'text' ) ) { | ||
colorStyles.text = `var:preset|color|${ textColor }`; | ||
} | ||
|
||
const backgroundClass = shouldSerialize( 'background' ) | ||
? getColorClassName( 'background-color', backgroundColor ) | ||
: undefined; | ||
if ( | ||
gradient && | ||
shouldSerialize( 'gradients' ) && | ||
hasGradientSupport( blockType ) | ||
) { | ||
colorStyles.gradient = `var:preset|gradient|${ gradient }`; | ||
} | ||
|
||
const serializeHasBackground = | ||
shouldSerialize( 'background' ) || shouldSerialize( 'gradients' ); | ||
const hasBackground = | ||
backgroundColor || | ||
style?.color?.background || | ||
( hasGradient && ( gradient || style?.color?.gradient ) ); | ||
if ( backgroundColor && shouldSerialize( 'background' ) ) { | ||
colorStyles.background = `var:preset|color|${ backgroundColor }`; | ||
} | ||
|
||
const newClassName = classnames( | ||
props.className, | ||
textClass, | ||
gradientClass, | ||
{ | ||
// Don't apply the background class if there's a custom gradient. | ||
[ backgroundClass ]: | ||
( ! hasGradient || ! style?.color?.gradient ) && | ||
!! backgroundClass, | ||
'has-text-color': | ||
shouldSerialize( 'text' ) && | ||
( textColor || style?.color?.text ), | ||
'has-background': serializeHasBackground && hasBackground, | ||
'has-link-color': | ||
shouldSerialize( 'link' ) && style?.elements?.link?.color, | ||
} | ||
...getClassnames( { | ||
...style, | ||
color: { | ||
...colorStyles, | ||
}, | ||
elements: { | ||
...style?.elements, | ||
link: { | ||
color: { | ||
text: shouldSerialize( 'link' ) | ||
? style?.elements?.link?.color | ||
: undefined, | ||
}, | ||
}, | ||
}, | ||
} ) | ||
); | ||
props.className = newClassName ? newClassName : undefined; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { Style } from '../../types'; | ||
|
||
const link = { | ||
name: 'link', | ||
getClassNames: ( style: Style ) => { | ||
const classNames = []; | ||
const styleValue: string | undefined = | ||
style?.elements?.link?.color?.text; | ||
if ( styleValue ) { | ||
classNames.push( 'has-link-color' ); | ||
} | ||
|
||
return classNames; | ||
}, | ||
}; | ||
|
||
export default [ link ]; |
Cool idea exploring concatenating to
var:preset|color|${ textColor }
@ramonjd!To respect this comment about the order that the classes need to be generated in, I wonder if that means we should also update the export in
gutenberg/packages/style-engine/src/styles/color/index.ts
Line 8 in 2cf8698
So:
Not sure if that'd help resolve some of the fixture failures? (Apologies if I'm way off here 😀)