2021-09-23 15:38:30 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import { SidebarLayout } from '@woocommerce/base-components/sidebar-layout';
|
2022-04-08 12:11:50 +00:00
|
|
|
import { useStoreCart } from '@woocommerce/base-context/hooks';
|
2021-09-23 15:38:30 +00:00
|
|
|
|
2021-10-18 16:12:36 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { useCartBlockContext } from '../../context';
|
|
|
|
|
2021-09-23 15:38:30 +00:00
|
|
|
const FrontendBlock = ( {
|
|
|
|
children,
|
2021-10-25 15:31:22 +00:00
|
|
|
className,
|
2021-09-23 15:38:30 +00:00
|
|
|
}: {
|
2021-10-25 14:46:34 +00:00
|
|
|
children: JSX.Element | JSX.Element[];
|
2021-10-25 15:31:22 +00:00
|
|
|
className: string;
|
2021-09-23 15:38:30 +00:00
|
|
|
} ): JSX.Element | null => {
|
2023-01-19 16:40:52 +00:00
|
|
|
const { cartItems, cartIsLoading } = useStoreCart();
|
2021-10-18 16:12:36 +00:00
|
|
|
const { hasDarkControls } = useCartBlockContext();
|
|
|
|
|
2021-09-23 15:38:30 +00:00
|
|
|
if ( cartIsLoading || cartItems.length >= 1 ) {
|
|
|
|
return (
|
|
|
|
<SidebarLayout
|
2021-10-25 15:31:22 +00:00
|
|
|
className={ classnames( 'wc-block-cart', className, {
|
2021-09-23 15:38:30 +00:00
|
|
|
'has-dark-controls': hasDarkControls,
|
|
|
|
} ) }
|
|
|
|
>
|
|
|
|
{ children }
|
|
|
|
</SidebarLayout>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default FrontendBlock;
|