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.
[ Product Block Editor ] Create Variation options block (woocommerce#…
…39256) * Add support for variable products * Add 'hello world' block to variations tab * Add product-section block to template * Add AttributeControl component to screen * Add changelog * Change labels * Make a copy of AttributeControl to VariationOptionsControl to allow the fields to evolve separately in future * Fix tests * Add changelog to woocommerce * Fix alert error * Remove copied control and start adapting attribute control to handle both scenarios * Add -field to block name * Revert "Add -field to block name" This reverts commit 50e1ee6. * Revert "Revert "Add -field to block name"" This reverts commit eee0441. * Extract more labels * Hide drag handle in variation options
- Loading branch information
Showing
15 changed files
with
190 additions
and
14 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/js/product-editor/changelog/add-variation-options-block
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,4 @@ | ||
Significance: minor | ||
Type: add | ||
|
||
Add variation options block |
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
26 changes: 26 additions & 0 deletions
26
packages/js/product-editor/src/blocks/variation-options/block.json
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,26 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "woocommerce/product-variations-options-field", | ||
"title": "Product variations options", | ||
"category": "woocommerce", | ||
"description": "The product variations options.", | ||
"keywords": [ "products", "variations" ], | ||
"textdomain": "default", | ||
"attributes": { | ||
"description": { | ||
"type": "string", | ||
"__experimentalRole": "content" | ||
} | ||
}, | ||
"supports": { | ||
"align": false, | ||
"html": false, | ||
"multiple": false, | ||
"reusable": false, | ||
"inserter": false, | ||
"lock": false, | ||
"__experimentalToolbar": false | ||
}, | ||
"editorStyle": "file:./editor.css" | ||
} |
58 changes: 58 additions & 0 deletions
58
packages/js/product-editor/src/blocks/variation-options/edit.tsx
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,58 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
import { createElement } from '@wordpress/element'; | ||
import { ProductAttribute } from '@woocommerce/data'; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore No types for this exist yet. | ||
// eslint-disable-next-line @woocommerce/dependency-group | ||
import { useEntityProp, useEntityId } from '@wordpress/core-data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useProductAttributes } from '../../hooks/use-product-attributes'; | ||
import { AttributeControl } from '../../components/attribute-control'; | ||
|
||
export function Edit() { | ||
const blockProps = useBlockProps(); | ||
|
||
const [ entityAttributes, setEntityAttributes ] = useEntityProp< | ||
ProductAttribute[] | ||
>( 'postType', 'product', 'attributes' ); | ||
|
||
const { attributes, handleChange } = useProductAttributes( { | ||
allAttributes: entityAttributes, | ||
onChange: setEntityAttributes, | ||
isVariationAttributes: true, | ||
productId: useEntityId( 'postType', 'product' ), | ||
} ); | ||
|
||
return ( | ||
<div { ...blockProps }> | ||
<AttributeControl | ||
value={ attributes } | ||
onChange={ handleChange } | ||
uiStrings={ { | ||
globalAttributeHelperMessage: '', | ||
customAttributeHelperMessage: '', | ||
newAttributeModalNotice: '', | ||
newAttributeModalTitle: __( | ||
'Add variation options', | ||
'woocommerce' | ||
), | ||
attributeRemoveLabel: __( | ||
'Remove variation option', | ||
'woocommerce' | ||
), | ||
attributeRemoveConfirmationMessage: __( | ||
'Remove this variation option?', | ||
'woocommerce' | ||
), | ||
} } | ||
/> | ||
</div> | ||
); | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/js/product-editor/src/blocks/variation-options/editor.scss
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,17 @@ | ||
.wp-block-woocommerce-product-variations-options-field { | ||
.woocommerce-sortable { | ||
padding: 0; | ||
} | ||
|
||
.woocommerce-list-item { | ||
background: none; | ||
border: none; | ||
border-bottom: 1px solid $gray-200; | ||
padding-left: 0; | ||
grid-template-columns: 26% auto 90px; | ||
} | ||
|
||
.woocommerce-sortable__handle { | ||
display: none; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/js/product-editor/src/blocks/variation-options/index.ts
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,29 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { createElement } from '@wordpress/element'; | ||
import { BlockConfiguration } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { initBlock } from '../../utils/init-blocks'; | ||
import blockConfiguration from './block.json'; | ||
import { Edit } from './edit'; | ||
import { VariationOptionsBlockAttributes } from './types'; | ||
|
||
const { name, ...metadata } = | ||
blockConfiguration as BlockConfiguration< VariationOptionsBlockAttributes >; | ||
|
||
export { metadata, name }; | ||
|
||
export const settings: Partial< | ||
BlockConfiguration< VariationOptionsBlockAttributes > | ||
> = { | ||
example: {}, | ||
edit: Edit, | ||
}; | ||
|
||
export function init() { | ||
return initBlock( { name, metadata, settings } ); | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/js/product-editor/src/blocks/variation-options/types.ts
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,8 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { BlockAttributes } from '@wordpress/blocks'; | ||
|
||
export interface VariationOptionsBlockAttributes extends BlockAttributes { | ||
description: string; | ||
} |
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
1 change: 1 addition & 0 deletions
1
packages/js/product-editor/src/components/attribute-control/new-attribute-modal.scss
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
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,4 @@ | ||
Significance: minor | ||
Type: update | ||
|
||
Add 'variable' to supported post types for product block editor |
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