-
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 product safety instructions freetext product option.
- Loading branch information
1 parent
0ea0114
commit 4979aa4
Showing
24 changed files
with
364 additions
and
11 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
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/safety-instructions/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': 'safety_instructions' }; | ||
|
||
// 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/safety-instructions/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/safety-instructions/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; |
38 changes: 38 additions & 0 deletions
38
assets/js/blocks/product-elements/safety-instructions/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,38 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
import { page, Icon } from '@wordpress/icons'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { getSetting } from '@germanized/settings'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import sharedConfig from '../shared/config'; | ||
import edit from './edit'; | ||
|
||
const { ancestor, ...configuration } = sharedConfig; | ||
|
||
const blockConfig = { | ||
...configuration, | ||
apiVersion: 2, | ||
title: __( 'Safety instructions', 'woocommerce-germanized' ) + ( ! getSetting( 'isPro' ) ? ' (Pro)' : '' ), | ||
description: __( 'Inserts the product\'s safety instructions.', '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-safety-instructions .wc-gzd-block-components-product-safety-instructions', | ||
} ) | ||
}, | ||
edit, | ||
}; | ||
|
||
registerBlockType( 'woocommerce-germanized/product-safety-instructions', 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
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
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.