2019-12-03 13:57:56 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2019-12-05 21:08:48 +00:00
|
|
|
import { BlockControls } from '@wordpress/block-editor';
|
|
|
|
import { Toolbar } from '@wordpress/components';
|
|
|
|
import { Fragment, useState } from '@wordpress/element';
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import TextToolbarButton from '@woocommerce/block-components/text-toolbar-button';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import FullCart from './components/full-cart';
|
|
|
|
import EmptyCart from './components/empty-cart';
|
2019-12-03 13:57:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Component to handle edit mode of "Cart Block".
|
|
|
|
*/
|
|
|
|
const Cart = () => {
|
2019-12-05 21:08:48 +00:00
|
|
|
const [ isFullCartMode, setFullCartMode ] = useState( true );
|
|
|
|
|
|
|
|
const toggleFullCartMode = () => {
|
|
|
|
setFullCartMode( ! isFullCartMode );
|
|
|
|
};
|
|
|
|
|
|
|
|
const getBlockControls = () => {
|
|
|
|
return (
|
|
|
|
<BlockControls className='wc-block-cart-toolbar'>
|
|
|
|
<Toolbar>
|
|
|
|
<TextToolbarButton
|
|
|
|
onClick={ toggleFullCartMode }
|
|
|
|
isToggled={ isFullCartMode }>
|
|
|
|
{ __(
|
|
|
|
'Full Cart',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
</TextToolbarButton>
|
|
|
|
<TextToolbarButton
|
|
|
|
onClick={ toggleFullCartMode }
|
|
|
|
isToggled={ ! isFullCartMode }>
|
|
|
|
{ __(
|
|
|
|
'Empty Cart',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
</TextToolbarButton>
|
|
|
|
</Toolbar>
|
|
|
|
</BlockControls>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const cart = isFullCartMode ? <FullCart /> : <EmptyCart />;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
{ getBlockControls() }
|
|
|
|
{ cart }
|
|
|
|
</Fragment>
|
|
|
|
);
|
2019-12-03 13:57:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Cart.propTypes = {};
|
|
|
|
|
|
|
|
export default Cart;
|