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

Add Fill & Outline styles, width settings & new typography controls for Product(Add to cart) button block #8781

Merged
merged 18 commits into from
Mar 24, 2023

Conversation

imanish003
Copy link
Contributor

@imanish003 imanish003 commented Mar 18, 2023

This PR is part of #8085 & adds following controls to product(Add to cart) button in Inspector controls.

Styles: Fill & Outline

Here is a quick demo video:

Screen.Recording.2023-03-18.at.12.16.44.PM.mov

Width Settings

The button block now has a width selector, which allows the user to set the button to 25%, 50%, 75%, or 100% of the parent container. By default, a button's width is determined by the size of its content.

You can find this setting in the button block's sidebar.
image

Typography controls

Now following typography controls are also available:

  • Font Family
  • Appearance
  • Line height
  • Letter spacing
  • Decoration
  • Letter case

Testing

Automated Tests

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

User Facing Testing

  • Create a new post & add Products block to it.
  • In products block, you can find Add to cart button as shown in screenshot below

image

- In the sidebar, you will see all newly added controls

image

  • Following newly added controls should work as expected:

    • Styles: Fill & Outline ( Feature plugin )
    • Width Settings ( Feature Plugin + WooCommerce Core )
    • Typography controls ( Feature plugin )
  • Also, block.tsx file is imported by Cross-sells products here. So make sure that Add to cart button still works fine for Cross-sell products. You can find more about cross-sell products here.

Known issues

  • Although all of new controls should also work for Add to cart button in All products block, but due to already reported issue #7930, these won't work for now. IMO, This issue should be fixed when we will work on #7930 issue. What do you think?
  • Do not include in the Testing Notes

WooCommerce Visibility

  • WooCommerce Core
  • Feature plugin
  • Experimental

Changelog

Add Fill & Outline styles, width settings & new typography controls for Product(Add to cart) button block.

This commit adds the Fill & Outline styles to the Product button block.
You can see new Styles section in Inspector Controls where you will be able to change between Fill & Outline styles.
The button block now has a width selector, which allows the user to
set the button to 25%, 50%, 75%, or 100% of the parent container.
By default, a button's width is determined by the size of its content.

You can find this setting in the button block's sidebar.
Now following typography controls are also available:
- Font Family
- Appearance
- Line height
- Letter spacing
- Decoration
- Letter case
@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2023

The release ZIP for this PR is accessible via:

https://wcblocks.wpcomstaging.com/wp-content/uploads/woocommerce-gutenberg-products-block-8781.zip

Script Dependencies Report

There is no changed script dependency between this branch and trunk.

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

TypeScript Errors Report

  • Files with errors: 479
  • Total errors: 2304

⚠️ ⚠️ This PR introduces new TS errors on 1 files:

assets/js/blocks/products/base-utils.js

comments-aggregator

@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2023

Size Change: +492 B (0%)

Total Size: 1.07 MB

Filename Size Change
build/all-products.js 37.1 kB +311 B (+1%)
build/wc-blocks-style-rtl.css 27 kB +90 B (0%)
build/wc-blocks-style.css 27 kB +91 B (0%)
ℹ️ View Unchanged
Filename Size
build/active-filters-frontend.js 7.98 kB
build/active-filters-wrapper-frontend.js 5.97 kB
build/active-filters.js 7.49 kB
build/all-products-frontend.js 11.8 kB
build/all-reviews.js 7.65 kB
build/attribute-filter-frontend.js 22.4 kB
build/attribute-filter-wrapper-frontend.js 7.1 kB
build/attribute-filter.js 13.2 kB
build/blocks-checkout.js 44 kB
build/breadcrumbs.js 2.04 kB
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.38 kB
build/cart-blocks/cart-cross-sells-frontend.js 253 B
build/cart-blocks/cart-cross-sells-products-frontend.js 9.72 kB
build/cart-blocks/cart-express-payment--checkout-blocks/express-payment-frontend.js 5.2 kB
build/cart-blocks/cart-express-payment-frontend.js 717 B
build/cart-blocks/cart-items-frontend.js 302 B
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.36 kB
build/cart-blocks/cart-line-items-frontend.js 1.07 kB
build/cart-blocks/cart-order-summary-frontend.js 1.24 kB
build/cart-blocks/cart-totals-frontend.js 307 B
build/cart-blocks/empty-cart-frontend.js 345 B
build/cart-blocks/filled-cart-frontend.js 653 B
build/cart-blocks/order-summary-coupon-form-frontend.js 1.62 kB
build/cart-blocks/order-summary-discount-frontend.js 2.12 kB
build/cart-blocks/order-summary-fee-frontend.js 272 B
build/cart-blocks/order-summary-heading-frontend.js 455 B
build/cart-blocks/order-summary-shipping-frontend.js 10.7 kB
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.33 kB
build/cart-frontend.js 29.3 kB
build/cart.js 48.1 kB
build/catalog-sorting.js 1.7 kB
build/checkout-blocks/actions-frontend.js 1.85 kB
build/checkout-blocks/billing-address-frontend.js 4.18 kB
build/checkout-blocks/contact-information-frontend.js 2.05 kB
build/checkout-blocks/express-payment-frontend.js 1.14 kB
build/checkout-blocks/fields-frontend.js 331 B
build/checkout-blocks/order-note-frontend.js 1.14 kB
build/checkout-blocks/order-summary-cart-items-frontend.js 3.68 kB
build/checkout-blocks/order-summary-coupon-form-frontend.js 1.79 kB
build/checkout-blocks/order-summary-discount-frontend.js 2.29 kB
build/checkout-blocks/order-summary-fee-frontend.js 275 B
build/checkout-blocks/order-summary-frontend.js 1.24 kB
build/checkout-blocks/order-summary-shipping-frontend.js 10.8 kB
build/checkout-blocks/order-summary-subtotal-frontend.js 273 B
build/checkout-blocks/order-summary-taxes-frontend.js 433 B
build/checkout-blocks/payment-frontend.js 8.39 kB
build/checkout-blocks/pickup-options-frontend.js 4.04 kB
build/checkout-blocks/shipping-address-frontend.js 4.14 kB
build/checkout-blocks/shipping-method-frontend.js 2.61 kB
build/checkout-blocks/shipping-methods-frontend.js 4.82 kB
build/checkout-blocks/terms-frontend.js 1.56 kB
build/checkout-blocks/totals-frontend.js 310 B
build/checkout-frontend.js 30.9 kB
build/checkout.js 45.8 kB
build/customer-account.js 3.16 kB
build/featured-category.js 14 kB
build/featured-product.js 14.4 kB
build/filter-wrapper-frontend.js 14 kB
build/filter-wrapper.js 2.4 kB
build/general-style-rtl.css 1.31 kB
build/general-style.css 1.31 kB
build/handpicked-products.js 7.92 kB
build/legacy-template.js 5.56 kB
build/mini-cart-component-frontend.js 28.2 kB
build/mini-cart-contents-block/cart-button-frontend.js 703 B
build/mini-cart-contents-block/checkout-button-frontend.js 696 B
build/mini-cart-contents-block/empty-cart-frontend.js 360 B
build/mini-cart-contents-block/filled-cart-frontend.js 268 B
build/mini-cart-contents-block/footer-frontend.js 3.11 kB
build/mini-cart-contents-block/items-frontend.js 237 B
build/mini-cart-contents-block/products-table-frontend.js 589 B
build/mini-cart-contents-block/shopping-button-frontend.js 573 B
build/mini-cart-contents-block/title-frontend.js 368 B
build/mini-cart-contents.js 17.1 kB
build/mini-cart-frontend.js 2.02 kB
build/mini-cart.js 4.49 kB
build/price-filter-frontend.js 13.9 kB
build/price-filter-wrapper-frontend.js 6.96 kB
build/price-filter.js 8.4 kB
build/price-format.js 1.19 kB
build/product-add-to-cart-frontend.js 6.43 kB
build/product-add-to-cart.js 178 B
build/product-best-sellers.js 8.26 kB
build/product-button-frontend.js 1.92 kB
build/product-categories.js 2.36 kB
build/product-category.js 9.25 kB
build/product-image-frontend.js 1.77 kB
build/product-image.js 178 B
build/product-new.js 8.26 kB
build/product-on-sale.js 8.59 kB
build/product-price-frontend.js 2.08 kB
build/product-query.js 11 kB
build/product-rating-frontend.js 1.33 kB
build/product-results-count.js 1.66 kB
build/product-sale-badge-frontend.js 977 B
build/product-search.js 2.63 kB
build/product-sku-frontend.js 454 B
build/product-stock-indicator-frontend.js 1.01 kB
build/product-summary-frontend.js 1.29 kB
build/product-tag.js 8.74 kB
build/product-title-frontend.js 1.37 kB
build/product-title.js 178 B
build/product-top-rated.js 8.5 kB
build/products-by-attribute.js 9.58 kB
build/rating-filter-frontend.js 20.8 kB
build/rating-filter-wrapper-frontend.js 5.58 kB
build/rating-filter.js 6.99 kB
build/reviews-by-category.js 11.9 kB
build/reviews-by-product.js 13 kB
build/reviews-frontend.js 7.11 kB
build/stock-filter-frontend.js 21 kB
build/stock-filter-wrapper-frontend.js 5.82 kB
build/stock-filter.js 7.7 kB
build/store-notices.js 1.69 kB
build/vendors--attribute-filter-wrapper--cart-blocks/cart-cross-sells-products--cart-blocks/order-summary--ef6753df-frontend.js 6.85 kB
build/vendors--attribute-filter-wrapper--rating-filter-wrapper--stock-filter-wrapper-frontend.js 7.7 kB
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/cart-line-items--cart-blocks/cart-order--3c5fe802-frontend.js 5.26 kB
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/order-summary-shipping--checkout-blocks--18f9376a-frontend.js 19.4 kB
build/vendors--cart-blocks/cart-cross-sells-products--product-add-to-cart-frontend.js 7.25 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/order-summary-shipping--checkout-block--24d3fc0c-frontend.js 8.24 kB
build/vendors--checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 5.44 kB
build/vendors--checkout-blocks/shipping-method-frontend.js 12 kB
build/wc-blocks-data.js 21.8 kB
build/wc-blocks-editor-style-rtl.css 5.78 kB
build/wc-blocks-editor-style.css 5.78 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 930 B
build/wc-blocks-registry.js 3.15 kB
build/wc-blocks-shared-context.js 1.52 kB
build/wc-blocks-shared-hocs.js 1.73 kB
build/wc-blocks-vendors-style-rtl.css 1.96 kB
build/wc-blocks-vendors-style.css 1.96 kB
build/wc-blocks-vendors.js 64.2 kB
build/wc-blocks.js 2.63 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.6 kB
build/wc-shipping-method-pickup-location.js 29.9 kB
build/woo-directives-runtime.js 2.73 kB
build/woo-directives-vendors.js 7.91 kB

compressed-size-action

@imanish003 imanish003 added focus: blocks Specific work involving or impacting how blocks behave. block-type: product elements Issues related to Product Element blocks. type: task The issue is an internally driven task (e.g. from another A8c team). block-type: product-query Issues related to/affecting all product-query variations. labels Mar 18, 2023
@imanish003 imanish003 marked this pull request as ready for review March 21, 2023 07:24
@woocommercebot woocommercebot requested review from a team and kmanijak and removed request for a team March 21, 2023 07:24
@imanish003 imanish003 requested a review from Aljullu March 21, 2023 07:24
@imanish003
Copy link
Contributor Author

Hi @Aljullu, I requested a review from you too, because following will require your opinion too:

Known issues
Although all of new controls should also work for Add to cart button in All products block, but due to already reported issue #7930, these won't work for now. IMO, This issue should be fixed when we will work on #7930 issue. What do you think?

Please find more details in PR description 🙏🏻

@imanish003 imanish003 changed the title Add more controls for Product(Add to cart) button Add more Inspector controls for Product(Add to cart) button Mar 21, 2023
@kmanijak
Copy link
Contributor

kmanijak commented Mar 21, 2023

Great work @imanish003!

I tested the solution and I found these two discrepancies:

Default button (without outline) is shorter on the frontend.

In Editor default and outlined button has the same height. Outlined button in the frontend as well. But default button on the frontend is shorter (smaller padding)

height.mov

100% width button that is technically an anchor exceeds the container (frontend)

"Select Options" or "View products" for variable and grouped products don't respect the container max width
image

Also, for small width (25%) they are wider

image

EDIT: The issue with width of anchor occurs only in Product Catalog, but not in a post


Although all of new controls should also work for Add to cart button in All products block, but due to already reported issue #7930, these won't work for now. IMO, This issue should be fixed when we will work on #7930 issue. What do you think?

My opinion is we skip that and focus on Products block, so I agree with you ☝️

@Aljullu
Copy link
Contributor

Aljullu commented Mar 21, 2023

  • Although all of new controls should also work for Add to cart button in All products block, but due to already reported issue #7930, these won't work for now.

That's weird, I'm no longer able to reproduce #7930 (I tested changing the color of the Add to Cart button):

Editor Frontend
imatge imatge

IMO, This issue should be fixed when we will work on #7930 issue. What do you think?

I don't think I'm entitled to make a decision on this. I agree that the priority is the Products block, but at the same time the All Products block is widely used so I'm not sure about having an experience that feels broken. Tagging @danielwrobert for his thoughts on this.

tl;dr when adding support for new styles to the Products block product element blocks, they are exposed to the All Products block product element blocks as well. To make these new styling options work in product element blocks inside All Products block, extra work is required.

Options we have:

  1. Don't fix it, as the priority right now is the Products block, we shouldn't spend time in the All Products block.
  2. Fix it, as the All Products block is widely used and it hasn't been officially deprecated yet.
  3. Somewhere in between: time-box some hours to see if it's easy to fix it in the All Products block. If it's easy, let's fix it, otherwise, let's leave it as-is and continue the work with the Products block.

(I lean towards option 3, but that depends on whether it's worth continuing spending time on the All Products block)

@danielwrobert
Copy link
Contributor

@Aljullu thank you for the ping and for the TL;DR - that's super helpful! 🍻

I agree with option 3. While we don’t want to leave the experience broken for folks who are currently using the All Products block, the Products Block is meant to replace it and we don’t want to let the former hinder the progress of the latter. Time-boxing to determine the necessary effort seems like a good balance.

@imanish003 since we already have an open Issue in #7930 it seems like we’re planning to address this either way - it’s just a matter of when – i.e., do we want to hold up the progress of this PR or, if it requires a more involved fix, merge it and circle back. Is that correct?

@imanish003
Copy link
Contributor Author

Hi @Aljullu @danielwrobert, Thank you for sharing your thoughts 🙏🏻

That's weird, I'm no longer able to reproduce #7930 (I tested changing the color of the Add to Cart button):

I also tested again, and it looks like all the controls are working fine except Width setting, which will be added in this PR. As this is something which will be introduced in this PR, therefore it makes sense that this should be fixed in this PR itself. I will look into it 🙂

Also, I think we may close #7930 if we can't reproduce it anymore.

In Editor default and outlined button has the same height. Outlined button in the frontend as well. But default button on the frontend is shorter (smaller padding)

More info: #8781 (comment)
@Aljullu
Copy link
Contributor

Aljullu commented Mar 22, 2023

Thanks!

Also, I think we may close #7930 if we can't reproduce it anymore.

I went ahead and closed it. 🙂

Edit: ups, by mistake I also closed this PR. I have reopened it. 😅

Fix following issues:
- "Select Options" or "View products" for variable and grouped products don't respect the container max width
- Also, for small width (25%) they are wider

More info: #8781 (comment)
@imanish003 imanish003 requested a review from kmanijak March 22, 2023 09:30
@imanish003
Copy link
Contributor Author

imanish003 commented Mar 22, 2023

Hi, @kmanijak 👋 I have made the requested changes except this one, in which I have replied to your suggestion for further discussion 🙂

Please let me know if you see any issues, except Width setting not working in All products block.

This commit fixes the width setting not working in the All Products block.
@imanish003
Copy link
Contributor Author

@Aljullu @kmanijak I have made changes in this commit to support Width Settings in All Products block. Can you please have a look? Because I am not 100% if that's the right way to do it. 🙏🏻

@kmanijak
Copy link
Contributor

kmanijak commented Mar 22, 2023

Hi, @kmanijak 👋 I have made the requested changes except #8781 (comment), in which I have replied to your suggestion for further discussion 🙂
Please let me know if you see any issues, except Width setting not working in All products block.

@Aljullu @kmanijak I have made changes in this commit to support Width Settings in All Products block. Can you please have a look? Because I am not 100% if that's the right way to do it. 🙏🏻

I retested and the issues I reported earlier are gone 💪 However, neither width nor outline is applied to the All Products on the frontend (they work fine in Editor).

EDIT:
After more testing:

  • Styles are applied correctly in the "Edit Mode" of All Products
  • Only Width is applied correctly in the Editor in "Preview Mode" - outline is ignored
  • Width is applied on the frontend from previous "Save" (e.g. if I change settings and save three times, what I see in frontend is the result of second save, not the last third one). Outline is ignored

`block.attributes.className` should be kept along with the width setting classes.
```
className: classnames( block.attributes.className, {
	[ `has-custom-width wp-block-button__width-${ block.attributes?.width }` ]:
		block.attributes?.width,
} )
```
@imanish003
Copy link
Contributor Author

@kmanijak I fixed the issue in ffa2c46. Thanks for pointing this out. 🙌🏻

Copy link
Contributor

@kmanijak kmanijak left a comment

Choose a reason for hiding this comment

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

Works like a charm in Products and All Products blocks! 💪

I left one small comment, so I'm pre-approving ✅

One question: you marked PR as a "Feature Plugin" but I don't see the width setting will enter the WC Core if I'm not mistaken. In that case I think it's better to mark "WC Core", what do you think?

@github-actions github-actions bot added this to the 9.9.0 milestone Mar 23, 2023
@imanish003
Copy link
Contributor Author

Hi @kmanijak, Thanks for pointing this out 🙌🏻

One question: you marked PR as a "Feature Plugin" but I don't see the width setting will enter the WC Core if I'm not mistaken. In that case I think it's better to mark "WC Core", what do you think?

You are right, As Width setting will be included in WC core too so I am checking both Feature plugin & WooCommerce Core checkbox for WooCommerce Visibility.

Also, I have updated testing step to include it i.e.:

Styles: Fill & Outline ( Feature plugin )
Width Settings ( Feature Plugin + WooCommerce Core )
Typography controls ( Feature plugin )

@imanish003 imanish003 merged commit 322a671 into trunk Mar 24, 2023
@imanish003 imanish003 deleted the add/8085-add-to-cart-button-functionalities branch March 24, 2023 07:08
@tarunvijwani tarunvijwani added the type: enhancement The issue is a request for an enhancement. label Mar 27, 2023
@tarunvijwani tarunvijwani changed the title Add more Inspector controls for Product(Add to cart) button Add Fill & Outline styles, width settings & new typography controls for Product(Add to cart) button block Mar 27, 2023
Aljullu added a commit that referenced this pull request Apr 19, 2023
@kmanijak kmanijak mentioned this pull request May 5, 2023
8 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block-type: product elements Issues related to Product Element blocks. block-type: product-query Issues related to/affecting all product-query variations. focus: blocks Specific work involving or impacting how blocks behave. type: enhancement The issue is a request for an enhancement. type: task The issue is an internally driven task (e.g. from another A8c team).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants