Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding attributes block to product block editor. (#38051)
- Loading branch information
1 parent
94599a1
commit 3679f01
Showing
52 changed files
with
308 additions
and
226 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/js/product-editor/assets/icons/section_attributes.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions
4
packages/js/product-editor/changelog/add-block-attributes-37728
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 | ||
|
||
Adding attributes components, block and styles. |
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/attributes/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-attributes-field", | ||
"title": "Product attributes", | ||
"category": "widgets", | ||
"description": "The product attributes.", | ||
"keywords": [ "products", "attributes" ], | ||
"textdomain": "default", | ||
"attributes": { | ||
"name": { | ||
"type": "string", | ||
"__experimentalRole": "content" | ||
} | ||
}, | ||
"supports": { | ||
"align": false, | ||
"html": false, | ||
"multiple": false, | ||
"reusable": false, | ||
"inserter": false, | ||
"lock": false, | ||
"__experimentalToolbar": false | ||
}, | ||
"editorStyle": "file:./editor.css" | ||
} |
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,35 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { createElement } from '@wordpress/element'; | ||
import { ProductAttribute } from '@woocommerce/data'; | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
// 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 { Attributes as AttributesContainer } from '../../components/attributes/attributes'; | ||
|
||
export function Edit() { | ||
const [ entityAttributes, setEntityAttributes ] = useEntityProp< | ||
ProductAttribute[] | ||
>( 'postType', 'product', 'attributes' ); | ||
|
||
const productId = useEntityId( 'postType', 'product' ); | ||
|
||
const blockProps = useBlockProps(); | ||
|
||
return ( | ||
<div { ...blockProps }> | ||
<AttributesContainer | ||
productId={ productId } | ||
value={ entityAttributes } | ||
onChange={ setEntityAttributes } | ||
/> | ||
</div> | ||
); | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/js/product-editor/src/blocks/attributes/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,21 @@ | ||
.wp-block-woocommerce-product-images-field { | ||
.woocommerce-image-gallery { | ||
margin-top: $gap-largest; | ||
} | ||
.woocommerce-media-uploader { | ||
text-align: left; | ||
} | ||
.woocommerce-media-uploader__label { | ||
display: none; | ||
} | ||
.woocommerce-sortable { | ||
margin-top: 0; | ||
padding: 0; | ||
} | ||
|
||
&:not(.has-images) { | ||
.woocommerce-sortable { | ||
display: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { initBlock } from '../../utils'; | ||
import metadata from './block.json'; | ||
import { Edit } from './edit'; | ||
|
||
const { name } = metadata; | ||
|
||
export { metadata, name }; | ||
|
||
export const settings = { | ||
example: {}, | ||
edit: Edit, | ||
}; | ||
|
||
export const init = () => | ||
initBlock( { | ||
name, | ||
metadata: metadata as never, | ||
settings, | ||
} ); |
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.