woocommerce/plugins/woocommerce-blocks/assets/js/blocks
Seghir Nadir 8ecfcfb9a0
Add Checkbox support for Additional Fields in Checkout Block (#42780)
* Introduce Additional Fields API for Checkout Block https://github.com/woocommerce/woocommerce-blocks/pull/12073

* revert test to what it was

* Default to text, if the type supplied is not supported throw an error

* Add type for options

* Return null if somehow the select made it through without options

* Make select fields type enum and add options to schema

* Lint fixes

* Update plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/address-form/address-form.tsx

Co-authored-by: Niels Lange <info@nielslange.de>

* Update plugins/woocommerce/src/Blocks/Domain/Services/CheckoutFields.php

Co-authored-by: Niels Lange <info@nielslange.de>

* Update checks to log errors and fail gracefully

* Add field id to class names

* Fix lint error

* Fix short array use

* Introduce Additional Fields API for Checkout Block https://github.com/woocommerce/woocommerce-blocks/pull/12073

* Default to text, if the type supplied is not supported throw an error

* Lint fixes

* Introduce Additional Fields API for Checkout Block https://github.com/woocommerce/woocommerce-blocks/pull/12073

* add support for registering checkboxes

* remove extra error log

* add styling

* fix rebase conflit

* fix rebase conflit 2

* fix linter errors

* address review comments

* add warning for checkbox

* fix changes

---------

Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
Co-authored-by: Niels Lange <info@nielslange.de>
2023-12-18 13:21:36 +01:00
..
active-filters Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
attribute-filter Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
breadcrumbs Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
cart Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
cart-checkout-shared Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
catalog-sorting Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
checkout Add Checkbox support for Additional Fields in Checkout Block (#42780) 2023-12-18 13:21:36 +01:00
classic-shortcode Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
classic-template Product gallery/legacy/transform (#42719) 2023-12-14 05:47:48 -08:00
collection-filters Experimental Collection Rating Filter (#41999) 2023-12-18 22:47:24 +13:00
customer-account Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
featured-items Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
filter-wrapper Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
handpicked-products Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
migration-products-to-product-collection Simplify Product Collection query attributes by removing attributes which are never used (https://github.com/woocommerce/woocommerce-blocks/pull/11259) 2023-10-18 12:47:55 +02:00
mini-cart Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
order-confirmation Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
page-content-wrapper update text domain in plugins/woocommerce-blocks (#42717) 2023-12-12 14:12:36 -08:00
price-filter Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
product-best-sellers Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
product-categories Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
product-category Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
product-collection Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
product-gallery Product Gallery: reset main image when variations are cleared (#42830) 2023-12-15 13:22:10 -08:00
product-new Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
product-on-sale Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
product-query Remove padding for the products query when background is added (#42817) 2023-12-18 11:14:43 +01:00
product-results-count Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
product-search Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
product-tag Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
product-template update text domain in plugins/woocommerce-blocks (#42717) 2023-12-12 14:12:36 -08:00
product-top-rated Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
products Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
products-by-attribute Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
rating-filter Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
reviews Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
shared/styles Add logic of Upgrade Notice after upgrading Products to Product Collection (https://github.com/woocommerce/woocommerce-blocks/pull/10267) 2023-08-18 08:25:15 +02:00
single-product Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
stock-filter Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
store-notices update text domain in plugins/woocommerce-blocks (#42717) 2023-12-12 14:12:36 -08: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.