forked from woocommerce/woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reusable blocks documentation for remaining blocks (woocommerce#4…
…0521) * Add documentation for woocommerce/product-radio-field * Update woocommerce/product-taxonomy-field documentation * Rename checkbox section for consistency * Edit pricing attribute name for consistency * Add documentation for woocommerce/product-pricing-field * Add 'conditional' documentation * Update README.md * Add usage text * Add documentation to collapsible * Fix details across all readmes * Add changelog * Try adding video html tag * Allow video html tag * Fix wrong position in doc * Rename 'name' to 'property' on InputControl props * Fix mistake in label position
- Loading branch information
Showing
11 changed files
with
301 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/js/product-editor/changelog/doc-more-reusable-blocks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Significance: patch | ||
Type: dev | ||
Comment: Add reusable blocks documentation | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/js/product-editor/src/blocks/collapsible/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# woocommerce/product-collapsible | ||
|
||
Container with collapsible inner blocks. | ||
|
||
![Collapsible](https://woocommerce.files.wordpress.com/2023/09/woocommerceproduct-collapsible.png) | ||
|
||
## Attributes | ||
|
||
### toggleText | ||
|
||
- **Type**: `string` | ||
- **Required**: ` Yes` | ||
|
||
The text to display on the toggle button. | ||
|
||
### initialCollapsed | ||
|
||
- **Type**: `boolean` | ||
- **Required**: ` Yes` | ||
|
||
Controls if the content is collapsed by default. | ||
|
||
### persistRender | ||
|
||
- **Type**: `boolean` | ||
- **Required**: ` Yes` | ||
|
||
Controls if content is rendered to the DOM even when collapsed. | ||
|
||
## Usage | ||
|
||
Here's the code that was used to create the example in the screenshot above: | ||
|
||
```php | ||
$product_inventory_advanced = $product_inventory_section->add_block( | ||
[ | ||
'id' => 'product-inventory-advanced', | ||
'blockName' => 'woocommerce/product-collapsible', | ||
'attributes' => [ | ||
'toggleText' => __( 'Advanced', 'woocommerce' ), | ||
'initialCollapsed' => true, | ||
'persistRender' => true, | ||
], | ||
] | ||
); | ||
$product_inventory_advanced->add_block( | ||
[ | ||
// add block information here | ||
] | ||
) | ||
``` |
45 changes: 45 additions & 0 deletions
45
packages/js/product-editor/src/blocks/conditional/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# woocommerce/conditional | ||
|
||
Container to only conditionally render inner blocks. | ||
|
||
<video src="https://github.com/woocommerce/woocommerce/assets/13437655/ccf6888d-59bd-4f7c-9487-105e5e0d8166"></video> | ||
|
||
## Attributes | ||
|
||
### mustMatch | ||
|
||
- **Type**: `Record< string, Array< string > >` | ||
- **Required**: `Yes` | ||
|
||
A list of requirements that must be met for the inner blocks to be rendered. The keys should reference properties from the product, and the values are possible values for that property so that the inner blocks are rendered. | ||
|
||
## Usage | ||
|
||
Here's the code that was used to create the example in the video above: | ||
|
||
```php | ||
$wrapper = $product_summary_field->get_parent()->add_block( | ||
[ | ||
'id' => 'example-conditional-wrapper', | ||
'blockName' => 'woocommerce/conditional', | ||
'order' => $product_summary_field->get_order() + 5, | ||
'attributes' => [ | ||
'mustMatch' => [ | ||
'name' => [ 'Car', 'Bike' ] | ||
], | ||
], | ||
] | ||
); | ||
$wrapper->add_block( | ||
[ | ||
'id' => 'example-pricing-field', | ||
'blockName' => 'woocommerce/product-pricing-field', | ||
'order' => $product_summary_field->get_order() + 5, | ||
'attributes' => [ | ||
'label' => __( 'Example price field', 'woocommerce'), | ||
'property' => 'custom_price', | ||
'help' => 'This is a help text', | ||
], | ||
] | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# woocommerce/product-pricing-field | ||
|
||
A product price block with currency display. | ||
|
||
![Product pricing field](https://woocommerce.files.wordpress.com/2023/09/woocommerceproduct-pricing-field.png) | ||
|
||
## Attributes | ||
|
||
### property | ||
|
||
- **Type:** `String` | ||
- **Required:** `Yes` | ||
|
||
Property in which the price value is stored. | ||
|
||
### label | ||
|
||
- **Type:** `String` | ||
- **Required:** `Yes` | ||
|
||
Label that appears on top of the price field. | ||
|
||
### help | ||
|
||
- **Type:** `String` | ||
- **Required:** `No` | ||
|
||
Help text that appears below the price field. | ||
|
||
## Usage | ||
|
||
Here's the code that adds the field from the screenshot after the Summary field: | ||
|
||
```php | ||
<?php | ||
|
||
if ( ! function_exists( 'add_pricing_field' ) ) { | ||
function add_pricing_field( $product_summary_field ) { | ||
$product_summary_field->get_parent()->add_block( | ||
[ | ||
'id' => 'example-pricing-field', | ||
'blockName' => 'woocommerce/product-pricing-field', | ||
'order' => $product_summary_field->get_order() + 5, | ||
'attributes' => [ | ||
'label' => __( 'Example price field', 'woocommerce'), | ||
'property' => 'custom_price', | ||
'help' => 'This is a help text', | ||
], | ||
] | ||
); | ||
} | ||
} | ||
|
||
if ( ! function_exists( 'example_hook_up_block_template_modifications_pricing' ) ) { | ||
function example_hook_up_block_template_modifications_pricing() { | ||
add_action( | ||
'woocommerce_block_template_area_product-form_after_add_block_product-summary', | ||
'add_pricing_field' | ||
); | ||
} | ||
} | ||
|
||
add_action( 'init', 'example_hook_up_block_template_modifications_pricing', 0 ); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# woocommerce/product-radio-field block | ||
|
||
Radio button field for the product editor. | ||
|
||
![Product radio field](https://woocommerce.files.wordpress.com/2023/09/woocommerceproduct-radio-field.png) | ||
|
||
## Attributes | ||
|
||
### title | ||
|
||
- **Type:** `String` | ||
- **Required:** `Yes` | ||
|
||
### description | ||
|
||
- **Type:** `String` | ||
- **Required:** `No` | ||
|
||
|
||
### property | ||
|
||
- **Type:** `String` | ||
- **Required:** `Yes` | ||
|
||
### options | ||
|
||
- **Type:** `Array` | ||
- **Required:** `Yes` | ||
|
||
## Usage | ||
|
||
Here's an example of the usage on the "Charge sales tax on" field in the Pricing section: | ||
|
||
```php | ||
$product_pricing_section->add_block( | ||
[ | ||
'id' => 'product-sale-tax', | ||
'blockName' => 'woocommerce/product-radio-field', | ||
'order' => 30, | ||
'attributes' => [ | ||
'title' => __( 'Charge sales tax on', 'woocommerce' ), | ||
'property' => 'tax_status', | ||
'options' => [ | ||
[ | ||
'label' => __( 'Product and shipping', 'woocommerce' ), | ||
'value' => 'taxable', | ||
], | ||
[ | ||
'label' => __( 'Only shipping', 'woocommerce' ), | ||
'value' => 'shipping', | ||
], | ||
[ | ||
'label' => __( "Don't charge tax", 'woocommerce' ), | ||
'value' => 'none', | ||
], | ||
], | ||
], | ||
] | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters