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-08-25 15:42:55 +00:00
|
|
|
import type { ReactElement } from 'react';
|
2021-10-29 02:35:17 +00:00
|
|
|
import { formatPrice } from '@woocommerce/price-format';
|
2021-10-21 09:07:20 +00:00
|
|
|
import { CartCheckoutCompatibilityNotice } from '@woocommerce/editor-components/compatibility-notices';
|
2022-03-26 00:32:23 +00:00
|
|
|
import { PanelBody, ExternalLink, SelectControl } 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';
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
attributes: Attributes;
|
|
|
|
setAttributes: ( attributes: Record< string, unknown > ) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MiniCartBlock = ( {
|
|
|
|
attributes,
|
|
|
|
setAttributes,
|
|
|
|
}: Props ): ReactElement => {
|
|
|
|
const { addToCartBehaviour } = 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
|
|
|
} );
|
|
|
|
|
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'
|
|
|
|
) }
|
|
|
|
>
|
|
|
|
<SelectControl
|
|
|
|
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'
|
|
|
|
) }
|
|
|
|
options={ [
|
|
|
|
{
|
|
|
|
value: 'none',
|
|
|
|
label: __(
|
|
|
|
'Do nothing',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'open_drawer',
|
|
|
|
label: __(
|
|
|
|
'Open cart drawer',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
},
|
|
|
|
] }
|
|
|
|
/>
|
|
|
|
</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>
|
|
|
|
{ __(
|
|
|
|
'Edit the appearance of your empty and filled mini cart contents.',
|
|
|
|
'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">
|
2021-12-07 14:29:56 +00:00
|
|
|
<span className="wc-block-mini-cart__amount">
|
|
|
|
{ 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-10-21 09:07:20 +00:00
|
|
|
<CartCheckoutCompatibilityNotice blockName="mini-cart" />
|
2021-08-25 15:42:55 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default MiniCartBlock;
|