woocommerce/plugins/woocommerce-blocks/assets/js/blocks
Albert Juhé Lluveras f3ec10a89c Add Drawer component (https://github.com/woocommerce/woocommerce-blocks/pull/4608)
* Add Drawer component

* Use element dataset instead of a window global

* Rename miniCartOverlay to miniCartDrawerPlaceholder

* Refactor styles so screen overlay covers the entire screen

* Use rem instead of em for the drawer title size to keep it consistent between renders

* Keep focus when replacing the mini cart button

* Match overlay colors from designs

* Use is-loading class like several other blocks

* Add more doc comments

* Don't listen to clicks on Mini Cart button when it's open

* Update Drawer component styles
2021-09-02 11:44:25 +02: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 Add Drawer component (https://github.com/woocommerce/woocommerce-blocks/pull/4608) 2021-09-02 11:44:25 +02: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.