Skip to content

Commit

Permalink
Add element styles for inner blocks within a variation to site editor
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Jan 11, 2024
1 parent a003477 commit 562a9fa
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ describe( 'global styles renderer', () => {
fontSize: '3em',
},
},
'core/media-text': {
color: {
text: 'maroon',
},
elements: {
link: {
color: {
text: 'firebrick',
},
':hover': {
color: {
text: 'coral',
},
},
},
},
},
},
elements: {
link: {
Expand Down Expand Up @@ -131,6 +148,9 @@ describe( 'global styles renderer', () => {
selector: '.my-image',
featureSelectors: '.my-image img, .my-image .crop-area',
},
'core/media-text': {
selector: '.media-text',
},
};

expect( getNodesWithStyles( tree, blockSelectors ) ).toEqual( [
Expand Down Expand Up @@ -173,6 +193,27 @@ describe( 'global styles renderer', () => {
},
},
},
{
selector: '.is-style-foo.my-group .media-text',
styles: {
color: {
text: 'maroon',
},
},
},
{
selector: '.is-style-foo.my-group .media-text a',
styles: {
color: {
text: 'firebrick',
},
':hover': {
color: {
text: 'coral',
},
},
},
},
{
selector: '.is-style-foo.my-group a',
styles: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,32 @@ export const getNodesWithStyles = ( tree, blockSelectors ) => {
variationBlockStyles
),
} );

// Process element styles for the inner blocks
// of the variation.
Object.entries(
variationBlockStyles.elements ?? {}
).forEach(
( [
variationBlockElement,
variationBlockElementStyles,
] ) => {
if (
variationBlockElementStyles &&
ELEMENTS[ variationBlockElement ]
) {
nodes.push( {
styles: variationBlockElementStyles,
selector: scopeSelector(
variationBlockSelector,
ELEMENTS[
variationBlockElement
]
),
} );
}
}
);
}
);

Expand Down

0 comments on commit 562a9fa

Please sign in to comment.