Skip to content

Commit

Permalink
Update block support style generation for named subpaths
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Jun 7, 2021
1 parent b27a966 commit 8a25589
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
26 changes: 20 additions & 6 deletions packages/block-editor/src/hooks/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
get,
has,
isEmpty,
isString,
kebabCase,
map,
omit,
Expand Down Expand Up @@ -77,12 +78,25 @@ export function getInlineStyles( styles = {} ) {
const subPaths = STYLE_PROPERTY[ propKey ].properties;
// Ignore styles on elements because they are handled on the server.
if ( has( styles, path ) && 'elements' !== first( path ) ) {
if ( !! subPaths ) {
subPaths.forEach( ( suffix ) => {
output[
propKey + capitalize( suffix )
] = compileStyleValue( get( styles, [ ...path, suffix ] ) );
} );
// Checking if style value is a string allows for shorthand css
// option and backwards compatibility for border radius support.
const styleValue = get( styles, path );

if ( !! subPaths && ! isString( styleValue ) ) {
if ( Array.isArray( subPaths ) ) {
subPaths.forEach( ( suffix ) => {
output[
propKey + capitalize( suffix )
] = compileStyleValue( get( styleValue, [ suffix ] ) );
} );
} else {
Object.entries( subPaths ).forEach( ( entry ) => {
const [ name, suffix ] = entry;
output[ name ] = compileStyleValue(
get( styleValue, [ suffix ] )
);
} );
}
} else {
output[ propKey ] = compileStyleValue( get( styles, path ) );
}
Expand Down
20 changes: 20 additions & 0 deletions packages/block-editor/src/hooks/test/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,24 @@ describe( 'getInlineStyles', () => {
paddingTop: '10px',
} );
} );

it( 'should return individual border radius styles', () => {
expect(
getInlineStyles( {
border: {
radius: {
topLeft: '10px',
topRight: '0.5rem',
bottomLeft: '0.5em',
bottomRight: '1em',
},
},
} )
).toEqual( {
borderTopLeftRadius: '10px',
borderTopRightRadius: '0.5rem',
borderBottomLeftRadius: '0.5em',
borderBottomRightRadius: '1em',
} );
} );
} );
6 changes: 6 additions & 0 deletions packages/blocks/src/api/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export const __EXPERIMENTAL_STYLE_PROPERTY = {
borderRadius: {
value: [ 'border', 'radius' ],
support: [ '__experimentalBorder', 'radius' ],
properties: {
borderTopLeftRadius: 'topLeft',
borderTopRightRadius: 'topRight',
borderBottomLeftRadius: 'bottomLeft',
borderBottomRightRadius: 'bottomRight',
},
},
borderStyle: {
value: [ 'border', 'style' ],
Expand Down

0 comments on commit 8a25589

Please sign in to comment.