2021-08-25 15:42:55 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2022-07-29 19:40:03 +00:00
|
|
|
import { miniCartAlt } from '@woocommerce/icons';
|
2022-02-01 16:54:38 +00:00
|
|
|
import { Icon } from '@wordpress/icons';
|
2022-04-08 13:47:19 +00:00
|
|
|
import { registerBlockType } from '@wordpress/blocks';
|
|
|
|
import type { BlockConfiguration } from '@wordpress/blocks';
|
2022-05-30 08:45:15 +00:00
|
|
|
import { isFeaturePluginBuild } from '@woocommerce/block-settings';
|
2023-06-20 20:28:16 +00:00
|
|
|
import { addFilter } from '@wordpress/hooks';
|
2021-08-25 15:42:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import edit from './edit';
|
|
|
|
|
2022-04-08 08:51:21 +00:00
|
|
|
const settings: BlockConfiguration = {
|
2021-08-25 15:42:55 +00:00
|
|
|
apiVersion: 2,
|
2023-05-11 12:52:03 +00:00
|
|
|
title: __( 'Mini-Cart', 'woo-gutenberg-products-block' ),
|
2021-08-25 15:42:55 +00:00
|
|
|
icon: {
|
2021-12-10 14:32:44 +00:00
|
|
|
src: (
|
|
|
|
<Icon
|
2022-07-29 19:40:03 +00:00
|
|
|
icon={ miniCartAlt }
|
2023-06-05 13:36:57 +00:00
|
|
|
className="wc-block-editor-components-block-icon wc-block-editor-mini-cart__icon"
|
2021-12-10 14:32:44 +00:00
|
|
|
/>
|
|
|
|
),
|
2021-08-25 15:42:55 +00:00
|
|
|
},
|
|
|
|
category: 'woocommerce',
|
|
|
|
keywords: [ __( 'WooCommerce', 'woo-gutenberg-products-block' ) ],
|
|
|
|
description: __(
|
2023-05-11 12:52:03 +00:00
|
|
|
'Display a button for shoppers to quickly view their cart.',
|
2021-08-25 15:42:55 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
2023-06-19 09:42:37 +00:00
|
|
|
providesContext: {
|
|
|
|
priceColorValue: 'priceColorValue',
|
|
|
|
iconColorValue: 'iconColorValue',
|
|
|
|
productCountColorValue: 'productCountColorValue',
|
|
|
|
},
|
2021-08-25 15:42:55 +00:00
|
|
|
supports: {
|
|
|
|
html: false,
|
|
|
|
multiple: false,
|
2022-05-30 08:45:15 +00:00
|
|
|
typography: {
|
|
|
|
fontSize: true,
|
|
|
|
...( isFeaturePluginBuild() && {
|
|
|
|
__experimentalFontFamily: true,
|
2022-08-05 18:15:10 +00:00
|
|
|
__experimentalFontWeight: true,
|
2022-05-30 08:45:15 +00:00
|
|
|
} ),
|
|
|
|
},
|
2021-08-25 15:42:55 +00:00
|
|
|
},
|
|
|
|
example: {
|
|
|
|
attributes: {
|
|
|
|
isPreview: true,
|
2023-02-28 17:40:06 +00:00
|
|
|
className: 'wc-block-mini-cart--preview',
|
2021-08-25 15:42:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
attributes: {
|
|
|
|
isPreview: {
|
|
|
|
type: 'boolean',
|
|
|
|
default: false,
|
|
|
|
},
|
2023-06-12 20:23:52 +00:00
|
|
|
miniCartIcon: {
|
|
|
|
type: 'string',
|
|
|
|
default: 'cart',
|
|
|
|
},
|
2022-03-26 00:32:23 +00:00
|
|
|
addToCartBehaviour: {
|
|
|
|
type: 'string',
|
|
|
|
default: 'none',
|
|
|
|
},
|
2022-08-02 14:28:52 +00:00
|
|
|
hasHiddenPrice: {
|
|
|
|
type: 'boolean',
|
|
|
|
default: false,
|
|
|
|
},
|
2023-03-14 14:59:46 +00:00
|
|
|
cartAndCheckoutRenderStyle: {
|
|
|
|
type: 'string',
|
|
|
|
default: 'hidden',
|
|
|
|
},
|
2023-06-19 09:42:37 +00:00
|
|
|
priceColor: {
|
|
|
|
type: 'string',
|
|
|
|
},
|
|
|
|
priceColorValue: {
|
|
|
|
type: 'string',
|
|
|
|
},
|
|
|
|
iconColor: {
|
|
|
|
type: 'string',
|
|
|
|
},
|
|
|
|
iconColorValue: {
|
|
|
|
type: 'string',
|
|
|
|
},
|
|
|
|
productCountColor: {
|
|
|
|
type: 'string',
|
|
|
|
},
|
|
|
|
productCountColorValue: {
|
|
|
|
type: 'string',
|
|
|
|
},
|
2021-08-25 15:42:55 +00:00
|
|
|
},
|
|
|
|
edit,
|
|
|
|
save() {
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-04-08 08:51:21 +00:00
|
|
|
registerBlockType( 'woocommerce/mini-cart', settings );
|
2023-06-20 20:28:16 +00:00
|
|
|
|
|
|
|
// Remove the Mini Cart template part from the block inserter.
|
|
|
|
addFilter(
|
|
|
|
'blocks.registerBlockType',
|
|
|
|
'woocommerce/mini-cart',
|
|
|
|
function ( blockSettings, blockName ) {
|
|
|
|
if ( blockName === 'core/template-part' ) {
|
|
|
|
return {
|
|
|
|
...blockSettings,
|
|
|
|
variations: blockSettings.variations.map(
|
|
|
|
( variation: { name: string } ) => {
|
|
|
|
if ( variation.name === 'instance_mini-cart' ) {
|
|
|
|
return {
|
|
|
|
...variation,
|
|
|
|
scope: [],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return variation;
|
|
|
|
}
|
|
|
|
),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return blockSettings;
|
|
|
|
}
|
|
|
|
);
|