From 088bd914b8567ebafc4742ae776a58f8fe093f4d Mon Sep 17 00:00:00 2001 From: Tung Du Date: Fri, 29 Oct 2021 13:58:43 +0700 Subject: [PATCH 01/14] initial color support --- .../blocks/cart-checkout/mini-cart/edit.tsx | 2 +- .../blocks/cart-checkout/mini-cart/index.tsx | 3 ++ .../blocks/cart-checkout/mini-cart/style.scss | 1 + src/BlockTypes/MiniCart.php | 30 ++++++++++++++++--- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/assets/js/blocks/cart-checkout/mini-cart/edit.tsx b/assets/js/blocks/cart-checkout/mini-cart/edit.tsx index eeaffcf8866..a330e2684bd 100644 --- a/assets/js/blocks/cart-checkout/mini-cart/edit.tsx +++ b/assets/js/blocks/cart-checkout/mini-cart/edit.tsx @@ -13,7 +13,7 @@ import QuantityBadge from './quantity-badge'; const MiniCartBlock = (): ReactElement => { const blockProps = useBlockProps( { - className: 'wc-block-mini-cart', + className: 'wc-block-mini-cart wp-block-woocommerce-mini-cart', } ); const productCount = 0; diff --git a/assets/js/blocks/cart-checkout/mini-cart/index.tsx b/assets/js/blocks/cart-checkout/mini-cart/index.tsx index b07203f29f0..840a7dd6395 100644 --- a/assets/js/blocks/cart-checkout/mini-cart/index.tsx +++ b/assets/js/blocks/cart-checkout/mini-cart/index.tsx @@ -26,6 +26,9 @@ const settings = { supports: { html: false, multiple: false, + color: { + background: false, + }, }, example: { attributes: { diff --git a/assets/js/blocks/cart-checkout/mini-cart/style.scss b/assets/js/blocks/cart-checkout/mini-cart/style.scss index 1bcb9c01273..3b63ecaaed7 100644 --- a/assets/js/blocks/cart-checkout/mini-cart/style.scss +++ b/assets/js/blocks/cart-checkout/mini-cart/style.scss @@ -7,6 +7,7 @@ align-items: center; background: transparent; border: none; + color: inherit; display: flex; font-weight: 400; padding: em($gap-small) em($gap-smaller); diff --git a/src/BlockTypes/MiniCart.php b/src/BlockTypes/MiniCart.php index a875d64c885..204c90512d0 100644 --- a/src/BlockTypes/MiniCart.php +++ b/src/BlockTypes/MiniCart.php @@ -161,6 +161,11 @@ protected function get_script_from_handle( $handle ) { */ protected function append_script_and_deps_src( $script ) { $wp_scripts = wp_scripts(); + + if ( ! $script ) { + return; + } + // This script and its dependencies have already been appended. if ( array_key_exists( $script->handle, $this->scripts_to_lazy_load ) ) { return; @@ -195,15 +200,17 @@ protected function append_script_and_deps_src( $script ) { * @return string Rendered block type output. */ protected function render( $attributes, $content ) { - return $content . $this->get_markup(); + return $content . $this->get_markup( $attributes ); } /** * Render the markup for the Mini Cart block. * + * @param array $attributes Block attributes. + * * @return string The HTML markup. */ - protected function get_markup() { + protected function get_markup( $attributes ) { if ( is_admin() || WC()->is_rest_api_request() ) { // In the editor we will display the placeholder, so no need to load // real cart data and to print the markup. @@ -219,6 +226,21 @@ protected function get_markup() { $cart_contents_total += $cart->get_subtotal_tax(); } + $classes = 'wc-block-mini-cart wp-block-woocommerce-mini-cart'; + + if ( ! empty( $attributes['textColor'] ) ) { + $classes .= sprintf( + ' has-%s-color', + esc_attr( $attributes['textColor'] ) + ); + } + + if ( ! empty( $attributes['style']['color']['text'] ) ) { + $style = 'color: ' . esc_attr( $attributes['style']['color']['text'] ); + } else { + $style = ''; + } + $aria_label = sprintf( /* translators: %1$d is the number of products in the cart. %2$s is the cart total */ _n( @@ -259,12 +281,12 @@ protected function get_markup() { '; if ( is_cart() || is_checkout() ) { - return '
+ return '
'; } - return '
+ return '