Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Reuse the TotalsWrapper component for C& C blocks inner blocks
Browse files Browse the repository at this point in the history
This component was removed in this PR, but  we wrap components in the Cart and Checkout sidebar in a TotalsWrapper. This will ensure consistent spacing and borders are applied to items in the sidebar.
  • Loading branch information
ralucaStan committed Apr 1, 2022
1 parent 3e35e51 commit 506eda5
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import classnames from 'classnames';
import { useContainerWidthContext } from '@woocommerce/base-context';
import { Panel } from '@woocommerce/blocks-checkout';
import type { CartItem } from '@woocommerce/types';
Expand All @@ -14,12 +13,10 @@ import OrderSummaryItem from './order-summary-item';
import './style.scss';

interface OrderSummaryProps {
className: string;
cartItems: CartItem[];
}

const OrderSummary = ( {
className = '',
cartItems = [],
}: OrderSummaryProps ): null | JSX.Element => {
const { isLarge, hasContainerWidth } = useContainerWidthContext();
Expand All @@ -30,10 +27,7 @@ const OrderSummary = ( {

return (
<Panel
className={ classnames(
'wc-block-components-order-summary',
className
) }
className="wc-block-components-order-summary"
initialOpen={ isLarge }
hasBorder={ false }
title={
Expand Down
11 changes: 1 addition & 10 deletions assets/js/base/components/cart-checkout/totals/coupon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
useValidationContext,
} from '@woocommerce/base-context';
import { Panel } from '@woocommerce/blocks-checkout';
import classnames from 'classnames';

/**
* Internal dependencies
Expand All @@ -37,18 +36,13 @@ export interface TotalsCouponProps {
* Submit handler
*/
onSubmit?: ( couponValue: string ) => void;
/**
* User defined classname in the block settings
*/
className?: string;
}

export const TotalsCoupon = ( {
instanceId,
isLoading = false,
initialOpen = false,
onSubmit = () => void 0,
className = '',
}: TotalsCouponProps ): JSX.Element => {
const [ couponValue, setCouponValue ] = useState( '' );
const currentIsLoading = useRef( false );
Expand All @@ -68,10 +62,7 @@ export const TotalsCoupon = ( {

return (
<Panel
className={ classnames(
className,
'wc-block-components-totals-coupon'
) }
className="wc-block-components-totals-coupon"
hasBorder={ false }
initialOpen={ initialOpen }
title={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
Currency,
} from '@woocommerce/types';
import { LooselyMustHave } from '@woocommerce/type-defs/utils';
import classNames from 'classnames';

/**
* Internal dependencies
Expand All @@ -34,7 +33,6 @@ export interface TotalsDiscountProps {
CartTotalsItem,
'total_discount' | 'total_discount_tax'
>;
className?: string;
}

const filteredCartCouponsFilterArg = {
Expand All @@ -47,7 +45,6 @@ const TotalsDiscount = ( {
isRemovingCoupon,
removeCoupon,
values,
className,
}: TotalsDiscountProps ): JSX.Element | null => {
const {
total_discount: totalDiscount,
Expand Down Expand Up @@ -75,10 +72,7 @@ const TotalsDiscount = ( {

return (
<TotalsItem
className={ classNames(
className,
'wc-block-components-totals-discount'
) }
className="wc-block-components-totals-discount"
currency={ currency }
description={
filteredCartCoupons.length !== 0 && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { TotalsCoupon } from '@woocommerce/base-components/cart-checkout';
import { useStoreCartCoupons } from '@woocommerce/base-context/hooks';
import { getSetting } from '@woocommerce/settings';
import { TotalsWrapper } from '@woocommerce/blocks-checkout';

const Block = ( { className }: { className: string } ): JSX.Element | null => {
const couponsEnabled = getSetting( 'couponsEnabled', true );
Expand All @@ -15,11 +16,12 @@ const Block = ( { className }: { className: string } ): JSX.Element | null => {
}

return (
<TotalsCoupon
className={ `${ className } wc-block-components-totals-wrapper` }
onSubmit={ applyCoupon }
isLoading={ isApplyingCoupon }
/>
<TotalsWrapper className={ className }>
<TotalsCoupon
onSubmit={ applyCoupon }
isLoading={ isApplyingCoupon }
/>
</TotalsWrapper>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
useStoreCartCoupons,
useStoreCart,
} from '@woocommerce/base-context/hooks';
import { ExperimentalDiscountsMeta } from '@woocommerce/blocks-checkout';
import {
ExperimentalDiscountsMeta,
TotalsWrapper,
} from '@woocommerce/blocks-checkout';

const DiscountSlotFill = (): JSX.Element => {
// Prepare props to pass to the ExperimentalOrderMeta slot fill. We need to pluck out receiveCart.
Expand All @@ -24,20 +27,20 @@ const DiscountSlotFill = (): JSX.Element => {

const Block = ( { className }: { className: string } ): JSX.Element => {
const { cartTotals, cartCoupons } = useStoreCart();

const { removeCoupon, isRemovingCoupon } = useStoreCartCoupons();
const totalsCurrency = getCurrencyFromPriceResponse( cartTotals );

return (
<>
<TotalsDiscount
className={ `${ className } wc-block-components-totals-wrapper` }
cartCoupons={ cartCoupons }
currency={ totalsCurrency }
isRemovingCoupon={ isRemovingCoupon }
removeCoupon={ removeCoupon }
values={ cartTotals }
/>
<TotalsWrapper className={ className }>
<TotalsDiscount
cartCoupons={ cartCoupons }
currency={ totalsCurrency }
isRemovingCoupon={ isRemovingCoupon }
removeCoupon={ removeCoupon }
values={ cartTotals }
/>
</TotalsWrapper>
<DiscountSlotFill />
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { TotalsFees } from '@woocommerce/blocks-checkout';
import { TotalsFees, TotalsWrapper } from '@woocommerce/blocks-checkout';
import { getCurrencyFromPriceResponse } from '@woocommerce/price-format';
import { useStoreCart } from '@woocommerce/base-context/hooks';

Expand All @@ -10,11 +10,9 @@ const Block = ( { className }: { className: string } ): JSX.Element => {
const totalsCurrency = getCurrencyFromPriceResponse( cartTotals );

return (
<TotalsFees
className={ `${ className } wc-block-components-totals-wrapper` }
currency={ totalsCurrency }
cartFees={ cartFees }
/>
<TotalsWrapper className={ className }>
<TotalsFees currency={ totalsCurrency } cartFees={ cartFees } />
</TotalsWrapper>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { TotalsShipping } from '@woocommerce/base-components/cart-checkout';
import { getCurrencyFromPriceResponse } from '@woocommerce/price-format';
import { useStoreCart } from '@woocommerce/base-context/hooks';
import { TotalsWrapper } from '@woocommerce/blocks-checkout';

const Block = ( {
className,
Expand All @@ -21,13 +22,14 @@ const Block = ( {
const totalsCurrency = getCurrencyFromPriceResponse( cartTotals );

return (
<TotalsShipping
className={ `${ className } wc-block-components-totals-wrapper` }
showCalculator={ isShippingCalculatorEnabled }
showRateSelector={ true }
values={ cartTotals }
currency={ totalsCurrency }
/>
<TotalsWrapper className={ className }>
<TotalsShipping
showCalculator={ isShippingCalculatorEnabled }
showRateSelector={ true }
values={ cartTotals }
currency={ totalsCurrency }
/>
</TotalsWrapper>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { Subtotal } from '@woocommerce/blocks-checkout';
import { Subtotal, TotalsWrapper } from '@woocommerce/blocks-checkout';
import { getCurrencyFromPriceResponse } from '@woocommerce/price-format';
import { useStoreCart } from '@woocommerce/base-context/hooks';

Expand All @@ -10,11 +10,9 @@ const Block = ( { className = '' }: { className?: string } ): JSX.Element => {
const totalsCurrency = getCurrencyFromPriceResponse( cartTotals );

return (
<Subtotal
className={ `${ className } wc-block-components-totals-wrapper` }
currency={ totalsCurrency }
values={ cartTotals }
/>
<TotalsWrapper className={ className }>
<Subtotal currency={ totalsCurrency } values={ cartTotals } />
</TotalsWrapper>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { TotalsTaxes } from '@woocommerce/blocks-checkout';
import { TotalsTaxes, TotalsWrapper } from '@woocommerce/blocks-checkout';
import { getCurrencyFromPriceResponse } from '@woocommerce/price-format';
import { useStoreCart } from '@woocommerce/base-context/hooks';
import { getSetting } from '@woocommerce/settings';
Expand Down Expand Up @@ -30,12 +30,13 @@ const Block = ( {
const totalsCurrency = getCurrencyFromPriceResponse( cartTotals );

return (
<TotalsTaxes
className={ `${ className } wc-block-components-totals-wrapper` }
showRateAfterTaxName={ showRateAfterTaxName }
currency={ totalsCurrency }
values={ cartTotals }
/>
<TotalsWrapper className={ className }>
<TotalsTaxes
showRateAfterTaxName={ showRateAfterTaxName }
currency={ totalsCurrency }
values={ cartTotals }
/>
</TotalsWrapper>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
*/
import { OrderSummary } from '@woocommerce/base-components/cart-checkout';
import { useStoreCart } from '@woocommerce/base-context/hooks';
import { TotalsWrapper } from '@woocommerce/blocks-checkout';

const Block = ( { className }: { className: string } ): JSX.Element => {
const { cartItems } = useStoreCart();

return (
<OrderSummary
className={ `${ className } wc-block-components-totals-wrapper` }
cartItems={ cartItems }
/>
<TotalsWrapper className={ className }>
<OrderSummary cartItems={ cartItems } />
</TotalsWrapper>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { TotalsCoupon } from '@woocommerce/base-components/cart-checkout';
import { useStoreCartCoupons } from '@woocommerce/base-context/hooks';
import { getSetting } from '@woocommerce/settings';
import { TotalsWrapper } from '@woocommerce/blocks-checkout';

const Block = ( {
className = '',
Expand All @@ -19,11 +20,12 @@ const Block = ( {
}

return (
<TotalsCoupon
className={ `${ className } wc-block-components-totals-wrapper` }
onSubmit={ applyCoupon }
isLoading={ isApplyingCoupon }
/>
<TotalsWrapper className={ className }>
<TotalsCoupon
onSubmit={ applyCoupon }
isLoading={ isApplyingCoupon }
/>
</TotalsWrapper>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
useStoreCartCoupons,
useStoreCart,
} from '@woocommerce/base-context/hooks';
import { ExperimentalDiscountsMeta } from '@woocommerce/blocks-checkout';
import {
ExperimentalDiscountsMeta,
TotalsWrapper,
} from '@woocommerce/blocks-checkout';

const DiscountSlotFill = (): JSX.Element => {
// Prepare props to pass to the ExperimentalOrderMeta slot fill. We need to pluck out receiveCart.
Expand All @@ -24,20 +27,20 @@ const DiscountSlotFill = (): JSX.Element => {

const Block = ( { className = '' }: { className?: string } ): JSX.Element => {
const { cartTotals, cartCoupons } = useStoreCart();

const { removeCoupon, isRemovingCoupon } = useStoreCartCoupons();
const totalsCurrency = getCurrencyFromPriceResponse( cartTotals );

return (
<>
<TotalsDiscount
className={ `${ className } wc-block-components-totals-wrapper` }
cartCoupons={ cartCoupons }
currency={ totalsCurrency }
isRemovingCoupon={ isRemovingCoupon }
removeCoupon={ removeCoupon }
values={ cartTotals }
/>
<TotalsWrapper className={ className }>
<TotalsDiscount
cartCoupons={ cartCoupons }
currency={ totalsCurrency }
isRemovingCoupon={ isRemovingCoupon }
removeCoupon={ removeCoupon }
values={ cartTotals }
/>
</TotalsWrapper>
<DiscountSlotFill />
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { TotalsFees } from '@woocommerce/blocks-checkout';
import { TotalsFees, TotalsWrapper } from '@woocommerce/blocks-checkout';
import { getCurrencyFromPriceResponse } from '@woocommerce/price-format';
import { useStoreCart } from '@woocommerce/base-context/hooks';

Expand All @@ -10,11 +10,9 @@ const Block = ( { className = '' }: { className?: string } ): JSX.Element => {
const totalsCurrency = getCurrencyFromPriceResponse( cartTotals );

return (
<TotalsFees
className={ `${ className } wc-block-components-totals-wrapper` }
currency={ totalsCurrency }
cartFees={ cartFees }
/>
<TotalsWrapper className={ className }>
<TotalsFees currency={ totalsCurrency } cartFees={ cartFees } />
</TotalsWrapper>
);
};

Expand Down
Loading

0 comments on commit 506eda5

Please sign in to comment.