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