Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Border controls: add defaults in the ToolPanel #34061

Merged
merged 7 commits into from
Dec 10, 2021
5 changes: 4 additions & 1 deletion packages/block-library/src/button/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@
},
"__experimentalBorder": {
"radius": true,
"__experimentalSkipSerialization": true
"__experimentalSkipSerialization": true,
"__experimentalDefaultControls": {
"radius": true
}
},
"__experimentalSelector": ".wp-block-button__link"
},
Expand Down
6 changes: 5 additions & 1 deletion packages/block-library/src/code/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
"radius": true,
"color": true,
"width": true,
"style": true
"style": true,
"__experimentalDefaultControls": {
"width": true,
"color": true
}
},
"color": {
"text": true,
Expand Down
8 changes: 7 additions & 1 deletion packages/block-library/src/group/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@
"color": true,
"radius": true,
"style": true,
"width": true
"width": true,
"__experimentalDefaultControls": {
"color": true,
"radius": true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making a note to self:

What is the minimum we need here? Is radius a candidate for an optional control?

Related comment: #33743 (comment)

"style": true,
"width": true
}
},
"__experimentalLayout": true
},
Expand Down
5 changes: 4 additions & 1 deletion packages/block-library/src/image/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@
"background": false
},
"__experimentalBorder": {
"radius": true
"radius": true,
"__experimentalDefaultControls": {
"radius": true
}
}
},
"styles": [
Expand Down
8 changes: 7 additions & 1 deletion packages/block-library/src/pullquote/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@
"color": true,
"radius": true,
"style": true,
"width": true
"width": true,
"__experimentalDefaultControls": {
"color": true,
"radius": true,
"style": true,
"width": true
}
}
},
"editorStyle": "wp-block-pullquote-editor",
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/pullquote/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
padding: 3em 0;
text-align: center; // Default text-alignment where the `textAlign` attribute value isn't specified.
overflow-wrap: break-word; // Break long strings of text without spaces so they don't overflow the block.
box-sizing: border-box;

p,
blockquote,
Expand Down
8 changes: 7 additions & 1 deletion packages/block-library/src/search/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@
"__experimentalBorder": {
"color": true,
"radius": true,
"__experimentalSkipSerialization": true
"width": true,
"__experimentalSkipSerialization": true,
"__experimentalDefaultControls": {
"color": true,
"radius": true,
"width": true
}
},
"html": false
},
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/search/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export default function SearchEdit( {
}, [ insertedInNavigationBlock ] );
const borderRadius = style?.border?.radius;
const borderColor = style?.border?.color;
const borderWidth = style?.border?.width;
const borderProps = useBorderProps( attributes );

// Check for old deprecated numerical border radius. Done as a separate
Expand Down Expand Up @@ -388,6 +389,7 @@ export default function SearchEdit( {
const getWrapperStyles = () => {
const styles = {
borderColor,
borderWidth: isButtonPositionInside ? borderWidth : undefined,
};

const isNonZeroBorderRadius = parseInt( borderRadius, 10 ) !== 0;
Expand Down
30 changes: 20 additions & 10 deletions packages/block-library/src/search/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function render_block_core_search( $attributes ) {
$use_icon_button = ( ! empty( $attributes['buttonUseIcon'] ) ) ? true : false;
$show_input = ( ! empty( $attributes['buttonPosition'] ) && 'button-only' === $attributes['buttonPosition'] ) ? false : true;
$show_button = ( ! empty( $attributes['buttonPosition'] ) && 'no-button' === $attributes['buttonPosition'] ) ? false : true;
$label_markup = '';
$input_markup = '';
$button_markup = '';
$inline_styles = styles_for_block_core_search( $attributes );
Expand Down Expand Up @@ -178,9 +177,11 @@ function classnames_for_block_core_search( $attributes ) {
* @return array Style HTML attribute.
*/
function styles_for_block_core_search( $attributes ) {
$wrapper_styles = array();
$button_styles = array();
$input_styles = array();
$wrapper_styles = array();
$button_styles = array();
$input_styles = array();
$is_button_inside = ! empty( $attributes['buttonPosition'] ) &&
'button-inside' === $attributes['buttonPosition'];

// Add width styles.
$has_width = ! empty( $attributes['width'] ) && ! empty( $attributes['widthUnit'] );
Expand All @@ -194,15 +195,26 @@ function styles_for_block_core_search( $attributes ) {
);
}

// Add border width styles.
$has_border_width = ! empty( $attributes['style']['border']['width'] );

if ( $has_border_width ) {
$border_width = $attributes['style']['border']['width'];

if ( $is_button_inside ) {
$wrapper_styles[] = sprintf( 'border-width: %s;', esc_attr( $border_width ) );
} else {
$button_styles[] = sprintf( 'border-width: %s;', esc_attr( $border_width ) );
$input_styles[] = sprintf( 'border-width: %s;', esc_attr( $border_width ) );
}
}

// Add border radius styles.
$has_border_radius = ! empty( $attributes['style']['border']['radius'] );

if ( $has_border_radius ) {
$default_padding = '4px';
$border_radius = $attributes['style']['border']['radius'];
// Apply wrapper border radius if button placed inside.
$is_button_inside = ! empty( $attributes['buttonPosition'] ) &&
'button-inside' === $attributes['buttonPosition'];

if ( is_array( $border_radius ) ) {
// Apply styles for individual corner border radii.
Expand Down Expand Up @@ -255,9 +267,7 @@ function styles_for_block_core_search( $attributes ) {
$has_border_color = ! empty( $attributes['style']['border']['color'] );

if ( $has_border_color ) {
$border_color = $attributes['style']['border']['color'];
$is_button_inside = ! empty( $attributes['buttonPosition'] ) &&
'button-inside' === $attributes['buttonPosition'];
$border_color = $attributes['style']['border']['color'];

// Apply wrapper border color if button placed inside.
if ( $is_button_inside ) {
Expand Down
7 changes: 6 additions & 1 deletion packages/block-library/src/table/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@
"__experimentalSkipSerialization": true,
"color": true,
"style": true,
"width": true
"width": true,
"__experimentalDefaultControls": {
"color": true,
"style": true,
"width": true
}
},
"__experimentalSelector": ".wp-block-table > table"
},
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/table/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
th,
td {
border-width: inherit;
border-style: inherit;
}
}
}