woocommerce/plugins/woocommerce-blocks/assets/js/blocks
Mike Jolley 4fd16267be Refactor Push Changes Readability and Performance (https://github.com/woocommerce/woocommerce-blocks/pull/10315)
* Add local state to address-form

* Update test with valid postcode and required fields

* Push changes refactoring

* Avoid loops due to retrying same data

* Callbacks to prevent rerenders

* Move validation functions

* Filter incoming values to only those included as fields to prevent errors

* Keep track of country changes to prevent excessive updates of addressFormFields.

* Use helpers in test

* Fill company

* Revert local state in address form

* Update address form to remove validation handling for postcode (country clears the field).

* Revert "Update test with valid postcode and required fields"

This reverts commit 718a6006df24f6e957297ad4d1ef9d6f690793bd.

* Clear postcode when country changes if invalid

* Revalidate fields when country changes

* Comment for pick

* Revert unneccessary test change

* Revery moving of functions to reduce diff size

* Increase push timeout in tests

* Revert test changes
2023-08-09 18:24:51 +01:00
..
active-filters Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439) 2023-08-07 11:30:53 +01:00
attribute-filter Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439) 2023-08-07 11:30:53 +01:00
breadcrumbs Per block stylesheets (https://github.com/woocommerce/woocommerce-blocks/pull/9831) 2023-07-04 13:06:48 +02:00
cart Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439) 2023-08-07 11:30:53 +01:00
cart-checkout-shared remove proptypes from payment-method-card and payment-method-error-bo… (https://github.com/woocommerce/woocommerce-blocks/pull/9817) 2023-08-03 12:06:52 +01:00
catalog-sorting Per block stylesheets (https://github.com/woocommerce/woocommerce-blocks/pull/9831) 2023-07-04 13:06:48 +02:00
checkout Refactor Push Changes Readability and Performance (https://github.com/woocommerce/woocommerce-blocks/pull/10315) 2023-08-09 18:24:51 +01:00
classic-template classicBlock: add defensive type handling (https://github.com/woocommerce/woocommerce-blocks/pull/10475) 2023-08-04 16:16:19 +02:00
customer-account Per block stylesheets (https://github.com/woocommerce/woocommerce-blocks/pull/9831) 2023-07-04 13:06:48 +02:00
featured-items Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439) 2023-08-07 11:30:53 +01:00
filter-wrapper Refactor Filter Wrapper to remove usage of useInnerBlocksProps (https://github.com/woocommerce/woocommerce-blocks/pull/8095) 2023-01-04 17:31:17 +07:00
handpicked-products Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439) 2023-08-07 11:30:53 +01:00
mini-cart Add Color Panel (https://github.com/woocommerce/woocommerce-blocks/pull/10062) 2023-07-21 10:35:32 +01:00
price-filter Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439) 2023-08-07 11:30:53 +01:00
product-best-sellers Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439) 2023-08-07 11:30:53 +01:00
product-categories Enable declaration-block-no-duplicate-properties stylelint rule (https://github.com/woocommerce/woocommerce-blocks/pull/10163) 2023-07-11 13:03:05 +00:00
product-category Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439) 2023-08-07 11:30:53 +01:00
product-collection Add manual path to upgrade Products block (https://github.com/woocommerce/woocommerce-blocks/pull/10268) 2023-07-21 08:22:49 +02:00
product-gallery Product Gallery: Add Crop, Zoom and Full-screen settings (https://github.com/woocommerce/woocommerce-blocks/pull/10445) 2023-08-02 10:43:08 +00:00
product-new Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439) 2023-08-07 11:30:53 +01:00
product-on-sale Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439) 2023-08-07 11:30:53 +01:00
product-query Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439) 2023-08-07 11:30:53 +01:00
product-results-count Per block stylesheets (https://github.com/woocommerce/woocommerce-blocks/pull/9831) 2023-07-04 13:06:48 +02:00
product-search Remove `propTypes` definitions from Product Search block (https://github.com/woocommerce/woocommerce-blocks/pull/9565) 2023-05-24 19:24:08 +07:00
product-tag Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439) 2023-08-07 11:30:53 +01:00
product-template Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439) 2023-08-07 11:30:53 +01:00
product-top-rated Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439) 2023-08-07 11:30:53 +01:00
products Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439) 2023-08-07 11:30:53 +01:00
products-by-attribute Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439) 2023-08-07 11:30:53 +01:00
rating-filter Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439) 2023-08-07 11:30:53 +01:00
reviews Fix PropType warning and error when adding All Reviews block to Editor (https://github.com/woocommerce/woocommerce-blocks/pull/9869) 2023-06-19 15:39:54 +05:30
shared Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439) 2023-08-07 11:30:53 +01:00
single-product Single Product block: Add wide and full-width alignments support (https://github.com/woocommerce/woocommerce-blocks/pull/8981) 2023-04-27 16:44:10 -03:00
stock-filter Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439) 2023-08-07 11:30:53 +01:00
store-notices Update the archive templates to use Products block (https://github.com/woocommerce/woocommerce-blocks/pull/8308)Co-authored-by: Alba Rincón <alba.rincon@automattic.com> 2023-02-22 08:24:04 +07:00
README.md Remove propTypes definitions from Newest Products block (https://github.com/woocommerce/woocommerce-blocks/pull/9613) 2023-05-29 13:12:36 +07:00

README.md

Blocks

Our blocks are generally made up of up to 4 files:

|- block.js
|- editor.scss
|- index.js
|- style.scss

The only required file is index.js, this sets up the block using registerBlockType. Each block has edit and save functions.

The scss files are split so that things in style are added to the editor and frontend, while styles in editor are only added to the editor. Most of our blocks should use core components that won't need CSS though.

Editing

A simple edit function can live in index.js, but most blocks are a little more complicated, so the edit function instead returns a Block component, which lives in block.js. By using a component, we can use React lifecycle methods to fetch data or save state.

The Newest Products block is a good example to read over, this is a simple block that fetches the products and renders them using the ProductPreview component.

We include settings in the sidebar, called the Inspector in gutenberg. See an example of this.

Other blocks have the concept of an "edit state", like when you need to pick a product in the Featured Product block, or pick a category in the Products by Category block.