woocommerce/plugins/woocommerce-blocks/assets/js/blocks
Mike Jolley cf8ab9fa93 Add key to each `CartTotalItem` (https://github.com/woocommerce/woocommerce-blocks/pull/4240)
* Move type defs

* Move type guards

* Fix imports

* Extract prepareTotalItems to TS file

* usePaymentMethodInterface as TS file

* Fix TS props

* Fix currency type defs

* Add return type to usePaymentMethodInterface

* Add key prop to CartTotalItem

* Fixed up js tests

* Move SymbolPosition into type-defs package

Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
2021-05-25 12:49:13 +01:00
..
active-filters Move Button and Label components to `@woocommerce/blocks-checkout` package (https://github.com/woocommerce/woocommerce-blocks/pull/4222) 2021-05-18 09:10:31 +01:00
attribute-filter Update @woocommerce/components (https://github.com/woocommerce/woocommerce-blocks/pull/4100) 2021-05-20 10:58:59 +02:00
cart-checkout Add key to each `CartTotalItem` (https://github.com/woocommerce/woocommerce-blocks/pull/4240) 2021-05-25 12:49:13 +01:00
featured-category Move Block Type Settings into Block Type Classes (https://github.com/woocommerce/woocommerce-blocks/pull/4059) 2021-04-22 12:37:27 +01:00
featured-product Move Block Type Settings into Block Type Classes (https://github.com/woocommerce/woocommerce-blocks/pull/4059) 2021-04-22 12:37:27 +01: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 Fix block elements that don't play well with dark backgrounds (https://github.com/woocommerce/woocommerce-blocks/pull/3887) 2021-03-16 10:43:04 +01: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 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-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 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-by-attribute Update @woocommerce/components (https://github.com/woocommerce/woocommerce-blocks/pull/4100) 2021-05-20 10:58:59 +02:00
reviews Update @woocommerce/components (https://github.com/woocommerce/woocommerce-blocks/pull/4100) 2021-05-20 10:58:59 +02:00
single-product Fix Circular Dependencies During Builds (https://github.com/woocommerce/woocommerce-blocks/pull/4025) 2021-04-08 13:31:12 +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.