diff --git a/assets/js/blocks/mini-cart/block.json b/assets/js/blocks/mini-cart/block.json new file mode 100644 index 00000000000..115537be6bf --- /dev/null +++ b/assets/js/blocks/mini-cart/block.json @@ -0,0 +1,70 @@ +{ + "name": "woocommerce/mini-cart", + "version": "1.0.0", + "title": "Mini-Cart", + "icon": "miniCartAlt", + "description": "Display a button for shoppers to quickly view their cart.", + "category": "woocommerce", + "keywords": [ "WooCommerce" ], + "textdomain": "woo-gutenberg-products-block", + "providesContext": { + "priceColorValue": "priceColorValue", + "iconColorValue": "iconColorValue", + "productCountColorValue": "productCountColorValue" + }, + "supports": { + "html": false, + "multiple": false, + "typography": { + "fontSize": true + } + }, + "example": { + "attributes": { + "isPreview": true, + "className": "wc-block-mini-cart--preview" + } + }, + "attributes": { + "isPreview": { + "type": "boolean", + "default": false + }, + "miniCartIcon": { + "type": "string", + "default": "cart" + }, + "addToCartBehaviour": { + "type": "string", + "default": "none" + }, + "hasHiddenPrice": { + "type": "boolean", + "default": false + }, + "cartAndCheckoutRenderStyle": { + "type": "string", + "default": "hidden" + }, + "priceColor": { + "type": "string" + }, + "priceColorValue": { + "type": "string" + }, + "iconColor": { + "type": "string" + }, + "iconColorValue": { + "type": "string" + }, + "productCountColor": { + "type": "string" + }, + "productCountColorValue": { + "type": "string" + } + }, + "apiVersion": 2, + "$schema": "https://schemas.wp.org/trunk/block.json" +} diff --git a/assets/js/blocks/mini-cart/index.tsx b/assets/js/blocks/mini-cart/index.tsx index 9c6e1a3f65e..4098ac26b1c 100644 --- a/assets/js/blocks/mini-cart/index.tsx +++ b/assets/js/blocks/mini-cart/index.tsx @@ -1,22 +1,30 @@ /** * External dependencies */ -import { __ } from '@wordpress/i18n'; import { miniCartAlt } from '@woocommerce/icons'; import { Icon } from '@wordpress/icons'; import { registerBlockType } from '@wordpress/blocks'; -import type { BlockConfiguration } from '@wordpress/blocks'; import { isFeaturePluginBuild } from '@woocommerce/block-settings'; import { addFilter } from '@wordpress/hooks'; - /** * Internal dependencies */ +import metadata from './block.json'; import edit from './edit'; +import './style.scss'; + +const featurePluginSupport = { + ...metadata.supports, + ...( isFeaturePluginBuild() && { + typography: { + ...metadata.supports.typography, + __experimentalFontFamily: true, + __experimentalFontWeight: true, + }, + } ), +}; -const settings: BlockConfiguration = { - apiVersion: 2, - title: __( 'Mini-Cart', 'woo-gutenberg-products-block' ), +registerBlockType( metadata, { icon: { src: ( ), }, - category: 'woocommerce', - keywords: [ __( 'WooCommerce', 'woo-gutenberg-products-block' ) ], - description: __( - 'Display a button for shoppers to quickly view their cart.', - 'woo-gutenberg-products-block' - ), providesContext: { - priceColorValue: 'priceColorValue', - iconColorValue: 'iconColorValue', - productCountColorValue: 'productCountColorValue', + ...metadata.providesContext, }, supports: { - html: false, - multiple: false, - typography: { - fontSize: true, - ...( isFeaturePluginBuild() && { - __experimentalFontFamily: true, - __experimentalFontWeight: true, - } ), - }, + ...featurePluginSupport, }, example: { - attributes: { - isPreview: true, - className: 'wc-block-mini-cart--preview', - }, + ...metadata.example, }, attributes: { - isPreview: { - type: 'boolean', - default: false, - }, - miniCartIcon: { - type: 'string', - default: 'cart', - }, - addToCartBehaviour: { - type: 'string', - default: 'none', - }, - hasHiddenPrice: { - type: 'boolean', - default: false, - }, - cartAndCheckoutRenderStyle: { - type: 'string', - default: 'hidden', - }, - priceColor: { - type: 'string', - }, - priceColorValue: { - type: 'string', - }, - iconColor: { - type: 'string', - }, - iconColorValue: { - type: 'string', - }, - productCountColor: { - type: 'string', - }, - productCountColorValue: { - type: 'string', - }, + ...metadata.attributes, }, edit, save() { return null; }, -}; - -registerBlockType( 'woocommerce/mini-cart', settings ); +} ); // Remove the Mini Cart template part from the block inserter. addFilter(