-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added blocks for all price labels. Support variation script.
- Loading branch information
1 parent
a185b7d
commit 6660704
Showing
48 changed files
with
1,316 additions
and
48 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
19 changes: 19 additions & 0 deletions
19
assets/js/blocks/product-elements/defect-description/block.js
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,19 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { withProductDataContext } from '@woocommerce/shared-hocs'; | ||
import PriceLabelBlock from '../shared/price-label-block'; | ||
export default ( props ) => { | ||
props = { ...props, 'labelType': 'defect-description' }; | ||
|
||
// It is necessary because this block has to support serveral contexts: | ||
// - Inside `All Products Block` -> `withProductDataContext` HOC | ||
// - Inside `Products Block` -> Gutenberg Context | ||
// - Inside `Single Product Template` -> Gutenberg Context | ||
// - Without any parent -> `WithSelector` and `withProductDataContext` HOCs | ||
// For more details, check https://github.com/woocommerce/woocommerce-blocks/pull/8609 | ||
if ( props.isDescendentOfSingleProductTemplate ) { | ||
return <PriceLabelBlock { ...props } />; | ||
} | ||
return withProductDataContext( PriceLabelBlock )( props ); | ||
}; |
65 changes: 65 additions & 0 deletions
65
assets/js/blocks/product-elements/defect-description/edit.js
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,65 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { | ||
AlignmentToolbar, | ||
BlockControls, | ||
useBlockProps, | ||
} from '@wordpress/block-editor'; | ||
import { useEffect } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Block from './block'; | ||
import { useIsDescendentOfSingleProductTemplate } from '../shared/use-is-descendent-of-single-product-template'; | ||
const Edit = ( { | ||
attributes, | ||
setAttributes, | ||
context, | ||
} ) => { | ||
const blockProps = useBlockProps(); | ||
const blockAttrs = { | ||
...attributes, | ||
...context, | ||
}; | ||
const isDescendentOfQueryLoop = Number.isFinite( context.queryId ); | ||
|
||
let { isDescendentOfSingleProductTemplate } = | ||
useIsDescendentOfSingleProductTemplate( { isDescendentOfQueryLoop } ); | ||
|
||
if ( isDescendentOfQueryLoop ) { | ||
isDescendentOfSingleProductTemplate = false; | ||
} | ||
|
||
useEffect( | ||
() => | ||
setAttributes( { | ||
isDescendentOfQueryLoop, | ||
isDescendentOfSingleProductTemplate, | ||
} ), | ||
[ | ||
isDescendentOfQueryLoop, | ||
isDescendentOfSingleProductTemplate, | ||
setAttributes, | ||
] | ||
); | ||
|
||
return ( | ||
<> | ||
<BlockControls> | ||
<AlignmentToolbar | ||
value={ attributes.textAlign } | ||
onChange={ ( textAlign ) => { | ||
setAttributes( { textAlign } ); | ||
} } | ||
/> | ||
</BlockControls> | ||
<div { ...blockProps }> | ||
<Block { ...blockAttrs } /> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default Edit; |
5 changes: 5 additions & 0 deletions
5
assets/js/blocks/product-elements/defect-description/frontend.js
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 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import Block from './block'; | ||
export default Block; |
37 changes: 37 additions & 0 deletions
37
assets/js/blocks/product-elements/defect-description/index.js
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,37 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
import { page, Icon } from '@wordpress/icons'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import sharedConfig from '../shared/config'; | ||
import edit from './edit'; | ||
|
||
const { ancestor, ...configuration } = sharedConfig; | ||
|
||
const blockConfig = { | ||
...configuration, | ||
apiVersion: 2, | ||
title: __( 'Defect Description', 'woocommerce-germanized' ), | ||
description: __( 'Inserts the product\'s defect description.', 'woocommerce-germanized' ), | ||
usesContext: [ 'query', 'queryId', 'postId' ], | ||
icon: { src: <Icon | ||
icon={ page } | ||
className="wc-block-editor-components-block-icon" | ||
/> }, | ||
|
||
supports: { | ||
...sharedConfig.supports, | ||
...( { | ||
__experimentalSelector: | ||
'.wp-block-woocommerce-gzd-product-defect-description .wc-gzd-block-components-product-defect-description', | ||
} ) | ||
}, | ||
edit, | ||
}; | ||
|
||
registerBlockType( 'woocommerce-germanized/product-defect-description', blockConfig ); |
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
19 changes: 19 additions & 0 deletions
19
assets/js/blocks/product-elements/deposit-packaging-type/block.js
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,19 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { withProductDataContext } from '@woocommerce/shared-hocs'; | ||
import PriceLabelBlock from '../shared/price-label-block'; | ||
export default ( props ) => { | ||
props = { ...props, 'labelType': 'deposit-packaging-type' }; | ||
|
||
// It is necessary because this block has to support serveral contexts: | ||
// - Inside `All Products Block` -> `withProductDataContext` HOC | ||
// - Inside `Products Block` -> Gutenberg Context | ||
// - Inside `Single Product Template` -> Gutenberg Context | ||
// - Without any parent -> `WithSelector` and `withProductDataContext` HOCs | ||
// For more details, check https://github.com/woocommerce/woocommerce-blocks/pull/8609 | ||
if ( props.isDescendentOfSingleProductTemplate ) { | ||
return <PriceLabelBlock { ...props } />; | ||
} | ||
return withProductDataContext( PriceLabelBlock )( props ); | ||
}; |
65 changes: 65 additions & 0 deletions
65
assets/js/blocks/product-elements/deposit-packaging-type/edit.js
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,65 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { | ||
AlignmentToolbar, | ||
BlockControls, | ||
useBlockProps, | ||
} from '@wordpress/block-editor'; | ||
import { useEffect } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Block from './block'; | ||
import { useIsDescendentOfSingleProductTemplate } from '../shared/use-is-descendent-of-single-product-template'; | ||
const Edit = ( { | ||
attributes, | ||
setAttributes, | ||
context, | ||
} ) => { | ||
const blockProps = useBlockProps(); | ||
const blockAttrs = { | ||
...attributes, | ||
...context, | ||
}; | ||
const isDescendentOfQueryLoop = Number.isFinite( context.queryId ); | ||
|
||
let { isDescendentOfSingleProductTemplate } = | ||
useIsDescendentOfSingleProductTemplate( { isDescendentOfQueryLoop } ); | ||
|
||
if ( isDescendentOfQueryLoop ) { | ||
isDescendentOfSingleProductTemplate = false; | ||
} | ||
|
||
useEffect( | ||
() => | ||
setAttributes( { | ||
isDescendentOfQueryLoop, | ||
isDescendentOfSingleProductTemplate, | ||
} ), | ||
[ | ||
isDescendentOfQueryLoop, | ||
isDescendentOfSingleProductTemplate, | ||
setAttributes, | ||
] | ||
); | ||
|
||
return ( | ||
<> | ||
<BlockControls> | ||
<AlignmentToolbar | ||
value={ attributes.textAlign } | ||
onChange={ ( textAlign ) => { | ||
setAttributes( { textAlign } ); | ||
} } | ||
/> | ||
</BlockControls> | ||
<div { ...blockProps }> | ||
<Block { ...blockAttrs } /> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default Edit; |
5 changes: 5 additions & 0 deletions
5
assets/js/blocks/product-elements/deposit-packaging-type/frontend.js
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 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import Block from './block'; | ||
export default Block; |
37 changes: 37 additions & 0 deletions
37
assets/js/blocks/product-elements/deposit-packaging-type/index.js
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,37 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
import { info, Icon } from '@wordpress/icons'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import sharedConfig from '../shared/config'; | ||
import edit from './edit'; | ||
|
||
const { ancestor, ...configuration } = sharedConfig; | ||
|
||
const blockConfig = { | ||
...configuration, | ||
apiVersion: 2, | ||
title: __( 'Deposit packaging type', 'woocommerce-germanized' ), | ||
description: __( 'Inserts the product\'s deposit packaging type.', 'woocommerce-germanized' ), | ||
usesContext: [ 'query', 'queryId', 'postId' ], | ||
icon: { src: <Icon | ||
icon={ info } | ||
className="wc-block-editor-components-block-icon" | ||
/> }, | ||
|
||
supports: { | ||
...sharedConfig.supports, | ||
...( { | ||
__experimentalSelector: | ||
'.wp-block-woocommerce-gzd-product-deposit-packaging-type .wc-gzd-block-components-product-deposit-packaging-type', | ||
} ) | ||
}, | ||
edit, | ||
}; | ||
|
||
registerBlockType( 'woocommerce-germanized/product-deposit-packaging-type', blockConfig ); |
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,19 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { withProductDataContext } from '@woocommerce/shared-hocs'; | ||
import PriceLabelBlock from '../shared/price-label-block'; | ||
export default ( props ) => { | ||
props = { ...props, 'labelType': 'deposit' }; | ||
|
||
// It is necessary because this block has to support serveral contexts: | ||
// - Inside `All Products Block` -> `withProductDataContext` HOC | ||
// - Inside `Products Block` -> Gutenberg Context | ||
// - Inside `Single Product Template` -> Gutenberg Context | ||
// - Without any parent -> `WithSelector` and `withProductDataContext` HOCs | ||
// For more details, check https://github.com/woocommerce/woocommerce-blocks/pull/8609 | ||
if ( props.isDescendentOfSingleProductTemplate ) { | ||
return <PriceLabelBlock { ...props } />; | ||
} | ||
return withProductDataContext( PriceLabelBlock )( props ); | ||
}; |
Oops, something went wrong.