Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Update Mini-Cart block editor sidebar (#9420)
Browse files Browse the repository at this point in the history
* Update Mini-Cart block editor sidebar

* Rename Mini Cart block to Mini-Cart

* Update Mini-Cart block editor sidebar (II)

* Update two instances of mini-cart to uppercase
  • Loading branch information
Aljullu committed May 11, 2023
1 parent 8ee64d5 commit c7c1e4b
Show file tree
Hide file tree
Showing 41 changed files with 198 additions and 152 deletions.
107 changes: 57 additions & 50 deletions assets/js/blocks/mini-cart/edit.tsx
Expand Up @@ -21,6 +21,7 @@ import { useSelect } from '@wordpress/data';
* Internal dependencies
*/
import QuantityBadge from './quantity-badge';
import './editor.scss';

interface Attributes {
addToCartBehaviour: string;
Expand Down Expand Up @@ -54,47 +55,18 @@ const Edit = ( { attributes, setAttributes }: Props ): ReactElement => {
<div { ...blockProps }>
<InspectorControls>
<PanelBody
title={ __(
'Mini Cart Settings',
'woo-gutenberg-products-block'
) }
title={ __( 'Settings', 'woo-gutenberg-products-block' ) }
>
<BaseControl
id="wc-block-mini-cart__add-to-cart-behaviour-toggle"
label={ __(
'Add-to-Cart behaviour',
'woo-gutenberg-products-block'
) }
>
<ToggleControl
label={ __(
'Open cart in a drawer',
'woo-gutenberg-products-block'
) }
onChange={ ( value ) => {
setAttributes( {
addToCartBehaviour: value
? 'open_drawer'
: 'none',
} );
} }
help={ __(
'Select what happens when a customer adds a product to the cart.',
'woo-gutenberg-products-block'
) }
checked={ addToCartBehaviour === 'open_drawer' }
/>
</BaseControl>
<ToggleControl
label={ __(
'Hide Cart Price',
'Display total price',
'woo-gutenberg-products-block'
) }
help={ __(
'Toggles the visibility of the Mini Cart price.',
'Toggle to display the total price of products in the shopping cart. If no products have been added, the price will not display.',
'woo-gutenberg-products-block'
) }
checked={ hasHiddenPrice }
checked={ ! hasHiddenPrice }
onChange={ () =>
setAttributes( {
hasHiddenPrice: ! hasHiddenPrice,
Expand All @@ -103,9 +75,9 @@ const Edit = ( { attributes, setAttributes }: Props ): ReactElement => {
/>
{ isSiteEditor && (
<ToggleGroupControl
className="wc-block-mini-cart__render-in-cart-and-checkout-toggle"
className="wc-block-editor-mini-cart__render-in-cart-and-checkout-toggle"
label={ __(
'Mini Cart in cart and checkout pages',
'Mini-Cart in cart and checkout pages',
'woo-gutenberg-products-block'
) }
value={ cartAndCheckoutRenderStyle }
Expand All @@ -115,7 +87,7 @@ const Edit = ( { attributes, setAttributes }: Props ): ReactElement => {
} );
} }
help={ __(
'Select how the Mini Cart behaves in the Cart and Checkout pages. This might affect the header layout.',
'Select how the Mini-Cart behaves in the Cart and Checkout pages. This might affect the header layout.',
'woo-gutenberg-products-block'
) }
>
Expand All @@ -136,27 +108,62 @@ const Edit = ( { attributes, setAttributes }: Props ): ReactElement => {
</ToggleGroupControl>
) }
</PanelBody>
{ templatePartEditUri && (
<PanelBody
title={ __(
'Template settings',
<PanelBody
title={ __(
'Cart Drawer',
'woo-gutenberg-products-block'
) }
>
{ templatePartEditUri && (
<>
<img
className="wc-block-editor-mini-cart__drawer-image"
src="/wp-content/plugins/woocommerce-blocks/images/blocks/mini-cart/cart-drawer.svg"
alt=""
/>
<p>
{ __(
'When opened, the Mini-Cart drawer gives shoppers quick access to view their selected products and checkout.',
'woo-gutenberg-products-block'
) }
</p>
<p className="wc-block-editor-mini-cart__drawer-link">
<ExternalLink href={ templatePartEditUri }>
{ __(
'Edit Mini-Cart Drawer template',
'woo-gutenberg-products-block'
) }
</ExternalLink>
</p>
</>
) }
<BaseControl
id="wc-block-mini-cart__add-to-cart-behaviour-toggle"
label={ __(
'Behavior',
'woo-gutenberg-products-block'
) }
>
<p>
{ __(
'Edit the appearance of the Mini Cart.',
<ToggleControl
label={ __(
'Open drawer when adding',
'woo-gutenberg-products-block'
) }
</p>
<ExternalLink href={ templatePartEditUri }>
{ __(
'Edit Mini Cart template part',
onChange={ ( value ) => {
setAttributes( {
addToCartBehaviour: value
? 'open_drawer'
: 'none',
} );
} }
help={ __(
'Toggle to open the Mini-Cart drawer when a shopper adds a product to their cart.',
'woo-gutenberg-products-block'
) }
</ExternalLink>
</PanelBody>
) }
checked={ addToCartBehaviour === 'open_drawer' }
/>
</BaseControl>
</PanelBody>
</InspectorControls>
<Noninteractive>
<button className="wc-block-mini-cart__button">
Expand Down
11 changes: 11 additions & 0 deletions assets/js/blocks/mini-cart/editor.scss
@@ -0,0 +1,11 @@
.wc-block-editor-mini-cart__render-in-cart-and-checkout-toggle {
width: 100%;
}

.wc-block-editor-mini-cart__drawer-image {
margin-bottom: 6px;
}

.wc-block-editor-mini-cart__drawer-link {
margin-bottom: 24px;
}
4 changes: 2 additions & 2 deletions assets/js/blocks/mini-cart/frontend.ts
Expand Up @@ -155,7 +155,7 @@ window.addEventListener( 'load', () => {
? openDrawerWithRefresh
: loadContentsWithRefresh;

// There might be more than one Mini Cart block in the page. Make sure
// There might be more than one Mini-Cart block in the page. Make sure
// only one opens when adding a product to the cart.
if ( i === 0 ) {
document.body.addEventListener(
Expand All @@ -171,7 +171,7 @@ window.addEventListener( 'load', () => {

/**
* Get the background color of the body then set it as the background color
* of the Mini Cart Contents block. We use :where here to make customized
* of the Mini-Cart Contents block. We use :where here to make customized
* background color alway have higher priority.
*
* We only set the background color, instead of the whole background. As
Expand Down
4 changes: 2 additions & 2 deletions assets/js/blocks/mini-cart/index.tsx
Expand Up @@ -15,7 +15,7 @@ import edit from './edit';

const settings: BlockConfiguration = {
apiVersion: 2,
title: __( 'Mini Cart', 'woo-gutenberg-products-block' ),
title: __( 'Mini-Cart', 'woo-gutenberg-products-block' ),
icon: {
src: (
<Icon
Expand All @@ -27,7 +27,7 @@ const settings: BlockConfiguration = {
category: 'woocommerce',
keywords: [ __( 'WooCommerce', 'woo-gutenberg-products-block' ) ],
description: __(
'Display a mini cart widget.',
'Display a button for shoppers to quickly view their cart.',
'woo-gutenberg-products-block'
),
supports: {
Expand Down
4 changes: 2 additions & 2 deletions assets/js/blocks/mini-cart/mini-cart-contents/attributes.tsx
Expand Up @@ -29,12 +29,12 @@ export const attributes = {
default: [
{
view: 'woocommerce/filled-mini-cart-contents-block',
label: __( 'Filled Mini Cart', 'woo-gutenberg-products-block' ),
label: __( 'Filled Mini-Cart', 'woo-gutenberg-products-block' ),
icon: <Icon icon={ filledCart } />,
},
{
view: 'woocommerce/empty-mini-cart-contents-block',
label: __( 'Empty Mini Cart', 'woo-gutenberg-products-block' ),
label: __( 'Empty Mini-Cart', 'woo-gutenberg-products-block' ),
icon: <Icon icon={ removeCart } />,
},
],
Expand Down
4 changes: 2 additions & 2 deletions assets/js/blocks/mini-cart/mini-cart-contents/edit.tsx
Expand Up @@ -50,7 +50,7 @@ const Edit = ( {
const blockProps = useBlockProps( {
/**
* This is a workaround for the Site Editor to calculate the
* correct height of the Mini Cart template part on the first load.
* correct height of the Mini-Cart template part on the first load.
*
* @see https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5825
*/
Expand All @@ -73,7 +73,7 @@ const Edit = ( {

/**
* This is a workaround for the Site Editor to set the correct
* background color of the Mini Cart Contents block base on
* background color of the Mini-Cart Contents block base on
* the main background color set by the theme.
*/
useEffect( () => {
Expand Down
4 changes: 2 additions & 2 deletions assets/js/blocks/mini-cart/mini-cart-contents/index.tsx
Expand Up @@ -17,7 +17,7 @@ import './inner-blocks';

const settings: BlockConfiguration = {
apiVersion: 2,
title: __( 'Mini Cart Contents', 'woo-gutenberg-products-block' ),
title: __( 'Mini-Cart Contents', 'woo-gutenberg-products-block' ),
icon: {
src: (
<Icon
Expand All @@ -29,7 +29,7 @@ const settings: BlockConfiguration = {
category: 'woocommerce',
keywords: [ __( 'WooCommerce', 'woo-gutenberg-products-block' ) ],
description: __(
'Display a mini cart widget.',
'Display a Mini-Cart widget.',
'woo-gutenberg-products-block'
),
supports: {
Expand Down
@@ -1,9 +1,9 @@
/**
* This is a workaround to style inner blocks using the color
* settings of the Mini Cart Contents block. It's possible to get
* the Mini Cart Contents block's attributes inside the inner blocks
* settings of the Mini-Cart Contents block. It's possible to get
* the Mini-Cart Contents block's attributes inside the inner blocks
* components, but we have 4 out of 7 inner blocks that inherit
* style from the Mini Cart Contents block, so we need to apply the
* style from the Mini-Cart Contents block, so we need to apply the
* styles here to avoid duplication.
*
* We only use this hack for the Site Editor. On the frontend, we
Expand Down
@@ -1,8 +1,8 @@
{
"name": "woocommerce/empty-mini-cart-contents-block",
"version": "1.0.0",
"title": "Empty Mini Cart view",
"description": "Blocks that are displayed when the Mini Cart is empty.",
"title": "Empty Mini-Cart view",
"description": "Blocks that are displayed when the Mini-Cart is empty.",
"category": "woocommerce",
"supports": {
"align": false,
Expand Down
@@ -1,8 +1,8 @@
{
"name": "woocommerce/filled-mini-cart-contents-block",
"version": "1.0.0",
"title": "Filled Mini Cart view",
"description": "Contains blocks that display the content of the Mini Cart.",
"title": "Filled Mini-Cart view",
"description": "Contains blocks that display the content of the Mini-Cart.",
"category": "woocommerce",
"supports": {
"align": false,
Expand Down
@@ -1,8 +1,8 @@
{
"name": "woocommerce/mini-cart-cart-button-block",
"version": "1.0.0",
"title": "Mini Cart View Cart Button",
"description": "Block that displays the cart button when the Mini Cart has products.",
"title": "Mini-Cart View Cart Button",
"description": "Block that displays the cart button when the Mini-Cart has products.",
"category": "woocommerce",
"supports": {
"align": false,
Expand Down
@@ -1,8 +1,8 @@
{
"name": "woocommerce/mini-cart-checkout-button-block",
"version": "1.0.0",
"title": "Mini Cart Proceed to Checkout Button",
"description": "Block that displays the checkout button when the Mini Cart has products.",
"title": "Mini-Cart Proceed to Checkout Button",
"description": "Block that displays the checkout button when the Mini-Cart has products.",
"category": "woocommerce",
"supports": {
"align": false,
Expand Down
@@ -1,8 +1,8 @@
{
"name": "woocommerce/mini-cart-footer-block",
"version": "1.0.0",
"title": "Mini Cart Footer",
"description": "Block that displays the footer of the Mini Cart block.",
"title": "Mini-Cart Footer",
"description": "Block that displays the footer of the Mini-Cart block.",
"category": "woocommerce",
"supports": {
"align": false,
Expand Down
@@ -1,8 +1,8 @@
{
"name": "woocommerce/mini-cart-items-block",
"version": "1.0.0",
"title": "Mini Cart Items",
"description": "Contains the products table and other custom blocks of filled mini cart.",
"title": "Mini-Cart Items",
"description": "Contains the products table and other custom blocks of filled mini-cart.",
"category": "woocommerce",
"supports": {
"align": false,
Expand Down
@@ -1,8 +1,8 @@
{
"name": "woocommerce/mini-cart-products-table-block",
"version": "1.0.0",
"title": "Mini Cart Products Table",
"description": "Block that displays the products table of the Mini Cart block.",
"title": "Mini-Cart Products Table",
"description": "Block that displays the products table of the Mini-Cart block.",
"category": "woocommerce",
"supports": {
"align": false,
Expand Down
@@ -1,8 +1,8 @@
{
"name": "woocommerce/mini-cart-shopping-button-block",
"version": "1.0.0",
"title": "Mini Cart Shopping Button",
"description": "Block that displays the shopping button when the Mini Cart is empty.",
"title": "Mini-Cart Shopping Button",
"description": "Block that displays the shopping button when the Mini-Cart is empty.",
"category": "woocommerce",
"supports": {
"align": false,
Expand Down
@@ -1,8 +1,8 @@
{
"name": "woocommerce/mini-cart-title-block",
"version": "1.0.0",
"title": "Mini Cart Title",
"description": "Block that displays the title of the Mini Cart block.",
"title": "Mini-Cart Title",
"description": "Block that displays the title of the Mini-Cart block.",
"category": "woocommerce",
"supports": {
"align": false,
Expand Down
Expand Up @@ -25,7 +25,7 @@ const Block = ( {
return null;
}

// The `Mini Cart Title` was converted to two inner blocks, but we still need to render the old title for
// The `Mini-Cart Title` was converted to two inner blocks, but we still need to render the old title for
// themes that have the old `mini-cart.html` template. So we check if there are any inner blocks and if
// not, render the title blocks.
const hasTitleInnerBlocks = hasChildren( children );
Expand Down
@@ -1,8 +1,8 @@
{
"name": "woocommerce/mini-cart-title-items-counter-block",
"version": "1.0.0",
"title": "Mini Cart Title Items Counter",
"description": "Block that displays the items counter part of the Mini Cart Title block.",
"title": "Mini-Cart Title Items Counter",
"description": "Block that displays the items counter part of the Mini-Cart Title block.",
"category": "woocommerce",
"supports": {
"align": false,
Expand Down
@@ -1,8 +1,8 @@
{
"name": "woocommerce/mini-cart-title-label-block",
"version": "1.0.0",
"title": "Mini Cart Title Label",
"description": "Block that displays the 'Your cart' part of the Mini Cart Title block.",
"title": "Mini-Cart Title Label",
"description": "Block that displays the 'Your cart' part of the Mini-Cart Title block.",
"category": "woocommerce",
"supports": {
"align": false,
Expand Down

0 comments on commit c7c1e4b

Please sign in to comment.