woocommerce/plugins/woocommerce-blocks/assets/js/blocks
Mike Jolley b385d4005c Refactor Checkout Inner Block Registration and Render frontend forced blocks (https://github.com/woocommerce/woocommerce-blocks/pull/4671)
* Append forced blocks

* Fix child detection

* Improve render logic to remove clone element

* Areas instead of block names

* Revert "Areas instead of block names"

This reverts commit c8d68e6424313ed15ca1eb1f91a3edfc24d06a8d.

* revert area change

* Registration system

* Refactor block registration to handle components + forcing

* Remove need for atomic block registration

* add attributes to namespaced blocks only

* Update area names to new format

* Avoid passing custom props to DOM

* Put back usage of cloneelement for DOM elements

* correct case of innerBlockAreas

* Inline documentation for renderParentBlock

* Play nice with other attributes when registering forced blocks
2021-09-03 14:25:09 +01:00
..
active-filters Replace deprecated divisions with math.div($size, $base) (https://github.com/woocommerce/woocommerce-blocks/pull/4550) 2021-08-24 13:37:43 +02:00
attribute-filter Add "Filter Products by Stock" block (https://github.com/woocommerce/woocommerce-blocks/pull/4145) 2021-08-20 16:56:14 +01:00
cart-checkout Refactor Checkout Inner Block Registration and Render frontend forced blocks (https://github.com/woocommerce/woocommerce-blocks/pull/4671) 2021-09-03 14:25:09 +01:00
featured-category Replace deprecated divisions with math.div($size, $base) (https://github.com/woocommerce/woocommerce-blocks/pull/4550) 2021-08-24 13:37:43 +02:00
featured-product Replace deprecated divisions with math.div($size, $base) (https://github.com/woocommerce/woocommerce-blocks/pull/4550) 2021-08-24 13:37:43 +02:00
handpicked-products Update @woocommerce/components (https://github.com/woocommerce/woocommerce-blocks/pull/4100) 2021-05-20 10:58:59 +02:00
price-filter Move Block Type Settings into Block Type Classes (https://github.com/woocommerce/woocommerce-blocks/pull/4059) 2021-04-22 12:37:27 +01:00
product-best-sellers Move Block Type Settings into Block Type Classes (https://github.com/woocommerce/woocommerce-blocks/pull/4059) 2021-04-22 12:37:27 +01:00
product-categories Make Product Categories List links unclickable in the editor (https://github.com/woocommerce/woocommerce-blocks/pull/4339) 2021-06-15 07:33:16 +02:00
product-category Update @woocommerce/components (https://github.com/woocommerce/woocommerce-blocks/pull/4100) 2021-05-20 10:58:59 +02:00
product-new Move Block Type Settings into Block Type Classes (https://github.com/woocommerce/woocommerce-blocks/pull/4059) 2021-04-22 12:37:27 +01:00
product-on-sale Move Block Type Settings into Block Type Classes (https://github.com/woocommerce/woocommerce-blocks/pull/4059) 2021-04-22 12:37:27 +01:00
product-search Fix unfiltered html usage of blocks (https://github.com/woocommerce/woocommerce-blocks/pull/4551) 2021-08-12 17:39:38 +01:00
product-tag Update @woocommerce/components (https://github.com/woocommerce/woocommerce-blocks/pull/4100) 2021-05-20 10:58:59 +02:00
product-top-rated Move Block Type Settings into Block Type Classes (https://github.com/woocommerce/woocommerce-blocks/pull/4059) 2021-04-22 12:37:27 +01:00
products Add "Filter Products by Stock" block (https://github.com/woocommerce/woocommerce-blocks/pull/4145) 2021-08-20 16:56:14 +01:00
products-by-attribute Add camelcase rule to eslint config (https://github.com/woocommerce/woocommerce-blocks/pull/4382) 2021-07-09 17:53:45 +01:00
reviews Make SortSelect components controlled (https://github.com/woocommerce/woocommerce-blocks/pull/4580) 2021-08-18 09:33:13 +02:00
single-product Refactor Render Parent Block (https://github.com/woocommerce/woocommerce-blocks/pull/4325) 2021-06-11 09:54:18 +01:00
stock-filter Add "Filter Products by Stock" block (https://github.com/woocommerce/woocommerce-blocks/pull/4145) 2021-08-20 16:56:14 +01:00
README.md Remove deprecated shortcode save handling from SSR Blocks (https://github.com/woocommerce/woocommerce-blocks/pull/4010) 2021-04-08 13:42:03 +01: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.