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

Product SKU: Adds support for color, typography, and spacing #8913

Merged
merged 12 commits into from
Apr 6, 2023

Conversation

imanish003
Copy link
Contributor

@imanish003 imanish003 commented Mar 31, 2023

This Pull Request enhances the styling capabilities of the Product SKU block by introducing additional support for color, typography & spacing. This improvement provides users with more flexibility when customizing the appearance of the Product SKU block.

Here is what Product SKU block supports now:

Color:

  • Text color
  • Background color

Typography:

  • Font family
  • Font size
  • Font Appearance
  • Line height
  • Letter spacing
  • Text decoration
  • Letter Case

Spacing:

  • Margin
  • Padding

Part of #8691 & #7954

User Facing Testing

Test using blocks sidebar

  • Create a new page or post
  • Add the "Products" block to your post.
  • Add Product SKU block as an inner block if not included already
  • Select the Product SKU block and open the block settings in the right sidebar.
  • Customize the block using the new styling options available:
    • Change the text color, background color, font family, font size, font appearance, line height, letter spacing, text decoration, letter case, margin, and padding under the appropriate settings sections.
  • Verify that the styling changes are immediately visible and applied correctly within the editor itself.
  • Save the post, then view it on the front-end to ensure the styling changes are visible and applied correctly.

Test using Global Styles

  • Open the Global Styles sidebar by clicking the "Styles" button at the top right corner of the editor.
Screen.Recording.2023-03-30.at.2.17.57.PM.mov
  • In the Global Styles sidebar, locate the "Product SKU" block.
  • Customize the block using the new styling options available under the "Product SKU" block in the Global Styles sidebar:
    • Change the text color, background color, font family, font size, font appearance, line height, letter spacing, text decoration, letter case, margin, and padding under the appropriate settings sections.
  • Verify that these applied correctly within editor & on frontend:
    • Create a new post
    • Add Products block
    • Add Product SKU block as an inner block if not included already
    • Check the Product SKU block in both the editor and on the front-end to ensure that the changes made through the Global styles UI are accurately applied:
      • In the editor, inspect Product SKU block & ensure it matches the values set in the Global styles UI.
      • Save the post & publish it. On frontend, inspect Product SKU block & ensure it matches the values set in the Global styles UI.

Also, verify the changes in All Products block, which also uses Product SKU block.

  • Do not include in the Testing Notes

WooCommerce Visibility

  • WooCommerce Core
  • Feature plugin
  • Experimental

Changelog

Enhance Product SKU block styling capabilities with additional support for color, typography & spacing

This commit introduces a new file `supports.ts` for the Product SKU block in the WooCommerce Blocks plugin, which adds color, typography, and spacing support. The following configuration has been added:

1. In `assets/js/atomic/blocks/product-elements/sku/supports.ts`, a new `supports` object is created, which extends the shared configuration and adds support for the following properties:
  - `text` and `background` color
  - `fontSize`, `lineHeight`, `__experimentalFontWeight`, `__experimentalFontFamily`, `__experimentalFontStyle`, `__experimentalTextTransform`, `__experimentalTextDecoration`, and `__experimentalLetterSpacing` for typography
  - `margin` and `padding` for spacing
…ll Products block

This commit extends the support for color, typography, and spacing to the Product SKU block when used within the All Products block. The following changes have been made:

1. In `assets/js/atomic/blocks/product-elements/sku/block.tsx`, the `useColorProps`, `useSpacingProps`, and `useTypographyProps` hooks are imported and used to add the appropriate className and style properties to the rendered SKU element.
2. In `assets/js/atomic/blocks/product-elements/sku/edit.tsx`, the `style` property is separated from `useBlockProps()` and used directly on the `div` element for the SKU block.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 31, 2023

The release ZIP for this PR is accessible via:

https://wcblocks.wpcomstaging.com/wp-content/uploads/woocommerce-gutenberg-products-block-8913.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: 450
  • Total errors: 2208

🎉 🎉 This PR does not introduce new TS errors.

comments-aggregator

@github-actions
Copy link
Contributor

github-actions bot commented Mar 31, 2023

Size Change: +787 B (0%)

Total Size: 1.06 MB

Filename Size Change
build/active-filters.js 7.49 kB +1 B (0%)
build/all-products-frontend.js 11.8 kB -4 B (0%)
build/all-products.js 37.8 kB +206 B (+1%)
build/all-reviews.js 7.65 kB -1 B (0%)
build/cart-blocks/cart-cross-sells-products-frontend.js 9.72 kB -2 B (0%)
build/cart-blocks/cart-express-payment--checkout-blocks/express-payment-frontend.js 5.2 kB -1 B (0%)
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.36 kB -3 B (0%)
build/cart-blocks/order-summary-coupon-form-frontend.js 1.62 kB -1 B (0%)
build/cart-blocks/order-summary-shipping-frontend.js 11.5 kB +2 B (0%)
build/cart.js 48.7 kB -1 B (0%)
build/checkout-blocks/billing-address-frontend.js 4.19 kB +1 B (0%)
build/checkout-blocks/contact-information-frontend.js 2.05 kB -1 B (0%)
build/checkout-blocks/order-summary-cart-items-frontend.js 3.68 kB -3 B (0%)
build/checkout-blocks/order-summary-coupon-form-frontend.js 1.78 kB -3 B (0%)
build/checkout-blocks/order-summary-shipping-frontend.js 11.6 kB +2 B (0%)
build/checkout-blocks/payment-frontend.js 8.79 kB +3 B (0%)
build/checkout-blocks/pickup-options-frontend.js 4.12 kB +2 B (0%)
build/checkout-blocks/shipping-address-frontend.js 4.14 kB +1 B (0%)
build/checkout-blocks/shipping-methods-frontend.js 5.82 kB +9 B (0%)
build/checkout-frontend.js 30.9 kB +3 B (0%)
build/checkout.js 46.4 kB +7 B (0%)
build/featured-category.js 14 kB -3 B (0%)
build/featured-product.js 14.4 kB -2 B (0%)
build/legacy-template.js 5.57 kB -1 B (0%)
build/mini-cart-contents-block/footer-frontend.js 3.18 kB -1 B (0%)
build/mini-cart-contents.js 17.4 kB +9 B (0%)
build/price-filter.js 8.41 kB +2 B (0%)
build/product-best-sellers.js 8.26 kB +1 B (0%)
build/product-button-frontend.js 1.91 kB -1 B (0%)
build/product-categories.js 2.37 kB +1 B (0%)
build/product-category.js 9.25 kB -1 B (0%)
build/product-image-frontend.js 1.76 kB -1 B (0%)
build/product-query.js 11 kB -1 B (0%)
build/product-rating-frontend.js 1.33 kB +5 B (0%)
build/product-search.js 2.63 kB -1 B (0%)
build/product-sku-frontend.js 999 B +545 B (+120%) 🆘
build/product-summary-frontend.js 1.29 kB -1 B (0%)
build/product-title-frontend.js 1.37 kB -4 B (0%)
build/product-top-rated.js 8.49 kB +1 B (0%)
build/products-by-attribute.js 9.58 kB +4 B (0%)
build/rating-filter.js 6.98 kB +2 B (0%)
build/stock-filter.js 7.7 kB +3 B (0%)
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/order-summary-shipping--checkout-blocks--18f9376a-frontend.js 19.4 kB +1 B (0%)
build/vendors--checkout-blocks/shipping-method-frontend.js 12 kB -2 B (0%)
build/wc-blocks-style-rtl.css 27.6 kB +6 B (0%)
build/wc-blocks-style.css 27.6 kB +6 B (0%)
build/wc-blocks-vendors.js 63.9 kB +3 B (0%)
ℹ️ View Unchanged
Filename Size
build/active-filters-frontend.js 7.99 kB
build/active-filters-wrapper-frontend.js 5.97 kB
build/attribute-filter-frontend.js 22.5 kB
build/attribute-filter-wrapper-frontend.js 7.1 kB
build/attribute-filter.js 13.2 kB
build/blocks-checkout.js 35.1 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-express-payment-frontend.js 718 B
build/cart-blocks/cart-items-frontend.js 301 B
build/cart-blocks/cart-line-items-frontend.js 1.06 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 654 B
build/cart-blocks/order-summary-discount-frontend.js 2.12 kB
build/cart-blocks/order-summary-fee-frontend.js 273 B
build/cart-blocks/order-summary-heading-frontend.js 455 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.33 kB
build/cart-frontend.js 29.3 kB
build/catalog-sorting.js 1.7 kB
build/checkout-blocks/actions-frontend.js 1.84 kB
build/checkout-blocks/express-payment-frontend.js 1.13 kB
build/checkout-blocks/fields-frontend.js 331 B
build/checkout-blocks/order-note-frontend.js 1.14 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-subtotal-frontend.js 273 B
build/checkout-blocks/order-summary-taxes-frontend.js 434 B
build/checkout-blocks/shipping-method-frontend.js 2.61 kB
build/checkout-blocks/terms-frontend.js 1.56 kB
build/checkout-blocks/totals-frontend.js 309 B
build/customer-account.js 3.17 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/mini-cart-component-frontend.js 28.3 kB
build/mini-cart-contents-block/cart-button-frontend.js 818 B
build/mini-cart-contents-block/checkout-button-frontend.js 819 B
build/mini-cart-contents-block/empty-cart-frontend.js 361 B
build/mini-cart-contents-block/filled-cart-frontend.js 268 B
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 704 B
build/mini-cart-contents-block/title-frontend.js 368 B
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-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-image.js 178 B
build/product-new.js 8.26 kB
build/product-on-sale.js 8.58 kB
build/product-price-frontend.js 2.08 kB
build/product-results-count.js 1.66 kB
build/product-sale-badge-frontend.js 974 B
build/product-stock-indicator-frontend.js 1.01 kB
build/product-tag.js 8.74 kB
build/product-title.js 178 B
build/rating-filter-frontend.js 20.8 kB
build/rating-filter-wrapper-frontend.js 5.58 kB
build/reviews-by-category.js 11.9 kB
build/reviews-by-product.js 13 kB
build/reviews-frontend.js 7.1 kB
build/stock-filter-frontend.js 21.1 kB
build/stock-filter-wrapper-frontend.js 5.82 kB
build/store-notices.js 1.69 kB
build/vendors--attribute-filter-wrapper--cart-blocks/cart-cross-sells-products--cart-blocks/order-summary--82e4ed06-frontend.js 6.84 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--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.25 kB
build/vendors--checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 5.44 kB
build/wc-blocks-data.js 21.8 kB
build/wc-blocks-editor-style-rtl.css 5.8 kB
build/wc-blocks-editor-style.css 5.8 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 933 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.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.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 changed the title Add/7954 product SKU global styles review Product SKU: Adds support for color, typography, and spacing Mar 31, 2023
This commit adds the ".wp-block-woocommerce-product-sku" class to the Product SKU Gutenberg block for server-side rendering purposes. The inclusion of this class ensures consistent styling between the editor and the front-end view of the block, providing a seamless experience for users.

The class name is generated based on the Gutenberg block prefix "wp-block", the namespace "woocommerce", and the block name "product-sku", creating a unique and identifiable class for the block. This class enables developers to target the block specifically in both the editor and front-end styles, maintaining the integrity of the block's appearance and functionality across different environments.

By adding this class to the server-side rendered version of the block, we ensure a unified and coherent styling experience throughout the block's usage.
@imanish003 imanish003 added type: enhancement The issue is a request for an enhancement. focus: blocks Specific work involving or impacting how blocks behave. block-type: product elements Issues related to Product Element blocks. block-type: product-query Issues related to/affecting all product-query variations. and removed block-type: product-query Issues related to/affecting all product-query variations. labels Mar 31, 2023
@imanish003 imanish003 marked this pull request as ready for review March 31, 2023 11:21
@woocommercebot woocommercebot requested review from a team and kmanijak and removed request for a team March 31, 2023 11:21
@imanish003
Copy link
Contributor Author

imanish003 commented Mar 31, 2023

@Aljullu, I am also adding you as reviewer because this PR adds isDescendantOfAllProducts flag for all products elements.
I noticed that product elements require special handling when used inside All products block. IMO this flag will be very useful in adding any new functionalities to product elements while still supporting All Products block.

I also considered creating a recursive function that checks block parents and their ancestors. Something like this:

function isDescendantOfAllProductsBlock(blockClientId, getBlockParents) {
  const parentClientIds = getBlockParents(blockClientId);

  if (parentClientIds.length === 0) {
    return false;
  }

  for (const parentId of parentClientIds) {
    const parentBlock = select('core/block-editor').getBlock(parentId);
    if (parentBlock.name === 'woocommerce/all-products') {
      return true;
    }

    if (isDescendantOfAllProductsBlock(parentId, getBlockParents)) {
      return true;
    }
  }

  return false;
}

But I dropped this idea because I thought this would have performance impact. Please let me know your thoughts about it 🙂

@imanish003 imanish003 requested a review from Aljullu March 31, 2023 11: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.

It's testing perfectly and code looks good to me. Nice improvement to the Product SKU block. 👏

Not sure if it's the expected behavior, but font-weight is only applied to the SKU: prefix, but not to the value:

imatge

@Aljullu, I am also adding you as reviewer because this PR adds isDescendantOfAllProducts flag for all products elements.

I see we have similar flag for other parent blocks, so it makes sense to me. 🙂

* External dependencies
*/
import { isFeaturePluginBuild } from '@woocommerce/block-settings';
import { __experimentalGetSpacingClassesAndStyles } from '@wordpress/block-editor';
Copy link
Contributor

Choose a reason for hiding this comment

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

Heads-up that this line introduced an ESLint warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ESLint warning is present wherever we use __experimentalGetSpacingClassesAndStyles, therefore I thought it was acceptable. However, I will add the following lines to ignore the warning going forward 🙂

// @ts-expect-error We check if this exists before using it.
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis

__experimentalTextDecoration: true,
__experimentalLetterSpacing: true,
},
__experimentalSelector: '.wc-block-components-product-sku',
Copy link
Contributor

Choose a reason for hiding this comment

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

Is __experimentalSelector required? I tried removing it and everything seemed to keep working as expected. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I think we can remove __experimentalSelector flag.

Comment on lines 15 to 21
color: {
text: true,
background: true,
},
typography: {
fontSize: true,
lineHeight: true,
Copy link
Contributor

@Aljullu Aljullu Apr 3, 2023

Choose a reason for hiding this comment

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

If we can remove __experimentalSelector, then we could make these styles available in WC core as well, so only the experimental ones would be gated to the feature plugin. 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense. I will make the necessary changes 🤝

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.

Thanks for taking care of this! Things I spotted while testing:

  1. Little caveat (edge case I think) is the text is wrapped in the Editor while it may escape the container in the frontend. Below is the example in All Products, but it behaves the same in Products block.
Editor Frontend
image image
  1. Letter case is not reflected in the Editor but it works ok in Frontend while used in GLobal Styles. Below you can see it's set to lowercase in Editor, but it's kept uppercase in there.
Editor Frontend
image image

Everything else looks good! I left some minor comments otherwise.

Also, the above may require the changes in Gutenberg, and in such case, I don't think they should block this PR from being merged 🙌

This commit refactors the Product SKU block supports to enable color, typography, and spacing features for all builds, while keeping experimental features specific to the feature plugin build. It also adds necessary lint and TypeScript error handling for the experimental spacing API.
@imanish003
Copy link
Contributor Author

imanish003 commented Apr 4, 2023

@Aljullu

Not sure if it's the expected behavior, but font-weight is only applied to the SKU: prefix, but not to the value:

Actually, we have value text in a strong tag:

<strong>{ value }</strong>

I thought we wanna keep strong tag. I don't have a strong opinion about it, if you want, I can remove the strong tag. 🙂

I see we have similar flag for other parent blocks, so it makes sense to me.

Excellent, this will simplify the process of keeping product elements compatible with the All products block! 🙌🏻

This commit adds the overflow-wrap property to the Product SKU block styles to handle long SKU values gracefully.
It also updates the comment for the experimental spacing API to better reflect the usage check.
This commit refactors the Product SKU block classname and style handling. It combines classnames for better readability and removes the hardcoded textTransform style in favor of default styles.
This also fix the issue where textTransform style was not working as expected.
@imanish003 imanish003 requested review from Aljullu and kmanijak April 4, 2023 09:46
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.

Looks good on my end, so approving. Leaving @kmanijak to do the final review on the items he brought up to the discussion.

I thought we wanna keep strong tag. I don't have a strong opinion about it, if you want, I can remove the strong tag. 🙂

I don't have a specific preference either. I would say let's keep it as-is now. At some point it might be good to get design feedback on it, though.

@github-actions github-actions bot added this to the 10.0.0 milestone Apr 5, 2023
@imanish003
Copy link
Contributor Author

@Aljullu I appreciate your valuable input 🙏 I agree with you; we can keep the strong tag for now, and as you suggested, we can seek design feedback at a later stage. I'll wait for @kmanijak final review and address any concerns he may have before merging this PR 🙌🏻

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.

I'll wait for @kmanijak final review and address any concerns he may have before merging this PR 🙌🏻

Excellent work! I double checked the previously raised glitches and smoke tested - all works as expected. Great work @imanish003! 💪

@imanish003 imanish003 merged commit 4566f40 into trunk Apr 6, 2023
@imanish003 imanish003 deleted the add/7954-product-sku-global-styles-review branch April 6, 2023 06:00
@opr
Copy link
Contributor

opr commented Apr 11, 2023

Hey @imanish003 when editing the case of the SKU block, it also affects the SKU itself. Is this intended? Would we prefer to display the SKU exactly as the merchant entered in the product page?

@imanish003
Copy link
Contributor Author

Is this intended? Would we prefer to display the SKU exactly as the merchant entered in the product page?

This is intended as per the current implementation. I understand your concern about displaying the SKU as the merchant entered it.
However, I'm not entirely sure whether we should display the SKU exactly as the merchant entered it because it is still possible to customize it the way merchant wants it using additional supports which were added in this PR.

Perhaps we could get input from @shaunandrews on this matter? 🙂

@kmanijak kmanijak mentioned this pull request May 5, 2023
9 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. focus: blocks Specific work involving or impacting how blocks behave. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants