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

Post Featured Image: Fix borders after addition of overlay feature #44286

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"color": true,
"radius": true,
"width": true,
"__experimentalSelector": "img, .block-editor-media-placeholder",
"__experimentalSelector": "img, .block-editor-media-placeholder, .wp-block-post-featured-image__overlay",
"__experimentalSkipSerialization": true,
"__experimentalDefaultControls": {
"color": true,
Expand Down
142 changes: 70 additions & 72 deletions packages/block-library/src/post-featured-image/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,87 +6,85 @@
backdrop-filter: none; // Removes background blur so the overlay's actual color is visible.
}

&.wp-block-post-featured-image {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While doing some further testing around this block's styles I noticed that were duplicating the block's class selector here. Removing it didn't appear to impact the block visually in either editor and inspecting via devtools still showed all the same styles applied.

As a result, I've cleaned these styles up. Including reducing the specificity on the button that also didn't need it.

Copy link
Member

Choose a reason for hiding this comment

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

This tests well for me, I can also see no difference in the block's styles in either editor 👍

// Style the placeholder.
.wp-block-post-featured-image__placeholder,
.components-placeholder {
justify-content: center;
align-items: center;
padding: 0;
// Style the placeholder.
.wp-block-post-featured-image__placeholder,
.components-placeholder {
justify-content: center;
align-items: center;
padding: 0;

// Hide the upload button, as it's also available in the media library.
.components-form-file-upload {
display: none;
}
// Hide the upload button, as it's also available in the media library.
.components-form-file-upload {
display: none;
}

// Style the upload button.
.components-button.components-button {
padding: 0;
display: flex;
justify-content: center;
align-items: center;
width: $grid-unit-60;
height: $grid-unit-60;
border-radius: 50%;
position: relative;
background: var(--wp-admin-theme-color);
border-color: var(--wp-admin-theme-color);
border-style: solid;
color: $white;
// Style the upload button.
.components-button {
padding: 0;
display: flex;
justify-content: center;
align-items: center;
width: $grid-unit-60;
height: $grid-unit-60;
border-radius: 50%;
position: relative;
background: var(--wp-admin-theme-color);
border-color: var(--wp-admin-theme-color);
border-style: solid;
color: $white;

> svg {
color: inherit;
}
> svg {
color: inherit;
}
}

// Show default placeholder height when not resized.
min-height: 200px;

// The following override the default placeholder styles that remove
// its border so that a user selection for border color or width displays
// a visual border.
&:where(.has-border-color) {
border-style: solid;
}
&:where([style*="border-top-color"]) {
border-top-style: solid;
}
&:where([style*="border-right-color"]) {
border-right-style: solid;
}
&:where([style*="border-bottom-color"]) {
border-bottom-style: solid;
}
&:where([style*="border-left-color"]) {
border-left-style: solid;
}
// Show default placeholder height when not resized.
min-height: 200px;

&:where([style*="border-width"]) {
border-style: solid;
}
&:where([style*="border-top-width"]) {
border-top-style: solid;
}
&:where([style*="border-right-width"]) {
border-right-style: solid;
}
&:where([style*="border-bottom-width"]) {
border-bottom-style: solid;
}
&:where([style*="border-left-width"]) {
border-left-style: solid;
}
// The following override the default placeholder styles that remove
// its border so that a user selection for border color or width displays
// a visual border.
&:where(.has-border-color) {
border-style: solid;
}
&:where([style*="border-top-color"]) {
border-top-style: solid;
}
&:where([style*="border-right-color"]) {
border-right-style: solid;
}
&:where([style*="border-bottom-color"]) {
border-bottom-style: solid;
}
&:where([style*="border-left-color"]) {
border-left-style: solid;
}

// Provide a minimum size for the placeholder when resized.
// Note, this should be as small as we can afford it, and exists only
// to ensure there's room for the upload button.
&[style*="height"] .components-placeholder {
min-height: $grid-unit-60;
min-width: $grid-unit-60;
height: 100%;
width: 100%;
&:where([style*="border-width"]) {
border-style: solid;
}
&:where([style*="border-top-width"]) {
border-top-style: solid;
}
&:where([style*="border-right-width"]) {
border-right-style: solid;
}
&:where([style*="border-bottom-width"]) {
border-bottom-style: solid;
}
&:where([style*="border-left-width"]) {
border-left-style: solid;
}
}

// Provide a minimum size for the placeholder when resized.
// Note, this should be as small as we can afford it, and exists only
// to ensure there's room for the upload button.
&[style*="height"] .components-placeholder {
min-height: $grid-unit-60;
min-width: $grid-unit-60;
height: 100%;
width: 100%;
}
}

Expand Down
42 changes: 18 additions & 24 deletions packages/block-library/src/post-featured-image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,25 @@ function get_block_core_post_featured_image_overlay_element_markup( $attributes
$has_custom_gradient = isset( $attributes['customGradient'] ) && $attributes['customGradient'];
$has_solid_overlay = isset( $attributes['overlayColor'] ) && $attributes['overlayColor'];
$has_custom_overlay = isset( $attributes['customOverlayColor'] ) && $attributes['customOverlayColor'];
$class_names = array(
'wp-block-post-featured-image__overlay',
);
$styles_properties = array();
$class_names = array( 'wp-block-post-featured-image__overlay' );
$styles = array();

if ( ! $has_dim_background ) {
return '';
}

// Generate required classes for the element.
// Apply border classes and styles.
$border_attributes = get_block_core_post_featured_image_border_attributes( $attributes );

if ( ! empty( $border_attributes['class'] ) ) {
$class_names[] = $border_attributes['class'];
}

if ( ! empty( $border_attributes['style'] ) ) {
$styles[] = $border_attributes['style'];
}

// Apply overlay and gradient classes.
if ( $has_dim_background ) {
$class_names[] = 'has-background-dim';
$class_names[] = "has-background-dim-{$attributes['dimRatio']}";
Expand All @@ -103,35 +112,20 @@ function get_block_core_post_featured_image_overlay_element_markup( $attributes
$class_names[] = "has-{$attributes['gradient']}-gradient-background";
}

// Generate required CSS properties and their values.
if ( ! empty( $attributes['style']['border']['radius'] ) ) {
$styles_properties['border-radius'] = $attributes['style']['border']['radius'];
}

if ( ! empty( $attributes['style']['border']['width'] ) ) {
$styles_properties['border-width'] = $attributes['style']['border']['width'];
}

// Apply background styles.
if ( $has_custom_gradient ) {
$styles_properties['background-image'] = $attributes['customGradient'];
$styles[] = sprintf( 'background-image: %s;', $attributes['customGradient'] );
}

if ( $has_custom_overlay ) {
$styles_properties['background-color'] = $attributes['customOverlayColor'];
}

$styles = '';

foreach ( $styles_properties as $style_attribute => $style_attribute_value ) {
$styles .= "{$style_attribute}: $style_attribute_value; ";
$styles[] = sprintf( 'background-color: %s;', $attributes['customOverlayColor'] );
}

return sprintf(
'<span class="%s" style="%s" aria-hidden="true"></span>',
esc_attr( implode( ' ', $class_names ) ),
esc_attr( trim( $styles ) )
esc_attr( safecss_filter_attr( implode( ' ', $styles ) ) )
);

}

/**
Expand Down
31 changes: 17 additions & 14 deletions packages/block-library/src/post-featured-image/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,23 @@ const Overlay = ( {

return (
<>
<span
aria-hidden="true"
className={ classnames(
'wp-block-post-featured-image__overlay',
dimRatioToClass( dimRatio ),
{
[ overlayColor.class ]: overlayColor.class,
'has-background-dim': dimRatio !== undefined,
'has-background-gradient': gradientValue,
[ gradientClass ]: gradientClass,
}
) }
style={ overlayStyles }
/>
{ !! dimRatio && (
aaronrobertshaw marked this conversation as resolved.
Show resolved Hide resolved
<span
aria-hidden="true"
className={ classnames(
'wp-block-post-featured-image__overlay',
dimRatioToClass( dimRatio ),
{
[ overlayColor.class ]: overlayColor.class,
'has-background-dim': dimRatio !== undefined,
'has-background-gradient': gradientValue,
[ gradientClass ]: gradientClass,
},
borderProps.className
) }
style={ overlayStyles }
/>
) }
<InspectorControls __experimentalGroup="color">
<ColorGradientSettingsDropdown
__experimentalHasMultipleOrigins
Expand Down