* setup basic column blocks

* fix classnames

* move hacks back

* dubplciate columns

* add express payment block

* adjust styles

* fix locking after rebase
This commit is contained in:
Seghir Nadir 2021-09-21 13:38:56 +01:00 committed by GitHub
parent f2af87226c
commit a459360dc1
11 changed files with 200 additions and 1 deletions

View File

@ -144,6 +144,7 @@ const CartEditor = ( { className, attributes, setAttributes } ) => {
{},
[
[ 'woocommerce/cart-order-summary-block', {}, [] ],
[ 'woocommerce/cart-express-payment-block', {}, [] ],
[ 'woocommerce/proceed-to-checkout-block', {}, [] ],
],
],

View File

@ -0,0 +1,26 @@
{
"name": "woocommerce/cart-express-payment-block",
"version": "1.0.0",
"title": "Express Checkout",
"description": "Provide an express payment option for your customers.",
"category": "woocommerce",
"supports": {
"align": false,
"html": false,
"multiple": false,
"reusable": false,
"inserter": false
},
"attributes": {
"lock": {
"type": "object",
"default": {
"remove": true,
"move": true
}
}
},
"parent": [ "woocommerce/cart-totals-block" ],
"textdomain": "woo-gutenberg-products-block",
"apiVersion": 2
}

View File

@ -0,0 +1,25 @@
/**
* External dependencies
*/
import { useStoreCart } from '@woocommerce/base-context/hooks';
/**
* Internal dependencies
*/
import { CartExpressPayment } from '../../../payment-methods';
const Block = (): JSX.Element | null => {
const { cartNeedsPayment } = useStoreCart();
if ( ! cartNeedsPayment ) {
return null;
}
return (
<div className="wc-block-cart__payment-options">
<CartExpressPayment />
</div>
);
};
export default Block;

View File

@ -0,0 +1,87 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { useBlockProps } from '@wordpress/block-editor';
import { Placeholder, Button } from 'wordpress-components';
import { useExpressPaymentMethods } from '@woocommerce/base-context/hooks';
import { Icon, card } from '@woocommerce/icons';
import { ADMIN_URL } from '@woocommerce/settings';
import classnames from 'classnames';
/**
* Internal dependencies
*/
import Block from './block';
import './editor.scss';
import { useBlockPropsWithLocking } from '../../hacks';
/**
* Renders a placeholder in the editor.
*/
const NoExpressPaymentMethodsPlaceholder = () => {
return (
<Placeholder
icon={ <Icon srcElement={ card } /> }
label={ __( 'Express Checkout', 'woo-gutenberg-products-block' ) }
className="wp-block-woocommerce-checkout-express-payment-block-placeholder"
>
<span className="wp-block-woocommerce-checkout-express-payment-block-placeholder__description">
{ __(
"Your store doesn't have any Payment Methods that support the Express Checkout Block. If they are added, they will be shown here.",
'woo-gutenberg-products-block'
) }
</span>
<Button
isPrimary
href={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=checkout` }
target="_blank"
rel="noopener noreferrer"
className="wp-block-woocommerce-checkout-express-payment-block-placeholder__button"
>
{ __(
'Configure Payment Methods',
'woo-gutenberg-products-block'
) }
</Button>
</Placeholder>
);
};
export const Edit = ( {
attributes,
}: {
attributes: {
lock: {
move: boolean;
remove: boolean;
};
};
} ): JSX.Element | null => {
const { paymentMethods, isInitialized } = useExpressPaymentMethods();
const hasExpressPaymentMethods = Object.keys( paymentMethods ).length > 0;
const blockProps = useBlockPropsWithLocking( {
className: classnames( {
'wp-block-woocommerce-cart-express-payment-block--has-express-payment-methods': hasExpressPaymentMethods,
} ),
attributes,
} );
if ( ! isInitialized ) {
return null;
}
return (
<div { ...blockProps }>
{ hasExpressPaymentMethods ? (
<Block />
) : (
<NoExpressPaymentMethodsPlaceholder />
) }
</div>
);
};
export const Save = (): JSX.Element => {
return <div { ...useBlockProps.save() } />;
};

View File

@ -0,0 +1,29 @@
// Adjust padding and margins in the editor to improve selected block outlines.
.wp-block-woocommerce-cart-express-payment-block {
margin: 14px 0 28px;
.components-placeholder__label svg {
font-size: 1em;
}
.wc-block-components-express-payment-continue-rule--checkout {
margin-bottom: 0;
}
&.wp-block-woocommerce-cart-express-payment-block--has-express-payment-methods {
padding: 14px 0;
margin: -14px 0 14px 0 !important;
position: relative;
}
}
.wp-block-woocommerce-checkout-express-payment-block-placeholder {
* {
pointer-events: all; // Overrides parent disabled component in editor context
}
.wp-block-woocommerce-checkout-express-payment-block-placeholder__description {
display: block;
margin: 0 0 1em;
}
}

View File

@ -0,0 +1,20 @@
/**
* External dependencies
*/
import { Icon, card } from '@woocommerce/icons';
import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
/**
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';
registerFeaturePluginBlockType( metadata, {
icon: {
src: <Icon srcElement={ card } />,
foreground: '#874FB9',
},
edit: Edit,
save: Save,
} );

View File

@ -13,6 +13,7 @@
},
"attributes": {
"lock": {
"type": "object",
"default": {
"remove": true,
"move": true

View File

@ -13,6 +13,7 @@
},
"attributes": {
"lock": {
"type": "object",
"default": {
"remove": true,
"move": true

View File

@ -13,8 +13,10 @@
},
"attributes": {
"lock": {
"type": "object",
"default": {
"remove": true
"remove": true,
"move": true
}
}
},

View File

@ -19,6 +19,12 @@
"text": {
"type": "string",
"required": false
},
"lock": {
"type": "object",
"default": {
"remove": true
}
}
},
"parent": [ "woocommerce/cart-i2" ],

View File

@ -5,4 +5,5 @@ import './cart-items-block';
import './cart-totals-block';
import './cart-line-items-block';
import './cart-order-summary-block';
import './cart-express-payment-block';
import './proceed-to-checkout-block';