Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Enable more style options for the Featured Category block #6276

Merged
merged 11 commits into from
Apr 21, 2022

Conversation

sunyatasattva
Copy link
Contributor

@sunyatasattva sunyatasattva commented Apr 16, 2022

This PR adds several style options to the Featured Product block. The current status of features supported and planned for each block can be seen in this spreadsheet.

This PR fixes the following problems:

  • Previously, the overlay of this block was actually rendered as a background. That meant inconsistent behavior in certain circumstances (like when an external padding was added). The overlay is now a separate DOM element.
  • Previously, the overlay color was controlled within the Color section of the sidebar, while its opacity was controlled elsewhere. This PR consolidates the controls under the Overlay section.
  • Previously, the featured product image was rendered as a background. This meant we could not correctly apply things like duotone filters (see Featured Product: Enable global style #5555). The image is now rendered as a separate DOM element.
  • Previously, the featured image was resized constraining it to the block size. This meant that the focal point could only be moved vertically. Now the focal point can be moved correctly (see below: Image fit options).
  • The resizable container handle was not completely visible (it would only show half a circle). This is fixed.
  • The resizable container handle was always visible regardless of the selected status of the block.
  • Previously, if the padding was large enough, the content could be pushed out of the container. Now the block behaves more like the Cover block, in the sense that the padding will scale the container up. This also means that the resizable control is subject to this rule, and can't resize the container lower than a certain minimum (determined by content and size). This is the same behavior as the Cover block.

This PR adds the following features:

  • Support for Duotone: users can now set a duotone filter on the featured product image.
  • Support for gradients: users can now set the overlay color as a gradient.
  • Support for padding: users can now set custom padding for the block.
  • Image fit options: The user can now decide how should the image behave on the resizing of the component; it can either scale to always cover the entire container, or remain its original size.

Closes #6151

Screenshots

Screen Shot 2022-04-16 at 21 21 49

Testing

Automated Tests

  • Changes in this PR are covered by Automated Tests.
    • Unit tests
    • E2E tests

Manual Testing

How to test the changes in this Pull Request:

  1. Use a block theme (such as Twenty Twenty Two)
  2. Add the ”Featured Category” block to a page and select a product.
  3. Make sure that the resizable handle is a shown fully (it should be a full circle), and that is shown only when the block is selected.
  4. Select the block and apply a Duotone filter.
  5. Make sure the overlay color control is under the Overlay section and change the overlay color to a gradient.
  6. Add a padding to the block and make sure the padding is added on the inside of the wrapper (i.e. no white space is created outside of the block).
  7. Move around your image focal point and make sure you can actually move around the entire image and not only constrained on one dimension.
  8. Apply “Image fit > Cover” and notice how the image will scale along with the container. As opposed to point 5 above, now the focal point picker is limited to one dimension.
  9. Increase the padding-top of the block and notice that the content can't get pushed out of the container, but instead the container resizes.
  10. When that's the case, try resizing the block through the handle to a lower height: the handle should move but the container should not resize. When the mouse is lifted, the handle should return to its original position.
  11. For the steps 4–9 above, save the page and check that the styles are applied correctly on the front-end (as the block is rendered statically via PHP).

User Facing Testing

These are steps for user testing (where "user" is someone interacting with this change that is not editing any code).

  • Same as above

Known issues

Currently, the border controls don't seem to work. This appears to be an issue related to the current Gutenberg version shipped with Core (Slack thread).


❗ Note: Since this PR includes several changes, we agreed that it should have a multi-line changelog. I checked the automation script which creates the changelog, and it seems to be fine with that. There might be some formatting issues with newlines and such, so perhaps, release lead, you might have to adjust a few things before publishing.

Changelog

Enhanced the Featured Category block:

  • Implemented support for duotone.
  • Implemented support for gradients on the overlay.
  • Implemented support for custom inner padding.
  • Implemented image fit options: users can now decide how should the image behave on the resizing of the component; it can either scale to always cover the entire container, or remain its original size.
  • Fixed an inconsistency where the overlay color was controlled by the background color control. It is now moved to the correct section.
  • Fixed the focal point picker, it now works on both axis as long as the image fit (above) is set to none.
  • Fixed an issue with the visibility of the resizing handle.
  • Fixed an issue which would keep the resizing handle always active regardless of block selection status.
  • Changed the behavior of the resizing: the block can't be resized below a minimum height determined by its content plus the padding.

@rubikuserbot rubikuserbot requested review from a team and tjcafferkey and removed request for a team April 16, 2022 19:25
@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
featured-category.js react, wp-is-shallow-equal ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 16, 2022

Size Change: +3.67 kB (0%)

Total Size: 867 kB

Filename Size Change
build/active-filters.js 6.59 kB -2 B (0%)
build/all-products.js 33.4 kB -59 B (0%)
build/all-reviews.js 7.78 kB +5 B (0%)
build/attribute-filter.js 13.4 kB +1 B (0%)
build/cart.js 44.3 kB +10 B (0%)
build/checkout-blocks/payment-frontend.js 7.84 kB +20 B (0%)
build/checkout-frontend.js 47.7 kB +2 B (0%)
build/checkout.js 45.6 kB +32 B (0%)
build/featured-category.js 12.1 kB +3.49 kB (+40%) 🚨
build/featured-product.js 10.6 kB +177 B (+2%)
build/handpicked-products.js 7.11 kB +4 B (0%)
build/mini-cart-contents.js 22.7 kB +7 B (0%)
build/price-filter.js 8.41 kB +3 B (0%)
build/product-add-to-cart--product-button--product-category-list--product-image--product-price--product-r--a0326d00.js 223 B -1 B (0%)
build/product-add-to-cart--product-button--product-image--product-title.js 2.65 kB -1 B (0%)
build/product-add-to-cart.js 6.64 kB -1 B (0%)
build/product-best-sellers.js 7.38 kB -1 B (0%)
build/product-button--product-category-list--product-image--product-price--product-rating--product-sale-b--e17c7c01.js 499 B -3 B (-1%)
build/product-button.js 1.08 kB +1 B (0%)
build/product-categories.js 2.78 kB +2 B (0%)
build/product-category.js 8.49 kB +6 B (0%)
build/product-image.js 1.07 kB +1 B (0%)
build/product-on-sale.js 7.99 kB +3 B (0%)
build/product-price.js 1.5 kB -1 B (0%)
build/product-rating.js 732 B -1 B (0%)
build/product-sale-badge.js 679 B +1 B (0%)
build/product-search.js 2.18 kB -2 B (0%)
build/product-stock-indicator.js 619 B -2 B (0%)
build/product-summary.js 918 B -1 B (0%)
build/product-tag.js 7.81 kB +2 B (0%)
build/product-title.js 910 B +1 B (0%)
build/product-top-rated.js 7.91 kB -1 B (0%)
build/products-by-attribute.js 8.39 kB -6 B (0%)
build/reviews-by-category.js 11.2 kB +5 B (0%)
build/reviews-by-product.js 12.2 kB -73 B (-1%)
build/single-product.js 10 kB -27 B (0%)
build/stock-filter.js 6.56 kB -6 B (0%)
build/wc-blocks-style-rtl.css 22 kB +40 B (0%)
build/wc-blocks-style.css 22 kB +39 B (0%)
build/wc-blocks-vendors.js 71.4 kB +12 B (0%)
build/wc-blocks.js 2.63 kB +2 B (0%)
ℹ️ View Unchanged
Filename Size
build/active-filters-frontend.js 5.92 kB
build/all-products-frontend.js 18.1 kB
build/attribute-filter-frontend.js 17.5 kB
build/blocks-checkout.js 17.4 kB
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.16 kB
build/cart-blocks/cart-express-payment-frontend.js 5.24 kB
build/cart-blocks/cart-items-frontend.js 298 B
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.27 kB
build/cart-blocks/cart-line-items-frontend.js 431 B
build/cart-blocks/cart-order-summary-frontend.js 1.1 kB
build/cart-blocks/cart-totals-frontend.js 321 B
build/cart-blocks/empty-cart-frontend.js 345 B
build/cart-blocks/filled-cart-frontend.js 783 B
build/cart-blocks/order-summary-coupon-form-frontend.js 2.81 kB
build/cart-blocks/order-summary-discount-frontend.js 2.31 kB
build/cart-blocks/order-summary-fee-frontend.js 273 B
build/cart-blocks/order-summary-heading-frontend.js 454 B
build/cart-blocks/order-summary-shipping--checkout-blocks/order-summary-shipping-frontend.js 6.33 kB
build/cart-blocks/order-summary-shipping-frontend.js 427 B
build/cart-blocks/order-summary-subtotal-frontend.js 273 B
build/cart-blocks/order-summary-taxes-frontend.js 433 B
build/cart-blocks/proceed-to-checkout-frontend.js 1.16 kB
build/cart-frontend.js 45.5 kB
build/checkout-blocks/actions-frontend.js 1.41 kB
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 4.12 kB
build/checkout-blocks/billing-address-frontend.js 893 B
build/checkout-blocks/contact-information-frontend.js 2.83 kB
build/checkout-blocks/express-payment-frontend.js 5.54 kB
build/checkout-blocks/fields-frontend.js 343 B
build/checkout-blocks/order-note-frontend.js 1.07 kB
build/checkout-blocks/order-summary-cart-items-frontend.js 3.67 kB
build/checkout-blocks/order-summary-coupon-form-frontend.js 2.97 kB
build/checkout-blocks/order-summary-discount-frontend.js 2.43 kB
build/checkout-blocks/order-summary-fee-frontend.js 275 B
build/checkout-blocks/order-summary-frontend.js 1.1 kB
build/checkout-blocks/order-summary-shipping-frontend.js 605 B
build/checkout-blocks/order-summary-subtotal-frontend.js 273 B
build/checkout-blocks/order-summary-taxes-frontend.js 432 B
build/checkout-blocks/shipping-address-frontend.js 996 B
build/checkout-blocks/shipping-methods-frontend.js 4.72 kB
build/checkout-blocks/terms-frontend.js 1.22 kB
build/checkout-blocks/totals-frontend.js 325 B
build/legacy-template.js 2.19 kB
build/mini-cart-component-frontend.js 16.6 kB
build/mini-cart-contents-block/empty-cart-frontend.js 327 B
build/mini-cart-contents-block/filled-cart-frontend.js 230 B
build/mini-cart-contents-block/footer--mini-cart-contents-block/products-table-frontend.js 4.69 kB
build/mini-cart-contents-block/footer-frontend.js 5.64 kB
build/mini-cart-contents-block/items-frontend.js 226 B
build/mini-cart-contents-block/products-table-frontend.js 289 B
build/mini-cart-contents-block/shopping-button-frontend.js 287 B
build/mini-cart-contents-block/title-frontend.js 367 B
build/mini-cart-frontend.js 1.72 kB
build/mini-cart.js 6.1 kB
build/price-filter-frontend.js 12.4 kB
build/price-format.js 1.19 kB
build/product-add-to-cart--product-button.js 565 B
build/product-add-to-cart-frontend.js 6.96 kB
build/product-button-frontend.js 1.84 kB
build/product-category-list-frontend.js 926 B
build/product-category-list.js 501 B
build/product-image-frontend.js 1.84 kB
build/product-new.js 7.68 kB
build/product-price-frontend.js 1.94 kB
build/product-rating-frontend.js 1.15 kB
build/product-sale-badge-frontend.js 1.09 kB
build/product-sku-frontend.js 380 B
build/product-sku.js 381 B
build/product-stock-indicator-frontend.js 1.03 kB
build/product-summary-frontend.js 1.33 kB
build/product-tag-list-frontend.js 918 B
build/product-tag-list.js 496 B
build/product-title-frontend.js 1.29 kB
build/reviews-frontend.js 7 kB
build/single-product-frontend.js 21.5 kB
build/stock-filter-frontend.js 6.5 kB
build/vendors--cart-blocks/cart-line-items--cart-blocks/cart-order-summary--cart-blocks/order-summary-shi--c02aad66-frontend.js 5.26 kB
build/vendors--cart-blocks/cart-line-items--checkout-blocks/order-summary-cart-items--mini-cart-contents---233ab542-frontend.js 3.14 kB
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--5b8feb0b-frontend.js 4.75 kB
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--decc3dc6-frontend.js 20.5 kB
build/vendors--mini-cart-contents-block/footer-frontend.js 6.86 kB
build/vendors--product-add-to-cart-frontend.js 7.53 kB
build/wc-blocks-data.js 9.87 kB
build/wc-blocks-editor-style-rtl.css 4.92 kB
build/wc-blocks-editor-style.css 4.92 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 930 B
build/wc-blocks-registry.js 2.7 kB
build/wc-blocks-shared-context.js 1.52 kB
build/wc-blocks-shared-hocs.js 1.14 kB
build/wc-blocks-vendors-style-rtl.css 1.28 kB
build/wc-blocks-vendors-style.css 1.28 kB
build/wc-payment-method-bacs.js 816 B
build/wc-payment-method-cheque.js 811 B
build/wc-payment-method-cod.js 909 B
build/wc-payment-method-paypal.js 837 B
build/wc-settings.js 2.61 kB

compressed-size-action

Copy link
Contributor

@tjcafferkey tjcafferkey left a comment

Choose a reason for hiding this comment

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

Each step checks out, and works as you described. However the block on the frontend does not look like it does in the editor. I've screenshotted what I've seen on my end along with the settings I have for the block.

Syntax Description
Settings 1 Screenshot 2022-04-18 at 10 10 42
Settings 2 Screenshot 2022-04-18 at 10 10 49
Editor Screenshot 2022-04-18 at 10 10 37
Frontend Screenshot 2022-04-18 at 10 10 54

@@ -70,6 +77,14 @@ const FeaturedCategory = ( {
debouncedSpeak,
triggerUrlUpdate = () => void null,
} ) => {
const { gradientValue, setGradient } = useGradient();
const onResize = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it is worth debouncing this callback if it's going to be executed on every resize event?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually it looks like it's already taken care of within the <ConstrainedResizable /> component, but if you could just confirm?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I can confirm. I've added useThrottle in this commit to make it easier to create throttled callbacks. I decided to go with throttling instead of debouncing here, because the approach in this case felt a bit more appropriate and responsive.

Gutenberg doesn't do this, by the way, and I was thinking whether I should make a PR to things like the Cover block to throttle/debounce their resize events at some point.

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
featured-category.js react, wp-is-shallow-equal ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@sunyatasattva
Copy link
Contributor Author

However the block on the frontend does not look like it does in the editor.

Thanks for spotting that. I think I know the problem, I'll take care of it at once!

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
featured-category.js react, wp-is-shallow-equal ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@sunyatasattva
Copy link
Contributor Author

@tjcafferkey This should work now 🙏

@tjcafferkey
Copy link
Contributor

tjcafferkey commented Apr 19, 2022

For some reason I'm still not getting a consistent block between the editor and the frontend? I'm using theme TwentyTwenty-Two, perhaps I am doing something wrong but I can't see what?

It looks like you also missed a suggested change which is resulting in a corrupt block. #6276 (comment)

Editor:
Screenshot 2022-04-19 at 09 32 56

Frontend
Screenshot 2022-04-19 at 09 33 00

@sunyatasattva
Copy link
Contributor Author

It looks like you also missed a suggested change which is resulting in a corrupt block.

This seems to indicate the problem, maybe pulling was unsuccessful on your side or something like that? 🤔

I have included your suggested change in this commit. So, something seems to be wrong with updating? 🤔

@tjcafferkey
Copy link
Contributor

I have included your suggested change in this commit. So, something seems to be wrong with updating? 🤔

Sorry, I was also testing the Featured Product block (where you also made changes) which is the other place I suggested you make the same change you made in that commit (so there are two in total)

@sunyatasattva
Copy link
Contributor Author

Oh I see, thanks for pointing that out! Fixed!

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
featured-category.js react, wp-is-shallow-equal ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@sunyatasattva sunyatasattva force-pushed the feature/6151-featured-category-styles branch from 9bce994 to daaa085 Compare April 19, 2022 14:14
@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
featured-category.js react, wp-is-shallow-equal ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
featured-category.js react, wp-is-shallow-equal ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
featured-category.js react, wp-is-shallow-equal ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@tjcafferkey
Copy link
Contributor

tjcafferkey commented Apr 20, 2022

Thanks for making those changes @sunyatasattva it looks like it is almost there! One thing I've noticed is when I add some padding (100px) then it doesn't quite look the same in the Editor vs the Frontend. Please see below, is there anything we can do about this? The same happens with the Featured Product block too it seems.

Editor Frontend
Screenshot 2022-04-20 at 08 37 59 Screenshot 2022-04-20 at 08 38 07

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
featured-category.js react, wp-is-shallow-equal ⚠️

This comment was automatically generated by the ./github/compare-assets action.

Copy link
Contributor

@tjcafferkey tjcafferkey left a comment

Choose a reason for hiding this comment

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

Works great now, thank you for sorting those issues!

@github-actions github-actions bot added this to the 7.5.0 milestone Apr 21, 2022
@tjcafferkey
Copy link
Contributor

Failing E2E test is unrelated. Merging anyway.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: featured product Issues related to the Featured Product block. block-type: product Issues related to/affecting all blocks related to products. focus: blocks Specific work involving or impacting how blocks behave. focus: global styles Issues that involve styles/css/layout structure. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update the Featured Category block with more styles/options
3 participants