woocommerce/plugins/woocommerce-blocks/assets/js/blocks
Sam Seay 137a2e8aa6
Checkout: Add placeholder option to country and state select, add error validation (#49616)
* WIP

* Add empty option for state as well

* Add client-side validation to country select inputs

* Add validation messages for state.

* Clean up redundant destructuring.

* Fix up the validation logic, fix bug where empty select was shown in some cases.

* Remove unused import

* Use import aliases instead of large relative paths

* Add changefile(s) from automation for the following project(s): woocommerce-blocks

* Fix a typo

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* use SelectOption type

* Also handle when address changes, because we shouldnt validate state when there is an address change

* adjust validation to handle any address change, not just country. translate field validations and use lowercase

* add a lowercase label for the country select as well

* Fix an issue where scroll to would not scroll to invalid select

---------

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
2024-07-24 17:59:15 +02:00
..
active-filters [Performance]: Replace `classnames` usage with `clsx` (#47760) 2024-05-31 05:49:36 +02:00
attribute-filter [Performance]: Replace `classnames` usage with `clsx` (#47760) 2024-05-31 05:49:36 +02:00
breadcrumbs Remove isFeaturePlugin and flag code from FeatureGating class (#47866) 2024-05-30 02:50:09 +12:00
cart Make proceed to order button non sticky when zoom level is bigger than 100% (#48391) 2024-06-28 10:05:49 +02:00
cart-checkout-shared Replace Products (Beta) with Product Collection in product archive templates (#48112) 2024-06-12 15:45:09 +02:00
catalog-sorting Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
checkout Checkout: Add placeholder option to country and state select, add error validation (#49616) 2024-07-24 17:59:15 +02:00
classic-shortcode Update Woo.com references to WooCommerce.com (#46259) 2024-04-09 09:50:15 +01:00
classic-template Fix Classic Template block registration on WP 6.6 (#48730) 2024-06-26 12:20:22 +02:00
coming-soon Deprecate and create new coming soon block version (#49786) 2024-07-24 15:12:38 +08:00
customer-account Add a new icon style to the Customer Account block (#48979) 2024-07-02 09:34:59 +02:00
featured-items [Performance]: Replace `classnames` usage with `clsx` (#47760) 2024-05-31 05:49:36 +02:00
filter-wrapper [Experimental] Filter block: replace custom upgrade panel by Transforms API (#44024) 2024-01-25 15:28:09 +07: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 Fix the mini cart items not being visible when zoomed in (#48384) 2024-07-09 16:47:21 +01:00
order-confirmation [Performance]: Replace `classnames` usage with `clsx` (#47760) 2024-05-31 05:49:36 +02:00
page-content-wrapper update text domain in plugins/woocommerce-blocks (#42717) 2023-12-12 14:12:36 -08:00
price-filter [Performance]: Replace `classnames` usage with `clsx` (#47760) 2024-05-31 05:49:36 +02: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 Product Collection: Revert rename of "Sync with current query" option (#49907) 2024-07-24 14:17:37 +02:00
product-filter [Experimental] Product Filters Redesign: Move icons to @woocommerce/icons package (#49646) 2024-07-18 15:53:39 -03:00
product-filters [Experimental] Add Product filters overlay settings (#48732) 2024-07-18 11:33:25 -07:00
product-filters-overlay [Experimental] Product Filters Overlay Navigation block (#48677) 2024-06-28 08:16:21 +00:00
product-filters-overlay-navigation [Experimental] Product Filters Overlay Navigation block (#48677) 2024-06-28 08:16:21 +00:00
product-gallery [Performance]: Replace `classnames` usage with `clsx` (#47760) 2024-05-31 05:49:36 +02: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 Hide Products (Beta) from inserter (#48204) 2024-06-12 15:45:27 +02:00
product-results-count Added Result Count Client Navigation (#45556) 2024-03-14 09:48:02 -07:00
product-search [Performance]: Replace `classnames` usage with `clsx` (#47760) 2024-05-31 05:49:36 +02:00
product-tag Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
product-template Product Collection: Fix alignment of the first item in Grid layout for WP 6.6 (#49096) 2024-07-05 17:24:27 +05:30
product-top-rated Fixed Blocks Linting Errors (#42727) 2023-12-12 15:05:20 -08:00
products [Performance]: Replace `classnames` usage with `clsx` (#47760) 2024-05-31 05:49:36 +02:00
products-by-attribute Fix sidebar attribute control in Products by Attribute block (#49351) 2024-07-11 15:52:57 +02:00
rating-filter [Performance]: Replace `classnames` usage with `clsx` (#47760) 2024-05-31 05:49:36 +02:00
reviews [Performance]: Replace `classnames` usage with `clsx` (#47760) 2024-05-31 05:49:36 +02: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 Increase product excerpt default length in Single Product template and block (#47651) 2024-05-31 08:19:06 +02:00
stock-filter [Performance]: Replace `classnames` usage with `clsx` (#47760) 2024-05-31 05:49:36 +02: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.