Product Query: create variation of `core/post-excerpt` as a Product Query inner block (https://github.com/woocommerce/woocommerce-blocks/pull/7837)
* Creates a new block variation based on the core “Post Excerpt” called “Product Summary”. * Brands it as our old “Product Summary” atomic element. * Creates a utility function to allow easy creation of such variations.
This commit is contained in:
parent
7dc5643dff
commit
dc63c2dc46
|
@ -8,12 +8,13 @@ import { addFilter } from '@wordpress/hooks';
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { CORE_NAME as PRODUCT_TITLE_ID } from './variations/elements/product-title';
|
import { CORE_NAME as PRODUCT_TITLE_ID } from './variations/elements/product-title';
|
||||||
|
import { CORE_NAME as PRODUCT_SUMMARY_ID } from './variations/elements/product-summary';
|
||||||
import './inspector-controls';
|
import './inspector-controls';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
import './variations/product-query';
|
import './variations/product-query';
|
||||||
import './variations/products-on-sale';
|
import './variations/products-on-sale';
|
||||||
|
|
||||||
const EXTENDED_CORE_ELEMENTS = [ PRODUCT_TITLE_ID ];
|
const EXTENDED_CORE_ELEMENTS = [ PRODUCT_SUMMARY_ID, PRODUCT_TITLE_ID ];
|
||||||
|
|
||||||
function registerProductQueryElementsNamespace(
|
function registerProductQueryElementsNamespace(
|
||||||
props: Block,
|
props: Block,
|
||||||
|
|
|
@ -175,7 +175,7 @@ export const withProductQueryControls =
|
||||||
<PopularPresets { ...props } />
|
<PopularPresets { ...props } />
|
||||||
) }
|
) }
|
||||||
<ToolsPanel
|
<ToolsPanel
|
||||||
class="woocommerce-product-query-toolspanel"
|
className="woocommerce-product-query-toolspanel"
|
||||||
label={ __(
|
label={ __(
|
||||||
'Advanced Filters',
|
'Advanced Filters',
|
||||||
'woo-gutenberg-products-block'
|
'woo-gutenberg-products-block'
|
||||||
|
@ -187,7 +187,7 @@ export const withProductQueryControls =
|
||||||
{ Object.entries( TOOLS_PANEL_CONTROLS ).map(
|
{ Object.entries( TOOLS_PANEL_CONTROLS ).map(
|
||||||
( [ key, Control ] ) =>
|
( [ key, Control ] ) =>
|
||||||
allowedControls?.includes( key ) ? (
|
allowedControls?.includes( key ) ? (
|
||||||
<Control { ...props } />
|
<Control { ...props } key={ key } />
|
||||||
) : null
|
) : null
|
||||||
) }
|
) }
|
||||||
</ToolsPanel>
|
</ToolsPanel>
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { isFeaturePluginBuild } from '@woocommerce/block-settings';
|
||||||
|
import {
|
||||||
|
BLOCK_DESCRIPTION,
|
||||||
|
BLOCK_ICON,
|
||||||
|
BLOCK_TITLE,
|
||||||
|
} from '@woocommerce/atomic-blocks/product-elements/summary/constants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal dependencies
|
||||||
|
*/
|
||||||
|
import { registerElementVariation } from './utils';
|
||||||
|
|
||||||
|
export const CORE_NAME = 'core/post-excerpt';
|
||||||
|
export const VARIATION_NAME = 'woocommerce/product-query/product-summary';
|
||||||
|
|
||||||
|
if ( isFeaturePluginBuild() ) {
|
||||||
|
registerElementVariation( CORE_NAME, {
|
||||||
|
blockDescription: BLOCK_DESCRIPTION,
|
||||||
|
blockIcon: BLOCK_ICON,
|
||||||
|
blockTitle: BLOCK_TITLE,
|
||||||
|
variationName: VARIATION_NAME,
|
||||||
|
} );
|
||||||
|
}
|
|
@ -2,29 +2,25 @@
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { isFeaturePluginBuild } from '@woocommerce/block-settings';
|
import { isFeaturePluginBuild } from '@woocommerce/block-settings';
|
||||||
import { registerBlockVariation } from '@wordpress/blocks';
|
|
||||||
import {
|
import {
|
||||||
BLOCK_DESCRIPTION,
|
BLOCK_DESCRIPTION,
|
||||||
BLOCK_ICON,
|
BLOCK_ICON,
|
||||||
BLOCK_TITLE,
|
BLOCK_TITLE,
|
||||||
} from '@woocommerce/atomic-blocks/product-elements/title/constants';
|
} from '@woocommerce/atomic-blocks/product-elements/title/constants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal dependencies
|
||||||
|
*/
|
||||||
|
import { registerElementVariation } from './utils';
|
||||||
|
|
||||||
export const CORE_NAME = 'core/post-title';
|
export const CORE_NAME = 'core/post-title';
|
||||||
export const VARIATION_NAME = 'woocommerce/product-query/product-title';
|
export const VARIATION_NAME = 'woocommerce/product-query/product-title';
|
||||||
|
|
||||||
if ( isFeaturePluginBuild() ) {
|
if ( isFeaturePluginBuild() ) {
|
||||||
registerBlockVariation( CORE_NAME, {
|
registerElementVariation( CORE_NAME, {
|
||||||
description: BLOCK_DESCRIPTION,
|
blockDescription: BLOCK_DESCRIPTION,
|
||||||
name: VARIATION_NAME,
|
blockIcon: BLOCK_ICON,
|
||||||
title: BLOCK_TITLE,
|
blockTitle: BLOCK_TITLE,
|
||||||
isActive: ( blockAttributes ) =>
|
variationName: VARIATION_NAME,
|
||||||
blockAttributes.__woocommerceNamespace === VARIATION_NAME,
|
|
||||||
icon: {
|
|
||||||
src: BLOCK_ICON,
|
|
||||||
},
|
|
||||||
attributes: {
|
|
||||||
__woocommerceNamespace: VARIATION_NAME,
|
|
||||||
},
|
|
||||||
scope: [ 'block', 'inserter' ],
|
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { registerBlockVariation } from '@wordpress/blocks';
|
||||||
|
|
||||||
|
interface VariationDetails {
|
||||||
|
blockDescription: string;
|
||||||
|
blockIcon: JSX.Element;
|
||||||
|
blockTitle: string;
|
||||||
|
variationName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function registerElementVariation(
|
||||||
|
coreName: string,
|
||||||
|
{ blockDescription, blockIcon, blockTitle, variationName }: VariationDetails
|
||||||
|
) {
|
||||||
|
registerBlockVariation( coreName, {
|
||||||
|
description: blockDescription,
|
||||||
|
name: variationName,
|
||||||
|
title: blockTitle,
|
||||||
|
isActive: ( blockAttributes ) =>
|
||||||
|
blockAttributes.__woocommerceNamespace === variationName,
|
||||||
|
icon: {
|
||||||
|
src: blockIcon,
|
||||||
|
},
|
||||||
|
attributes: {
|
||||||
|
__woocommerceNamespace: variationName,
|
||||||
|
},
|
||||||
|
scope: [ 'block', 'inserter' ],
|
||||||
|
} );
|
||||||
|
}
|
Loading…
Reference in New Issue