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

Product Stock indicator: Add support for background color, margin, padding & various typography controls #8954

Merged
merged 18 commits into from
Apr 18, 2023

Conversation

imanish003
Copy link
Contributor

@imanish003 imanish003 commented Apr 4, 2023

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

Here is what Product Stock Indicator 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 #7954 & #8695

Testing

Test using blocks sidebar

  • Create a new page or post
  • Add the "Products" block to your post.
  • Add Product Stock Indicator block as an inner block if not included already
  • Select the Product Stock Indicator 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 correctly applied within the editor.
  • 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 Stock Indicator" block.
  • Customize the block using the new styling options available under the "Product Stock Indicator" 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 Stock Indicator block as an inner block if not included already
    • Check the Product Stock Indicator 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 Stock Indicator block & ensure it matches the values set in the Global styles UI.
      • Save the post & publish it. On frontend, inspect Product Stock Indicator block & ensure it matches the values set in the Global styles UI.

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

  • Do not include in the Testing Notes

WooCommerce Visibility

  • WooCommerce Core
  • Feature plugin
  • Experimental

Changelog

Product Stock indicator: Added support for background color, margin, padding & various typography controls

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.
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.
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.
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.
This commit updates the stock-indicator block support in the woocommerce-blocks repository. It includes the following changes:

- Added support for background color, line height, and various experimental typography features.
- Conditionally included support for margin and padding based on the availability of the __experimentalGetSpacingClassesAndStyles function from the @wordpress/block-editor package.

These updates provide more customization options for the stock-indicator block, allowing users to better match the appearance of this element to their site's design.
@imanish003 imanish003 changed the title Product SKU: Adds support for background color, typography, and spacing Product Stock indicator: Adds support for background color, typography, and spacing Apr 4, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Apr 4, 2023

The release ZIP for this PR is accessible via:

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

🎉 🎉 This PR does not introduce new TS errors.

comments-aggregator

@github-actions
Copy link
Contributor

github-actions bot commented Apr 4, 2023

Size Change: +453 B (0%)

Total Size: 1.11 MB

Filename Size Change
build/active-filters.js 7.49 kB -1 B (0%)
build/all-products-frontend.js 11.8 kB +6 B (0%)
build/all-products.js 38.5 kB +127 B (0%)
build/attribute-filter.js 13.2 kB +1 B (0%)
build/cart-blocks/cart-cross-sells-products-frontend.js 9.82 kB +2 B (0%)
build/checkout-frontend.js 30.9 kB -1 B (0%)
build/handpicked-products.js 7.92 kB +4 B (0%)
build/mini-cart-component-frontend.js 29.2 kB +2 B (0%)
build/mini-cart-contents-block/checkout-button-frontend.js 869 B -1 B (0%)
build/mini-cart-contents-block/shopping-button-frontend.js 760 B +1 B (0%)
build/mini-cart-contents-block/title-frontend.js 1.09 kB +2 B (0%)
build/mini-cart-contents-block/title-items-counter-frontend.js 733 B +1 B (0%)
build/mini-cart-contents-block/title-label-frontend.js 660 B +2 B (0%)
build/price-filter.js 8.46 kB -1 B (0%)
build/product-button--product-image--product-price--product-rating--product-sale-badge--product-sku--product-title.js 0 B -262 B (removed) 🏆
build/product-button-frontend.js 1.92 kB +1 B (0%)
build/product-button.js 4.17 kB +1 B (0%)
build/product-image-frontend.js 1.83 kB +2 B (0%)
build/product-price-frontend.js 2.12 kB +1 B (0%)
build/product-price.js 1.67 kB +1 B (0%)
build/product-query.js 11.3 kB +1 B (0%)
build/product-rating-frontend.js 1.33 kB +1 B (0%)
build/product-sale-badge-frontend.js 976 B +2 B (0%)
build/product-sale-badge.js 799 B +2 B (0%)
build/product-sku.js 577 B +1 B (0%)
build/product-stock-indicator-frontend.js 1.19 kB +176 B (+17%) ⚠️
build/product-stock-indicator.js 770 B +123 B (+19%) ⚠️
build/product-summary.js 922 B -1 B (0%)
build/product-title-frontend.js 1.37 kB +2 B (0%)
build/product-title.js 3.73 kB +2 B (0%)
build/products-by-attribute.js 9.59 kB -1 B (0%)
build/rating-filter.js 6.98 kB -1 B (0%)
build/stock-filter.js 7.71 kB -2 B (0%)
build/vendors--checkout-blocks/shipping-method-frontend.js 12 kB -2 B (0%)
build/product-button--product-image--product-price--product-rating--product-sale-badge--product-sku--prod--408017d2.js 262 B +262 B (new file) 🆕
ℹ️ View Unchanged
Filename Size
build/active-filters-frontend.js 7.99 kB
build/active-filters-wrapper-frontend.js 5.97 kB
build/all-reviews.js 7.66 kB
build/attribute-filter-frontend.js 22.4 kB
build/attribute-filter-wrapper-frontend.js 7.07 kB
build/blocks-checkout.js 35.1 kB
build/breadcrumbs.js 2.05 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--checkout-blocks/express-payment-frontend.js 5.16 kB
build/cart-blocks/cart-express-payment-frontend.js 720 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.4 kB
build/cart-blocks/cart-line-items-frontend.js 1.06 kB
build/cart-blocks/cart-order-summary-frontend.js 1.27 kB
build/cart-blocks/cart-totals-frontend.js 308 B
build/cart-blocks/empty-cart-frontend.js 346 B
build/cart-blocks/filled-cart-frontend.js 656 B
build/cart-blocks/order-summary-coupon-form-frontend.js 1.63 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 11.8 kB
build/cart-blocks/order-summary-subtotal-frontend.js 273 B
build/cart-blocks/order-summary-taxes-frontend.js 431 B
build/cart-blocks/proceed-to-checkout-frontend.js 1.33 kB
build/cart-frontend.js 29.3 kB
build/cart.js 48.7 kB
build/catalog-sorting.js 1.7 kB
build/checkout-blocks/actions-frontend.js 1.84 kB
build/checkout-blocks/billing-address-frontend.js 4.19 kB
build/checkout-blocks/contact-information-frontend.js 2.05 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-cart-items-frontend.js 3.71 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.28 kB
build/checkout-blocks/order-summary-shipping-frontend.js 11.8 kB
build/checkout-blocks/order-summary-subtotal-frontend.js 273 B
build/checkout-blocks/order-summary-taxes-frontend.js 431 B
build/checkout-blocks/payment-frontend.js 8.27 kB
build/checkout-blocks/pickup-options-frontend.js 4.14 kB
build/checkout-blocks/shipping-address-frontend.js 4.14 kB
build/checkout-blocks/shipping-method-frontend.js 2.63 kB
build/checkout-blocks/shipping-methods-frontend.js 5.83 kB
build/checkout-blocks/terms-frontend.js 1.56 kB
build/checkout-blocks/totals-frontend.js 310 B
build/checkout.js 46.3 kB
build/customer-account.js 3.17 kB
build/featured-category.js 14.1 kB
build/featured-product.js 14.3 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/legacy-template.js 5.63 kB
build/mini-cart-contents-block/cart-button-frontend.js 867 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.2 kB
build/mini-cart-contents-block/items-frontend.js 237 B
build/mini-cart-contents-block/products-table-frontend.js 588 B
build/mini-cart-contents.js 17.8 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 7.04 kB
build/price-format.js 1.19 kB
build/product-add-to-cart--product-button--product-image--product-price--product-rating--product-sale-bad--49d3ecb2.js 253 B
build/product-add-to-cart--product-button--product-image--product-rating--product-title.js 151 B
build/product-add-to-cart-frontend.js 6.43 kB
build/product-add-to-cart.js 8.8 kB
build/product-best-sellers.js 8.26 kB
build/product-button--product-image--product-price--product-rating--product-sale-badge--product-sku--prod--5bce0384.js 464 B
build/product-categories.js 2.37 kB
build/product-category.js 9.25 kB
build/product-image.js 4.29 kB
build/product-new.js 8.26 kB
build/product-on-sale.js 8.59 kB
build/product-rating.js 920 B
build/product-results-count.js 1.66 kB
build/product-search.js 2.63 kB
build/product-sku-frontend.js 1 kB
build/product-summary-frontend.js 1.29 kB
build/product-tag.js 8.75 kB
build/product-top-rated.js 8.49 kB
build/rating-filter-frontend.js 20.8 kB
build/rating-filter-wrapper-frontend.js 5.59 kB
build/reviews-by-category.js 11.9 kB
build/reviews-by-product.js 13 kB
build/reviews-frontend.js 7.1 kB
build/single-product.js 11 kB
build/stock-filter-frontend.js 21.1 kB
build/stock-filter-wrapper-frontend.js 5.83 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.82 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/wc-blocks-data.js 21.8 kB
build/wc-blocks-editor-style-rtl.css 5.87 kB
build/wc-blocks-editor-style.css 5.87 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-style-rtl.css 27.6 kB
build/wc-blocks-style.css 27.6 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 63.8 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 changed the title Product Stock indicator: Adds support for background color, typography, and spacing Product Stock indicator: Added support for background color, margin, padding & various typography controls Apr 4, 2023
@imanish003 imanish003 changed the title Product Stock indicator: Added support for background color, margin, padding & various typography controls Product Stock indicator: Add support for background color, margin, padding & various typography controls Apr 4, 2023
@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. labels Apr 4, 2023
This commit introduces a new function, `getTextBasedOnStock`, which handles the generation of stock text based on the stock information provided. It replaces the previous `lowStockText` and `stockText` functions, making the code more readable and maintainable.

In addition, minor adjustments to the class name handling have been made to simplify the code and ensure consistent styling when used inside the All Products block.

In the `edit.tsx` file, the `useBlockProps` function call has been updated to include the default `wc-block-components-product-stock-indicator` class name, ensuring it is always applied.
@imanish003 imanish003 marked this pull request as ready for review April 6, 2023 09:15
@woocommercebot woocommercebot requested review from a team and gigitux and removed request for a team April 6, 2023 09:16
Copy link
Contributor

@gigitux gigitux left a comment

Choose a reason for hiding this comment

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

Great work!
Since that we removed the __experimentalSelector key, I think that we can remove those lines: https://github.com/woocommerce/woocommerce-blocks/pull/8954/files#diff-fdc398df407d5b8f5953192c6f08df749bebd4b2e771ee9bf1cccdb0b7a9966dR31-R45

@github-actions github-actions bot added this to the 10.1.0 milestone Apr 13, 2023
This commit removes the redundant get_block_type_supports() method from the ProductStockIndicator.php file, as it is no longer needed. The block type supports are now handled in the frontend.
@imanish003
Copy link
Contributor Author

Hi @gigitux, thanks for the suggestion. I've removed the get_block_type_supports as you recommended.
Additionally, in the future, we can use the block.json file to register this block on both the frontend and server side.

Could you please take a quick look before I merge this PR? 🙂

@imanish003 imanish003 requested a review from gigitux April 14, 2023 05:51
Copy link
Contributor

@gigitux gigitux left a comment

Choose a reason for hiding this comment

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

Nice work! 🚢

@imanish003 imanish003 enabled auto-merge (squash) April 17, 2023 12:17
@imanish003 imanish003 merged commit f306a32 into trunk Apr 18, 2023
@imanish003 imanish003 deleted the add/7954-product-stock-indicator-spacing branch April 18, 2023 09:50
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.

2 participants