From ba51354724e82dcf5d05e9e840d8b6afcab712a3 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Mon, 4 Jan 2021 13:58:12 +1000 Subject: [PATCH 1/3] CSS variable based search border radius --- lib/block-supports/border.php | 1 + lib/class-wp-theme-json.php | 4 ++++ packages/block-editor/src/hooks/border-radius.js | 6 ++++-- packages/block-library/src/search/block.json | 5 ++++- packages/block-library/src/search/editor.scss | 1 - packages/block-library/src/search/style.scss | 13 ++++++++++++- packages/blocks/src/api/constants.js | 4 ++++ 7 files changed, 29 insertions(+), 5 deletions(-) diff --git a/lib/block-supports/border.php b/lib/block-supports/border.php index 085cdda187da0c..e09070a71d78ac 100644 --- a/lib/block-supports/border.php +++ b/lib/block-supports/border.php @@ -46,6 +46,7 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) { if ( isset( $block_attributes['style']['border']['radius'] ) ) { $border_radius = intval( $block_attributes['style']['border']['radius'] ); $styles[] = sprintf( 'border-radius: %dpx;', $border_radius ); + $styles[] = sprintf( '--wp--style--border--radius: %dpx;', $border_radius ); } } diff --git a/lib/class-wp-theme-json.php b/lib/class-wp-theme-json.php index 6b140156f65db8..652c6f806b8125 100644 --- a/lib/class-wp-theme-json.php +++ b/lib/class-wp-theme-json.php @@ -235,6 +235,10 @@ class WP_Theme_JSON { * - 'support': path to the block support in block.json. */ const PROPERTIES_METADATA = array( + '--wp--style--border--radius' => array( + 'value' => array( 'border', 'radius' ), + 'support' => array( '__experimentalBorder', 'radius' ), + ), '--wp--style--color--link' => array( 'value' => array( 'color', 'link' ), 'support' => array( 'color', 'link' ), diff --git a/packages/block-editor/src/hooks/border-radius.js b/packages/block-editor/src/hooks/border-radius.js index beb42e529751de..d4d101683b2565 100644 --- a/packages/block-editor/src/hooks/border-radius.js +++ b/packages/block-editor/src/hooks/border-radius.js @@ -36,16 +36,18 @@ export function BorderRadiusEdit( props ) { ...style, border: { ...style?.border, - radius: newRadius, + radius: newRadius && `${ newRadius }px`, }, }; setAttributes( { style: cleanEmptyObject( newStyle ) } ); }; + const value = style?.border?.radius.replace( 'px', '' ); + return ( Date: Tue, 5 Jan 2021 21:24:32 +1000 Subject: [PATCH 2/3] Update theme.json docs for search border support --- docs/designers-developers/developers/themes/theme-json.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/designers-developers/developers/themes/theme-json.md b/docs/designers-developers/developers/themes/theme-json.md index d46acdb4c5a097..68efa27f45786a 100644 --- a/docs/designers-developers/developers/themes/theme-json.md +++ b/docs/designers-developers/developers/themes/theme-json.md @@ -317,6 +317,12 @@ h4 { } ``` +#### Border Properties + +| Context | Radius | +| --- | --- | +| Search | Yes | + #### Color Properties These are the current color properties supported by blocks: From 7e3af47f0708a8b5d4e33098ce0aa88783eb774b Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Mon, 18 Jan 2021 15:29:02 +1000 Subject: [PATCH 3/3] Add border radius CSS variable to style test --- packages/block-editor/src/hooks/test/style.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/block-editor/src/hooks/test/style.js b/packages/block-editor/src/hooks/test/style.js index 62c5a97b6e211e..78265643f8ce74 100644 --- a/packages/block-editor/src/hooks/test/style.js +++ b/packages/block-editor/src/hooks/test/style.js @@ -20,6 +20,7 @@ describe( 'getInlineStyles', () => { border: { radius: 10 }, } ) ).toEqual( { + '--wp--style--border--radius': 10, backgroundColor: 'black', borderRadius: 10, color: 'red',