woocommerce/plugins/woocommerce-blocks/assets/js/blocks
Tung Du 862477f9aa Remove compatibility notice from Mini Cart block (https://github.com/woocommerce/woocommerce-blocks/pull/6803) 2022-08-01 18:01:57 +02:00
..
active-filters Fix: Add support to apply filters via URL for All Products block (https://github.com/woocommerce/woocommerce-blocks/pull/6642) 2022-07-11 14:04:19 +07:00
attribute-filter Fix: Replace DropdownSelector with FormTokenField from Gutenberg (https://github.com/woocommerce/woocommerce-blocks/pull/6647) 2022-08-01 19:00:59 +07:00
cart Fix missing translations in inspector (https://github.com/woocommerce/woocommerce-blocks/pull/6737) 2022-08-01 15:57:33 +01:00
cart-checkout-shared Upgrade wp-prettier to 2.6.2 and reformat the codebase (https://github.com/woocommerce/woocommerce-blocks/pull/6566) 2022-06-15 11:56:52 +02:00
checkout Fix missing translations in inspector (https://github.com/woocommerce/woocommerce-blocks/pull/6737) 2022-08-01 15:57:33 +01:00
classic-template Show classic template in the inserter only for specific templates (https://github.com/woocommerce/woocommerce-blocks/pull/6539) 2022-06-29 09:42:02 +02:00
featured-items Select the correct inner button for the "Featured Item" button to update its url (https://github.com/woocommerce/woocommerce-blocks/pull/6741) 2022-07-26 14:30:18 +02:00
handpicked-products Upgrade wp-prettier to 2.6.2 and reformat the codebase (https://github.com/woocommerce/woocommerce-blocks/pull/6566) 2022-06-15 11:56:52 +02:00
mini-cart Remove compatibility notice from Mini Cart block (https://github.com/woocommerce/woocommerce-blocks/pull/6803) 2022-08-01 18:01:57 +02:00
price-filter Fix: Add support to apply filters via URL for All Products block (https://github.com/woocommerce/woocommerce-blocks/pull/6642) 2022-07-11 14:04:19 +07:00
product-best-sellers Start using `block.json` and convert to TS the `Product Best Sellers` block (https://github.com/woocommerce/woocommerce-blocks/pull/6683) 2022-07-20 11:29:49 +02:00
product-categories Upgrade wp-prettier to 2.6.2 and reformat the codebase (https://github.com/woocommerce/woocommerce-blocks/pull/6566) 2022-06-15 11:56:52 +02:00
product-category Start using `block.json` and convert to TS the `Product by Category` block (https://github.com/woocommerce/woocommerce-blocks/pull/6680) 2022-07-19 15:09:46 +02:00
product-new Remove custom `Icon` component in favour of `@wordpress/icons` where possible (https://github.com/woocommerce/woocommerce-blocks/pull/5599) 2022-02-01 16:54:38 +00:00
product-on-sale Remove custom `Icon` component in favour of `@wordpress/icons` where possible (https://github.com/woocommerce/woocommerce-blocks/pull/5599) 2022-02-01 16:54:38 +00:00
product-search Update @woocmmerce/eslint-plugin to 2.0.0 (https://github.com/woocommerce/woocommerce-blocks/pull/6203) 2022-04-08 14:47:19 +01:00
product-tag Upgrade wp-prettier to 2.6.2 and reformat the codebase (https://github.com/woocommerce/woocommerce-blocks/pull/6566) 2022-06-15 11:56:52 +02:00
product-top-rated Remove custom `Icon` component in favour of `@wordpress/icons` where possible (https://github.com/woocommerce/woocommerce-blocks/pull/5599) 2022-02-01 16:54:38 +00:00
products All Products block: Migrate to block.json (https://github.com/woocommerce/woocommerce-blocks/pull/6754) 2022-07-28 12:26:36 +02:00
products-by-attribute Upgrade wp-prettier to 2.6.2 and reformat the codebase (https://github.com/woocommerce/woocommerce-blocks/pull/6566) 2022-06-15 11:56:52 +02:00
reviews Remove the ToggleButtonControl in favor of ToggleGroupControl (https://github.com/woocommerce/woocommerce-blocks/pull/5967) 2022-04-11 13:33:46 +02:00
single-product Update @woocmmerce/eslint-plugin to 2.0.0 (https://github.com/woocommerce/woocommerce-blocks/pull/6203) 2022-04-08 14:47:19 +01:00
stock-filter Fix: Add support to apply filters via URL for All Products block (https://github.com/woocommerce/woocommerce-blocks/pull/6642) 2022-07-11 14:04:19 +07:00
README.md Format Markdown files using wp-scripts (https://github.com/woocommerce/woocommerce-blocks/pull/6462) 2022-06-09 14:43:17 +02: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.