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

Refactor: Use an alternative mini cart icon to fix the Mini Cart styling issues #5985

Merged
merged 11 commits into from
Mar 9, 2022

Conversation

dinhtungdu
Copy link
Member

Fixes #5930

The current Mini Cart icon leads to some difficulties and style issues:

  • We need the background for the counter (badge) => an extra setting which isn't really necessary.
  • The theme block doesn't work great with dark themes (at least, out of the box).
    • For a special case - Twenty Twenty Two - its large header page template uses a dark header, while other pages use the normal white header. The Mini Cart doesn't work with it.
    • Increase code complexity: because we need to style an inner element of the Mini Cart block, we need __experimentalSkipSerialization to target inner elements for global style. We also need to calculate manually color classes and style inside the block component.

This PR tries to solve all of the above issues by using the icon as proposed here. By using that icon, we can:

  • Remove the background setting which is useless now.
  • Remove the transparent button option, which doesn't make sense anymore without the background setting.
  • Remove __experimentalSkipSerialization, let Blocks Editor and Site Editor target the Mini Cart block using .wp-block-woocommerce-mini-cart.
  • Remove color and class manipulation for the counter.
  • Icon inherits the color from the parent by default, so it works with both dark and light backgrounds, and at the same time.

Accessibility

Other Checks

  • I've updated this doc for any feature flags or experimental interfaces implemented in this pull request.
  • I tagged two reviewers because this PR makes queries to the database or I think it might have some security impact.

Screenshots

image

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. Add the block to the header.
  2. Make sure it works by default with Twenty Twenty Two. On both dark and light headers.
  3. Test the predefined color and custom color for block style and global style.
  4. Ensure the block style priority is higher than global style.

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, or
  • See steps below.

Notes

  • Look like the Site Editor is having an issue clearing the global style cache. Changing the global text color for the Mini Cart icon works after load. But it doesn't work if we keep the editor open:
    • Go to Site Editor > Style (Beta) > Blocks Styles > Mini Cart.
    • Change the text color > Save it.
    • Keep the current tab open, in a new tab, go to the site front-end, see the text color has been updated correctly.
    • Switch to the site editor tab, change the text color of the mini cart to another, see it work on the Editor > Save.
    • Switch to the front end tab, reload the editor, see the color still the previous value.

@dinhtungdu dinhtungdu self-assigned this Mar 3, 2022
@rubikuserbot rubikuserbot requested review from a team and tjcafferkey and removed request for a team March 3, 2022 11:53
@dinhtungdu dinhtungdu added type: refactor The issue/PR is related to refactoring. skip-changelog PRs that you don't want to appear in the changelog. status: needs review type: bug The issue/PR concerns a confirmed bug. block: mini-cart Issues related to the Mini-Cart block. labels Mar 3, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2022

Size Change: +327 B (0%)

Total Size: 864 kB

Filename Size Change
build/all-products.js 34 kB -3 B (0%)
build/atomic-block-components/add-to-cart.js 7.49 kB +1 B (0%)
build/mini-cart-component-frontend.js 16.5 kB +465 B (+3%)
build/mini-cart.js 6.33 kB -61 B (-1%)
build/single-product.js 10 kB -3 B (0%)
build/wc-blocks-style-rtl.css 22.2 kB -147 B (-1%)
build/wc-blocks-style.css 22.2 kB -143 B (-1%)
build/wc-blocks-vendors.js 69.6 kB +218 B (0%)
ℹ️ View Unchanged
Filename Size
build/active-filters-frontend.js 6.28 kB
build/active-filters.js 6.97 kB
build/all-products-frontend.js 18.6 kB
build/all-reviews.js 8.03 kB
build/atomic-block-components/add-to-cart--atomic-block-components/button--atomic-block-components/catego--90468e1a.js 223 B
build/atomic-block-components/add-to-cart--atomic-block-components/button--atomic-block-components/image---a7e2bb9b.js 2.64 kB
build/atomic-block-components/add-to-cart-frontend.js 7.01 kB
build/atomic-block-components/button--atomic-block-components/category-list--atomic-block-components/imag--f11cdc7a.js 501 B
build/atomic-block-components/button-frontend.js 2.08 kB
build/atomic-block-components/button.js 2.3 kB
build/atomic-block-components/category-list-frontend.js 922 B
build/atomic-block-components/category-list.js 500 B
build/atomic-block-components/image-frontend.js 1.86 kB
build/atomic-block-components/image.js 1.08 kB
build/atomic-block-components/price-frontend.js 1.95 kB
build/atomic-block-components/price.js 1.51 kB
build/atomic-block-components/rating-frontend.js 1.14 kB
build/atomic-block-components/rating.js 717 B
build/atomic-block-components/sale-badge-frontend.js 1.1 kB
build/atomic-block-components/sale-badge.js 683 B
build/atomic-block-components/sku-frontend.js 386 B
build/atomic-block-components/sku.js 386 B
build/atomic-block-components/stock-indicator-frontend.js 1.04 kB
build/atomic-block-components/stock-indicator.js 623 B
build/atomic-block-components/summary-frontend.js 1.34 kB
build/atomic-block-components/summary.js 923 B
build/atomic-block-components/tag-list-frontend.js 923 B
build/atomic-block-components/tag-list.js 498 B
build/atomic-block-components/title-frontend.js 1.31 kB
build/atomic-block-components/title.js 933 B
build/attribute-filter-frontend.js 16.8 kB
build/attribute-filter.js 13.1 kB
build/blocks-checkout.js 17.4 kB
build/cart-blocks/accepted-payment-methods-frontend.js 1.16 kB
build/cart-blocks/checkout-button-frontend.js 1.16 kB
build/cart-blocks/empty-cart-frontend.js 346 B
build/cart-blocks/express-payment-frontend.js 5.2 kB
build/cart-blocks/filled-cart-frontend.js 767 B
build/cart-blocks/items-frontend.js 298 B
build/cart-blocks/line-items-frontend.js 5.5 kB
build/cart-blocks/order-summary-frontend.js 8.88 kB
build/cart-blocks/totals-frontend.js 321 B
build/cart-frontend.js 45.3 kB
build/cart.js 43.6 kB
build/checkout-blocks/actions-frontend.js 1.41 kB
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 4.13 kB
build/checkout-blocks/billing-address-frontend.js 891 B
build/checkout-blocks/contact-information-frontend.js 2.84 kB
build/checkout-blocks/express-payment-frontend.js 5.5 kB
build/checkout-blocks/fields-frontend.js 345 B
build/checkout-blocks/order-note-frontend.js 1.13 kB
build/checkout-blocks/order-summary-frontend.js 11.3 kB
build/checkout-blocks/payment-frontend.js 7.78 kB
build/checkout-blocks/shipping-address-frontend.js 997 B
build/checkout-blocks/shipping-methods-frontend.js 4.73 kB
build/checkout-blocks/terms-frontend.js 1.22 kB
build/checkout-blocks/totals-frontend.js 325 B
build/checkout-frontend.js 47.5 kB
build/checkout.js 44.8 kB
build/featured-category.js 8.63 kB
build/featured-product.js 9.73 kB
build/handpicked-products.js 7.11 kB
build/legacy-template.js 2.19 kB
build/mini-cart-contents-block/empty-cart-frontend.js 328 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 5.33 kB
build/mini-cart-contents-block/footer-frontend.js 5.67 kB
build/mini-cart-contents-block/items-frontend.js 225 B
build/mini-cart-contents-block/products-table-frontend.js 5.36 kB
build/mini-cart-contents-block/shopping-button-frontend.js 288 B
build/mini-cart-contents-block/title-frontend.js 367 B
build/mini-cart-contents.js 23.6 kB
build/mini-cart-frontend.js 1.72 kB
build/price-filter-frontend.js 12.5 kB
build/price-filter.js 8.49 kB
build/price-format.js 1.19 kB
build/product-best-sellers.js 7.39 kB
build/product-categories.js 3.17 kB
build/product-category.js 8.5 kB
build/product-new.js 7.68 kB
build/product-on-sale.js 8 kB
build/product-search.js 2.19 kB
build/product-tag.js 7.83 kB
build/product-top-rated.js 7.92 kB
build/products-by-attribute.js 8.4 kB
build/reviews-by-category.js 11.5 kB
build/reviews-by-product.js 12.6 kB
build/reviews-frontend.js 7.34 kB
build/single-product-frontend.js 22 kB
build/stock-filter-frontend.js 6.5 kB
build/stock-filter.js 6.58 kB
build/vendors--atomic-block-components/add-to-cart--cart-blocks/order-summary--checkout-blocks/billing-ad--c5eb4dcd-frontend.js 19 kB
build/vendors--atomic-block-components/add-to-cart-frontend.js 7.51 kB
build/vendors--atomic-block-components/price--cart-blocks/line-items--cart-blocks/order-summary--checkout--194c50bf-frontend.js 5.26 kB
build/vendors--cart-blocks/line-items--checkout-blocks/order-summary--mini-cart-contents-block/products-table-frontend.js 3.14 kB
build/vendors--cart-blocks/order-summary--checkout-blocks/billing-address--checkout-blocks/order-summary---eb4d2cec-frontend.js 4.74 kB
build/vendors--mini-cart-contents-block/footer--mini-cart-contents-block/products-table-frontend.js 7.71 kB
build/wc-blocks-data.js 9.83 kB
build/wc-blocks-editor-style-rtl.css 4.84 kB
build/wc-blocks-editor-style.css 4.84 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 953 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-blocks.js 2.62 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

@dinhtungdu dinhtungdu requested review from Aljullu and gigitux March 3, 2022 12:30
@dinhtungdu
Copy link
Member Author

Requested additional reviews from Albert and Luigi because this changed how we style the Mini Cart block.

Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

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

I like this approach and it's really cool to see how much code could be removed. 👏 My only concern is that it removes the background color setting. Was that intentional? I think we should try to keep it.

Ie, in trunk it's possible to change the styles of the Mini Cart button to something like this:

imatge

@dinhtungdu
Copy link
Member Author

@Aljullu I added the background back in 5a11609

My only concern is that it removes the background color setting. Was that intentional?

Yes, I removed the background because I don't want to use experimental features and the background setting was initially created for the badge background. But I agree with you that having the ability to set the background for the button is actually useful.

@dinhtungdu dinhtungdu requested a review from Aljullu March 4, 2022 03:33
Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

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

Works perfectly now, thanks @dinhtungdu! I just have one last question: why do we need to use __experimentalSelector and __experimentalSkipSerialization? Can't we apply the background styles directly into the wrapper element (.wc-block-mini-cart)?

@dinhtungdu
Copy link
Member Author

dinhtungdu commented Mar 4, 2022

why do we need to use __experimentalSelector and __experimentalSkipSerialization? Can't we apply the background styles directly into the wrapper element (.wc-block-mini-cart)?

@Aljullu If we apply the style to the wrapper element, this will happen.

image

At glance, we can solve this problem by styling the wrapper as an inline block. But we will have an issue with alignment because we need the wrapper full width (to its container) for the alignment to work.

By default, the Global style target the wrapper element (.wp-block-woocommerce-mini-cart in our case). It works fine with text color, but not with background color. That's why we need __experimentalSelector.

About __experimentalSkipSerialization, we need that flag to prevent Site Editor generate inline style for Mini Cart block, which is injected into the wrapper element.

Alternative options

Actually, there is another way to solve this problem, to make styling work without experimental features

<Button> block is an inline element. It often comes with <Buttons> as the wrapper for multiple <Button> blocks. The <Buttons> block provides alignment for inner blocks.

We can apply the approach of the <Button> block to Mini Cart block by removing the alignment and styling it as an inline element. If we need alignment, we can use a <Row> block and add <MiniCart> as an inner block. By doing so, we don't need experimental flags and we can reduce even more lines of code. But it makes the block harder to use at the same time IMO.

Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

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

Oh, I missed that, thanks @dinhtungdu! I was in fact testing it inside a Row block, that's why I missed it. 😅

Let's merge this PR as-is. However, I would like us to try to get rid of those experimental APIs. Otherwise, we can only enable background color controls in the Feature Plugin (but not in WC core), and that would be a missed opportunity. 😞

We can apply the approach of the block to Mini Cart block by removing the alignment and styling it as an inline element. If we need alignment, we can use a block and add as an inner block. By doing so, we don't need experimental flags and we can reduce even more lines of code. But it makes the block harder to use at the same time IMO.

I like this solution. How do you feel about creating a PR to experiment with it? Honestly, I think most usages of the Mini Cart block will come once we start adding it to patterns, so we will be able to control where it renders. Another thing to consider is that at some point we would like to make the Mini Cart block available inside the Navigation block, that would remove another instance of needing it to have alignment for itself.

cc'ing @gigitux here too for his thoughts on this.

@gigitux
Copy link
Contributor

gigitux commented Mar 4, 2022

Oh, I missed that, thanks @dinhtungdu! I was in fact testing it inside a Row block, that's why I missed it. 😅

Let's merge this PR as-is. However, I would like us to try to get rid of those experimental APIs. Otherwise, we can only enable background color controls in the Feature Plugin (but not in WC core), and that would be a missed opportunity. 😞

We can apply the approach of the block to Mini Cart block by removing the alignment and styling it as an inline element. If we need alignment, we can use a block and add as an inner block. By doing so, we don't need experimental flags and we can reduce even more lines of code. But it makes the block harder to use at the same time IMO.

I like this solution. How do you feel about creating a PR to experiment with it? Honestly, I think most usages of the Mini Cart block will come once we start adding it to patterns, so we will be able to control where it renders. Another thing to consider is that at some point we would like to make the Mini Cart block available inside the Navigation block, that would remove another instance of needing it to have alignment for itself.

cc'ing @gigitux here too for his thoughts on this.

I agree with @dinhtungdu's thoughts. I guess, in accordance with our goal, for the next block we should follow the alternative solution. We should avoid using custom style and use the blocks that Gutenberg makes available for positioning as much as possible.
I don't know how difficult this approach is, but if it doesn't take long, could we try it, so we can avoid a future block migration?

@dinhtungdu dinhtungdu changed the title Refactor: Use an alternative approach to fix the Mini Cart styling issues Refactor: Use an alternative mini cart icon to fix the Mini Cart styling issues Mar 7, 2022
@dinhtungdu
Copy link
Member Author

How do you feel about creating a PR to experiment with it?

#6002 is the attempt to remove the experimental flags and simplify the codebase.

@dinhtungdu dinhtungdu requested a review from Aljullu March 8, 2022 10:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: mini-cart Issues related to the Mini-Cart block. skip-changelog PRs that you don't want to appear in the changelog. type: bug The issue/PR concerns a confirmed bug. type: refactor The issue/PR is related to refactoring.
Projects
None yet
4 participants