From 56551347a6d7f717783867f1c48e8a7da5fb2a60 Mon Sep 17 00:00:00 2001 From: Seghir Nadir Date: Tue, 21 Sep 2021 11:18:27 +0100 Subject: [PATCH] Setup basic column blocks for Cart i2 (https://github.com/woocommerce/woocommerce-blocks/pull/4780) * setup basic column blocks * fix classnames * fix broken block.json in cart items block * move hacks back * dubplciate columns --- .../cart-i2/columns/columns-block.tsx | 15 ++ .../cart-checkout/cart-i2/columns/index.ts | 1 + .../cart-i2/{edit.js => edit.tsx} | 49 ++++-- .../cart-checkout/cart-i2/editor-utils.ts | 19 +++ .../blocks/cart-checkout/cart-i2/editor.scss | 47 ++++++ .../js/blocks/cart-checkout/cart-i2/hacks.ts | 151 ++++++++++++++++++ .../js/blocks/cart-checkout/cart-i2/index.js | 2 +- .../inner-blocks/cart-items-block/block.json | 25 +++ .../inner-blocks/cart-items-block/edit.tsx | 41 +++++ .../cart-items-block/frontend.tsx | 14 ++ .../inner-blocks/cart-items-block/index.tsx | 20 +++ .../inner-blocks/cart-totals-block/block.json | 27 ++++ .../inner-blocks/cart-totals-block/edit.tsx | 47 ++++++ .../cart-totals-block/frontend.tsx | 19 +++ .../inner-blocks/cart-totals-block/index.tsx | 20 +++ .../inner-blocks/cart-totals-block/style.scss | 8 + .../cart-i2/inner-blocks/index.tsx | 5 + .../cart-i2/use-forced-layout.ts | 63 ++++++++ .../checkout/blocks-registry/types.ts | 3 + 19 files changed, 559 insertions(+), 17 deletions(-) create mode 100644 plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/columns/columns-block.tsx create mode 100644 plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/columns/index.ts rename plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/{edit.js => edit.tsx} (85%) create mode 100644 plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/editor-utils.ts create mode 100644 plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/hacks.ts create mode 100644 plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-items-block/block.json create mode 100644 plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-items-block/edit.tsx create mode 100644 plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-items-block/frontend.tsx create mode 100644 plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-items-block/index.tsx create mode 100644 plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-totals-block/block.json create mode 100644 plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-totals-block/edit.tsx create mode 100644 plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-totals-block/frontend.tsx create mode 100644 plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-totals-block/index.tsx create mode 100644 plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-totals-block/style.scss create mode 100644 plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/index.tsx create mode 100644 plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/use-forced-layout.ts diff --git a/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/columns/columns-block.tsx b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/columns/columns-block.tsx new file mode 100644 index 00000000000..d0ea19ba6aa --- /dev/null +++ b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/columns/columns-block.tsx @@ -0,0 +1,15 @@ +/** + * External dependencies + */ +import { useBlockProps } from '@wordpress/block-editor'; + +export const Columns = ( { + children, + ...props +}: { + children?: React.ReactNode; +} ): JSX.Element => { + const blockProps = useBlockProps( props ); + + return
{ children }
; +}; diff --git a/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/columns/index.ts b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/columns/index.ts new file mode 100644 index 00000000000..805a5f6d232 --- /dev/null +++ b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/columns/index.ts @@ -0,0 +1 @@ +export * from './columns-block'; diff --git a/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/edit.js b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/edit.tsx similarity index 85% rename from plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/edit.js rename to plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/edit.tsx index 8a64b980bbd..5cf95a358b1 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/edit.js +++ b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout/cart-i2/edit.tsx @@ -1,16 +1,12 @@ +/* tslint:disable */ /** * External dependencies */ import classnames from 'classnames'; import { __ } from '@wordpress/i18n'; import { CartCheckoutFeedbackPrompt } from '@woocommerce/editor-components/feedback-prompt'; -import { InspectorControls } from '@wordpress/block-editor'; -import { - Disabled, - PanelBody, - ToggleControl, - Notice, -} from '@wordpress/components'; +import { InnerBlocks, InspectorControls } from '@wordpress/block-editor'; +import { PanelBody, ToggleControl, Notice } from '@wordpress/components'; import PropTypes from 'prop-types'; import { CartCheckoutCompatibilityNotice } from '@woocommerce/editor-components/compatibility-notices'; import ViewSwitcher from '@woocommerce/editor-components/view-switcher'; @@ -25,13 +21,13 @@ import { import { createInterpolateElement, useRef } from '@wordpress/element'; import { getAdminLink, getSetting } from '@woocommerce/settings'; import { previewCart } from '@woocommerce/resource-previews'; +import { SidebarLayout } from '@woocommerce/base-components/sidebar-layout'; /** * Internal dependencies */ -import Block from './block.js'; -import EmptyCartEdit from './empty-cart-edit'; import './editor.scss'; +import { Columns } from './columns'; const BlockSettings = ( { attributes, setAttributes } ) => { const { @@ -162,6 +158,10 @@ const BlockSettings = ( { attributes, setAttributes } ) => { ); }; +const ALLOWED_BLOCKS: string[] = [ + 'woocommerce/cart-items-block', + 'woocommerce/cart-totals-block', +]; /** * Component to handle edit mode of "Cart Block". * @@ -176,6 +176,13 @@ const BlockSettings = ( { attributes, setAttributes } ) => { * @param {function(any):any} props.setAttributes Setter for attributes. */ const CartEditor = ( { className, attributes, setAttributes } ) => { + const cartClassName = classnames( 'wc-block-cart', { + 'has-dark-controls': attributes.hasDarkControls, + } ); + const defaultInnerBlocksTemplate = [ + [ 'woocommerce/cart-items-block', {}, [] ], + [ 'woocommerce/cart-totals-block', {}, [] ], + ]; return (
{ attributes={ attributes } setAttributes={ setAttributes } /> - - - - - + + + + + + + -