From bf8838b505aca6bda0b97f8c1c28ba078fe1e067 Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Tue, 20 Sep 2022 17:29:26 +1000
Subject: [PATCH 1/6] Add overlay to post featured image border selectors
---
packages/block-library/src/post-featured-image/block.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/block-library/src/post-featured-image/block.json b/packages/block-library/src/post-featured-image/block.json
index 1072c7576d645..40f51cffa06e7 100644
--- a/packages/block-library/src/post-featured-image/block.json
+++ b/packages/block-library/src/post-featured-image/block.json
@@ -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,
From 85f38a0909c2dfb0f4347b403c776344264198b3 Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Wed, 21 Sep 2022 13:51:18 +1000
Subject: [PATCH 2/6] Fix borders on overlays for individual blocks
---
.../src/post-featured-image/index.php | 42 ++++++++-----------
1 file changed, 18 insertions(+), 24 deletions(-)
diff --git a/packages/block-library/src/post-featured-image/index.php b/packages/block-library/src/post-featured-image/index.php
index 552811f6d2f21..40a7f41cd78ac 100644
--- a/packages/block-library/src/post-featured-image/index.php
+++ b/packages/block-library/src/post-featured-image/index.php
@@ -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']}";
@@ -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(
'',
esc_attr( implode( ' ', $class_names ) ),
- esc_attr( trim( $styles ) )
+ esc_attr( safecss_filter_attr( implode( ' ', $styles ) ) )
);
-
}
/**
From b388f346b3515c9dde4fd94b78b825b8102669d7 Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Wed, 21 Sep 2022 14:20:28 +1000
Subject: [PATCH 3/6] Provide a fallback border style
---
packages/block-library/src/post-featured-image/style.scss | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/packages/block-library/src/post-featured-image/style.scss b/packages/block-library/src/post-featured-image/style.scss
index d4cfbc7273638..fbe1ae75fad90 100644
--- a/packages/block-library/src/post-featured-image/style.scss
+++ b/packages/block-library/src/post-featured-image/style.scss
@@ -12,6 +12,11 @@
box-sizing: border-box;
}
+ :where(img),
+ :where(.wp-block-post-featured-image__overlay) {
+ border-style: solid;
+ }
+
&.alignwide img,
&.alignfull img {
width: 100%;
From 1d9bd9ab035e8ad4d99d9588af8bed42c364935b Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Wed, 21 Sep 2022 14:21:17 +1000
Subject: [PATCH 4/6] Make the editor markup match frontend
Overlay was being rendered in editor regardless of if there should be one and it didn't have border classes applied to the overlay.
---
.../src/post-featured-image/overlay.js | 31 ++++++++++---------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/packages/block-library/src/post-featured-image/overlay.js b/packages/block-library/src/post-featured-image/overlay.js
index 572cef64801e7..f577978b9a3c9 100644
--- a/packages/block-library/src/post-featured-image/overlay.js
+++ b/packages/block-library/src/post-featured-image/overlay.js
@@ -47,20 +47,23 @@ const Overlay = ( {
return (
<>
-
+ { !! dimRatio && (
+
+ ) }
Date: Fri, 23 Sep 2022 15:03:33 +1000
Subject: [PATCH 5/6] Remove fallback for theme.json border style
This would need a border-width: 0 as well to avoid the border it adds. Doing so would mean multiple edits required at the Global Styles level worsening UX. Setting the style via theme.json comes with further edge cases as well.
---
packages/block-library/src/post-featured-image/style.scss | 5 -----
1 file changed, 5 deletions(-)
diff --git a/packages/block-library/src/post-featured-image/style.scss b/packages/block-library/src/post-featured-image/style.scss
index fbe1ae75fad90..d4cfbc7273638 100644
--- a/packages/block-library/src/post-featured-image/style.scss
+++ b/packages/block-library/src/post-featured-image/style.scss
@@ -12,11 +12,6 @@
box-sizing: border-box;
}
- :where(img),
- :where(.wp-block-post-featured-image__overlay) {
- border-style: solid;
- }
-
&.alignwide img,
&.alignfull img {
width: 100%;
From 84def8bff9bb8242c4b4b6d652f7b32493174721 Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Fri, 23 Sep 2022 15:12:56 +1000
Subject: [PATCH 6/6] Reduce unnecessary specificity in styles
---
.../src/post-featured-image/editor.scss | 142 +++++++++---------
1 file changed, 70 insertions(+), 72 deletions(-)
diff --git a/packages/block-library/src/post-featured-image/editor.scss b/packages/block-library/src/post-featured-image/editor.scss
index c52d14f44f7a6..37c29160055d8 100644
--- a/packages/block-library/src/post-featured-image/editor.scss
+++ b/packages/block-library/src/post-featured-image/editor.scss
@@ -6,87 +6,85 @@
backdrop-filter: none; // Removes background blur so the overlay's actual color is visible.
}
- &.wp-block-post-featured-image {
- // 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%;
}
}