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

Commit

Permalink
Merge branch 'feature/checkout-i2' of https://github.com/woocommerce/…
Browse files Browse the repository at this point in the history
  • Loading branch information
senadir committed Jun 3, 2021
2 parents bdd2176 + 6d25213 commit c0251f7
Show file tree
Hide file tree
Showing 20 changed files with 167 additions and 73 deletions.
13 changes: 11 additions & 2 deletions assets/js/blocks/cart-checkout/checkout-i2/component-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ registerBlockComponent( {
blockName: 'woocommerce/checkout-order-summary-block',
component: lazy( () =>
import(
/* webpackChunkName: "checkout-blocks/order-summary" */ './inner-blocks/checkout-order-summary/block'
/* webpackChunkName: "checkout-blocks/order-summary" */ './inner-blocks/checkout-order-summary-block/block'
)
),
} );
Expand All @@ -103,7 +103,16 @@ registerBlockComponent( {
blockName: 'woocommerce/checkout-express-payment-block',
component: lazy( () =>
import(
/* webpackChunkName: "checkout-blocks/express-payment" */ './inner-blocks/checkout-express-payment/block'
/* webpackChunkName: "checkout-blocks/express-payment" */ './inner-blocks/checkout-express-payment-block/block'
)
),
} );

registerBlockComponent( {
blockName: 'woocommerce/checkout-shipping-methods-block',
component: lazy( () =>
import(
/* webpackChunkName: "checkout-blocks/shipping-methods" */ './inner-blocks/checkout-shipping-methods-block/frontend'
)
),
} );
1 change: 1 addition & 0 deletions assets/js/blocks/cart-checkout/checkout-i2/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
/**
* Internal dependencies
*/
import './style.scss';
import Block from './block';
import blockAttributes from './attributes';
import { renderParentBlock } from './render-parent-block';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { InnerBlockTemplate } from '../../types';
const ALLOWED_BLOCKS = [
'woocommerce/checkout-express-payment-block',
'woocommerce/checkout-shipping-address-block',
'woocommerce/checkout-shipping-methods',
'woocommerce/checkout-shipping-methods-block',
'woocommerce/checkout-contact-information-block',
'woocommerce/checkout-billing-address-block',
'woocommerce/checkout-payment-block',
Expand All @@ -26,7 +26,7 @@ const TEMPLATE: InnerBlockTemplate[] = [
[ 'woocommerce/checkout-contact-information-block', {}, [] ],
[ 'woocommerce/checkout-shipping-address-block', {}, [] ],
[ 'woocommerce/checkout-billing-address-block', {}, [] ],
[ 'woocommerce/checkout-shipping-methods', {}, [] ],
[ 'woocommerce/checkout-shipping-methods-block', {}, [] ],
[ 'woocommerce/checkout-payment-block', {}, [] ],
[ 'woocommerce/checkout-order-note-block', {}, [] ],
[ 'woocommerce/checkout-actions-block', {}, [] ],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* External dependencies
*/
import withFilteredAttributes from '@woocommerce/base-hocs/with-filtered-attributes';
import { FormStep } from '@woocommerce/base-components/cart-checkout';
import { useCheckoutContext } from '@woocommerce/base-context';
import { useCheckoutAddress } from '@woocommerce/base-context/hooks';

/**
* Internal dependencies
*/
import Block from './block';
import attributes from './attributes';

const FrontendBlock = ( {
title,
description,
showStepNumber,
}: {
title: string;
description: string;
requireCompanyField: boolean;
requirePhoneField: boolean;
showApartmentField: boolean;
showCompanyField: boolean;
showPhoneField: boolean;
showStepNumber: boolean;
} ) => {
const { isProcessing: checkoutIsProcessing } = useCheckoutContext();
const { showShippingFields } = useCheckoutAddress();

if ( ! showShippingFields ) {
return null;
}

return (
<FormStep
id="shipping-option"
disabled={ checkoutIsProcessing }
className="wc-block-checkout__shipping-option"
title={ title }
description={ description }
showStepNumber={ showStepNumber }
>
<Block />
</FormStep>
);
};

export default withFilteredAttributes( attributes )( FrontendBlock );
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
import { Edit, Save } from './edit';
import attributes from './attributes';

registerFeaturePluginBlockType( 'woocommerce/checkout-shipping-methods', {
registerFeaturePluginBlockType( 'woocommerce/checkout-shipping-methods-block', {
title: __( 'Shipping Methods', 'woo-gutenberg-products-block' ),
category: 'woocommerce',
description: __(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import './checkout-contact-information-block';
import './checkout-billing-address-block';
import './checkout-actions-block';
import './checkout-order-note-block';
import './checkout-order-summary';
import './checkout-order-summary-block';
import './checkout-payment-block';
import './checkout-express-payment';
import './checkout-shipping-methods';
import './checkout-express-payment-block';
import './checkout-shipping-methods-block';
97 changes: 97 additions & 0 deletions assets/js/blocks/cart-checkout/checkout-i2/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Loading skeleton.
.is-loading.wp-block-woocommerce-checkout-i2 {
.wp-block-woocommerce-checkout-totals-block,
.wp-block-woocommerce-checkout-fields-block {
> div {
@include placeholder();
margin: 0 0 1.5em 0;
display: none;
}

.wp-block-woocommerce-checkout-contact-information-block,
.wp-block-woocommerce-checkout-payment-block {
min-height: 10em;
display: block;
}
.wp-block-woocommerce-checkout-shipping-address-block {
min-height: 24em;
display: block;
}
.wp-block-woocommerce-checkout-actions-block {
width: 50%;
min-height: 4em;
margin-left: 50%;
display: block;
}
.wp-block-woocommerce-checkout-order-summary-block {
min-height: 47em;
display: block;
}
}

// @todo these styles replace the need for SidebarLayout styles. We define styles here so placeholder elements (loading state) for the checkout has the same sidebar type layout before JS loads.
&.wp-block-woocommerce-checkout-i2 {
display: flex;
flex-wrap: wrap;
margin: 0 auto $gap;
position: relative;

.wp-block-woocommerce-checkout-fields-block {
box-sizing: border-box;
margin: 0;
padding-right: percentage($gap-largest / 1060px); // ~1060px is the default width of the content area in Storefront.
width: 65%;
}
.wp-block-woocommerce-checkout-totals-block {
box-sizing: border-box;
margin: 0;
padding-left: percentage($gap-large / 1060px);
width: 35%;

.wc-block-components-panel > h2 {
@include font-size(regular);
@include reset-box();
@include reset-typography();
.wc-block-components-panel__button {
font-weight: 400;
}
}
}
}

.is-medium,
.is-small,
.is-mobile {
&.wp-block-woocommerce-checkout-i2 {
flex-direction: column;
margin: 0 auto $gap;

.wp-block-woocommerce-checkout-fields-block {
padding: 0;
width: 100%;
}
.wp-block-woocommerce-checkout-totals-block {
padding: 0;
width: 100%;
}
}
}

.is-large {
.wp-block-woocommerce-checkout-totals-block {
.wc-block-components-totals-item,
.wc-block-components-panel {
padding-left: $gap;
padding-right: $gap;
}
}
}

// For Twenty Twenty we need to increase specificity a bit more.
.theme-twentytwenty {
.wp-block-woocommerce-checkout-totals-block .wc-block-components-panel > h2 {
@include font-size(large);
@include reset-box();
}
}
}
66 changes: 1 addition & 65 deletions src/BlockTypes/CheckoutI2.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function render( $attributes, $content ) {
wp_dequeue_script( 'selectWoo' );
wp_dequeue_style( 'select2' );

return $this->inject_html_data_attributes( $content . $this->get_skeleton(), $attributes );
return $this->inject_html_data_attributes( $content, $attributes );
}

/**
Expand Down Expand Up @@ -236,70 +236,6 @@ protected function hydrate_from_api() {
remove_filter( 'woocommerce_store_api_disable_nonce_check', '__return_true' );
}

/**
* Render skeleton markup for the checkout block.
*/
protected function get_skeleton() {
return '
<div class="wc-block-skeleton wc-block-components-sidebar-layout wc-block-checkout wc-block-checkout--is-loading wc-block-checkout--skeleton hidden" aria-hidden="true">
<div class="wc-block-components-main wc-block-checkout__main">
<div class="wc-block-components-express-payment wc-block-components-express-payment--checkout"></div>
<div class="wc-block-components-express-payment-continue-rule wc-block-components-express-payment-continue-rule--checkout"><span></span></div>
<form class="wc-block-checkout__form">
<fieldset class="wc-block-checkout__contact-fields wc-block-components-checkout-step">
<div class="wc-block-components-checkout-step__heading">
<div class="wc-block-components-checkout-step__title"></div>
</div>
<div class="wc-block-components-checkout-step__container">
<div class="wc-block-components-checkout-step__content">
<span></span>
</div>
</div>
</fieldset>
<fieldset class="wc-block-checkout__contact-fields wc-block-components-checkout-step">
<div class="wc-block-components-checkout-step__heading">
<div class="wc-block-components-checkout-step__title"></div>
</div>
<div class="wc-block-components-checkout-step__container">
<div class="wc-block-components-checkout-step__content">
<span></span>
</div>
</div>
</fieldset>
<fieldset class="wc-block-checkout__contact-fields wc-block-components-checkout-step">
<div class="wc-block-components-checkout-step__heading">
<div class="wc-block-components-checkout-step__title"></div>
</div>
<div class="wc-block-components-checkout-step__container">
<div class="wc-block-components-checkout-step__content">
<span></span>
</div>
</div>
</fieldset>
<fieldset class="wc-block-checkout__contact-fields wc-block-components-checkout-step">
<div class="wc-block-components-checkout-step__heading">
<div class="wc-block-components-checkout-step__title"></div>
</div>
<div class="wc-block-components-checkout-step__container">
<div class="wc-block-components-checkout-step__content">
<span></span>
</div>
</div>
</fieldset>
</form>
</div>
<div class="wc-block-components-sidebar wc-block-checkout__sidebar">
<div class="components-card"></div>
</div>
<div class="wc-block-components-main wc-block-checkout__main-totals">
<div class="wc-block-checkout__actions">
<button class="components-button button wc-block-button wc-block-components-checkout-place-order-button">&nbsp;</button>
</div>
</div>
</div>
' . $this->get_skeleton_inline_script();
}

/**
* Callback for woocommerce_payment_methods_list_item filter to add token id
* to the generated list.
Expand Down
1 change: 1 addition & 0 deletions src/BlockTypesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ protected function get_atomic_blocks() {
'checkout-order-summary-block',
'checkout-payment-block',
'checkout-shipping-address-block',
'checkout-shipping-methods-block',
'checkout-express-payment-block',
'checkout-newsletter-block',
];
Expand Down

0 comments on commit c0251f7

Please sign in to comment.