2021-08-25 15:42:55 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2022-03-09 09:13:52 +00:00
|
|
|
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
|
2021-10-29 02:35:17 +00:00
|
|
|
import { formatPrice } from '@woocommerce/price-format';
|
2022-08-02 14:28:52 +00:00
|
|
|
import {
|
|
|
|
PanelBody,
|
|
|
|
ExternalLink,
|
|
|
|
ToggleControl,
|
2023-03-02 14:09:37 +00:00
|
|
|
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
|
|
|
|
__experimentalToggleGroupControl as ToggleGroupControl,
|
2022-08-02 14:28:52 +00:00
|
|
|
} from '@wordpress/components';
|
2021-12-14 00:54:23 +00:00
|
|
|
import { getSetting } from '@woocommerce/settings';
|
2021-11-17 15:39:07 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2021-12-07 14:29:56 +00:00
|
|
|
import Noninteractive from '@woocommerce/base-components/noninteractive';
|
2023-03-02 14:26:00 +00:00
|
|
|
import type { ReactElement } from 'react';
|
2023-03-14 14:59:46 +00:00
|
|
|
import { useSelect } from '@wordpress/data';
|
2021-08-25 15:42:55 +00:00
|
|
|
|
2021-10-29 02:35:17 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import QuantityBadge from './quantity-badge';
|
|
|
|
|
2022-03-26 00:32:23 +00:00
|
|
|
interface Attributes {
|
|
|
|
addToCartBehaviour: string;
|
2022-08-02 14:28:52 +00:00
|
|
|
hasHiddenPrice: boolean;
|
2023-03-14 14:59:46 +00:00
|
|
|
cartAndCheckoutRenderStyle: boolean;
|
2022-03-26 00:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
attributes: Attributes;
|
|
|
|
setAttributes: ( attributes: Record< string, unknown > ) => void;
|
|
|
|
}
|
|
|
|
|
2022-04-08 08:51:21 +00:00
|
|
|
const Edit = ( { attributes, setAttributes }: Props ): ReactElement => {
|
2023-03-14 14:59:46 +00:00
|
|
|
const { addToCartBehaviour, hasHiddenPrice, cartAndCheckoutRenderStyle } =
|
|
|
|
attributes;
|
2021-08-25 15:42:55 +00:00
|
|
|
const blockProps = useBlockProps( {
|
2022-03-09 09:13:52 +00:00
|
|
|
className: `wc-block-mini-cart`,
|
2021-11-17 15:39:07 +00:00
|
|
|
} );
|
|
|
|
|
2023-03-14 14:59:46 +00:00
|
|
|
const isSiteEditor = useSelect( 'core/edit-site' ) !== undefined;
|
|
|
|
|
2021-12-14 00:54:23 +00:00
|
|
|
const templatePartEditUri = getSetting(
|
|
|
|
'templatePartEditUri',
|
|
|
|
''
|
|
|
|
) as string;
|
2021-11-30 09:42:07 +00:00
|
|
|
|
2021-08-25 15:42:55 +00:00
|
|
|
const productCount = 0;
|
2021-10-29 02:35:17 +00:00
|
|
|
const productTotal = 0;
|
2021-08-25 15:42:55 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div { ...blockProps }>
|
2021-11-17 15:39:07 +00:00
|
|
|
<InspectorControls>
|
2022-03-26 00:32:23 +00:00
|
|
|
<PanelBody
|
|
|
|
title={ __(
|
|
|
|
'Mini Cart Settings',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
>
|
2023-03-02 14:09:37 +00:00
|
|
|
<ToggleGroupControl
|
2023-03-14 14:59:46 +00:00
|
|
|
className="wc-block-mini-cart__add-to-cart-behaviour-toggle"
|
2022-03-26 00:32:23 +00:00
|
|
|
label={ __(
|
|
|
|
'Add-to-Cart behaviour',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
value={ addToCartBehaviour }
|
|
|
|
onChange={ ( value ) => {
|
|
|
|
setAttributes( { addToCartBehaviour: value } );
|
|
|
|
} }
|
|
|
|
help={ __(
|
|
|
|
'Select what happens when a customer adds a product to the cart.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2023-03-02 14:09:37 +00:00
|
|
|
>
|
|
|
|
<ToggleGroupControlOption
|
|
|
|
value="none"
|
|
|
|
label={ __(
|
|
|
|
'Do nothing',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
<ToggleGroupControlOption
|
|
|
|
value="open_drawer"
|
|
|
|
label={ __(
|
|
|
|
'Open cart drawer',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
</ToggleGroupControl>
|
2022-08-02 14:28:52 +00:00
|
|
|
<ToggleControl
|
|
|
|
label={ __(
|
|
|
|
'Hide Cart Price',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
help={ __(
|
|
|
|
'Toggles the visibility of the Mini Cart price.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
checked={ hasHiddenPrice }
|
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
|
|
|
hasHiddenPrice: ! hasHiddenPrice,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
2023-03-14 14:59:46 +00:00
|
|
|
{ isSiteEditor && (
|
|
|
|
<ToggleGroupControl
|
|
|
|
className="wc-block-mini-cart__render-in-cart-and-checkout-toggle"
|
|
|
|
label={ __(
|
|
|
|
'Mini Cart in cart and checkout pages',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
value={ cartAndCheckoutRenderStyle }
|
|
|
|
onChange={ ( value ) => {
|
|
|
|
setAttributes( {
|
|
|
|
cartAndCheckoutRenderStyle: value,
|
|
|
|
} );
|
|
|
|
} }
|
|
|
|
help={ __(
|
|
|
|
'Select how the Mini Cart behaves in the Cart and Checkout pages. This might affect the header layout.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
>
|
|
|
|
<ToggleGroupControlOption
|
|
|
|
value={ 'hidden' }
|
|
|
|
label={ __(
|
|
|
|
'Hide',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
<ToggleGroupControlOption
|
|
|
|
value={ 'removed' }
|
|
|
|
label={ __(
|
|
|
|
'Remove',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
</ToggleGroupControl>
|
|
|
|
) }
|
2022-03-26 00:32:23 +00:00
|
|
|
</PanelBody>
|
2021-12-14 00:54:23 +00:00
|
|
|
{ templatePartEditUri && (
|
|
|
|
<PanelBody
|
|
|
|
title={ __(
|
2022-03-22 01:56:02 +00:00
|
|
|
'Template settings',
|
2021-12-14 00:54:23 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
>
|
2022-03-22 01:56:02 +00:00
|
|
|
<p>
|
|
|
|
{ __(
|
2022-09-12 08:39:26 +00:00
|
|
|
'Edit the appearance of the Mini Cart.',
|
2022-03-22 01:56:02 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
</p>
|
2021-12-14 00:54:23 +00:00
|
|
|
<ExternalLink href={ templatePartEditUri }>
|
|
|
|
{ __(
|
2022-03-22 01:56:02 +00:00
|
|
|
'Edit Mini Cart template part',
|
2021-11-30 09:42:07 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2021-12-14 00:54:23 +00:00
|
|
|
</ExternalLink>
|
|
|
|
</PanelBody>
|
|
|
|
) }
|
2021-11-17 15:39:07 +00:00
|
|
|
</InspectorControls>
|
2021-12-07 14:29:56 +00:00
|
|
|
<Noninteractive>
|
2022-03-09 09:13:52 +00:00
|
|
|
<button className="wc-block-mini-cart__button">
|
2022-08-02 14:28:52 +00:00
|
|
|
{ ! hasHiddenPrice && (
|
2022-10-31 10:47:01 +00:00
|
|
|
<span className="wc-block-mini-cart__amount">
|
2022-08-02 14:28:52 +00:00
|
|
|
{ formatPrice( productTotal ) }
|
|
|
|
</span>
|
|
|
|
) }
|
2022-03-09 09:13:52 +00:00
|
|
|
<QuantityBadge count={ productCount } />
|
2021-12-07 14:29:56 +00:00
|
|
|
</button>
|
|
|
|
</Noninteractive>
|
2021-08-25 15:42:55 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-04-08 08:51:21 +00:00
|
|
|
export default Edit;
|