From ef0de13568bea7526c82a2396e49517f17c7f15e Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Mon, 9 Dec 2024 12:10:10 +0100 Subject: [PATCH 1/6] ECE only (w/o WooPay) loads smoothly now --- client/express-checkout/button-ui.js | 21 +++++++++++++--- .../express-checkout-element.scss | 24 +++++++++++++++++++ client/express-checkout/index.js | 2 +- ...lass-wc-payments-woopay-button-handler.php | 2 +- ...xpress-checkout-button-display-handler.php | 7 +++--- ...yments-express-checkout-button-handler.php | 2 +- 6 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 client/express-checkout/express-checkout-element.scss diff --git a/client/express-checkout/button-ui.js b/client/express-checkout/button-ui.js index 9e29ea6b7b5..5e2cf9e9d7f 100644 --- a/client/express-checkout/button-ui.js +++ b/client/express-checkout/button-ui.js @@ -32,17 +32,32 @@ const expressCheckoutButtonUi = { renderButton: ( eceButton ) => { if ( get$Container()?.length ) { - expressCheckoutButtonUi.showContainer(); eceButton.mount( expressCheckoutElementId ); } }, hideContainer: () => { - get$Container().hide(); + const wrapper = document.querySelector('.wcpay-express-checkout-wrapper'); + + if (wrapper) { + wrapper.style.display = 'none'; + wrapper.classList.remove('is-loaded'); + wrapper.setAttribute('aria-hidden', 'true'); + } }, showContainer: () => { - get$Container().show(); + const wrapper = document.querySelector('.wcpay-express-checkout-wrapper'); + + if (wrapper) { + wrapper.style.display = 'block'; + // Force a reflow to ensure the transition works + wrapper.offsetHeight; + wrapper.classList.add('is-loaded'); + wrapper.setAttribute('aria-hidden', 'false'); + expressCheckoutButtonUi.getButtonSeparator().show(); + } + }, }; diff --git a/client/express-checkout/express-checkout-element.scss b/client/express-checkout/express-checkout-element.scss new file mode 100644 index 00000000000..b38d9af71e8 --- /dev/null +++ b/client/express-checkout/express-checkout-element.scss @@ -0,0 +1,24 @@ +.wcpay-express-checkout-wrapper { + opacity: 0; + max-height: 0; + overflow: hidden; + transition: + opacity 0.2s ease-in-out, + max-height 0.3s ease-out; // Slightly longer duration for height + + &.is-loaded { + opacity: 1; + max-height: 90px; // Adjust based on button (40px) + separator + margins + } + + // Style the express checkout element + .wcpay-express-checkout-element { + min-height: 40px; + } + + // Style the separator + .wcpay-express-checkout-button-separator { + margin: 1.5em 0; + text-align: center; + } +} \ No newline at end of file diff --git a/client/express-checkout/index.js b/client/express-checkout/index.js index 6f36a3e6b59..69aaeef4fad 100644 --- a/client/express-checkout/index.js +++ b/client/express-checkout/index.js @@ -6,6 +6,7 @@ import { debounce } from 'lodash'; * Internal dependencies */ import WCPayAPI from '../checkout/api'; +import './express-checkout-element.scss'; import '../checkout/express-checkout-buttons.scss'; import { getExpressCheckoutButtonAppearance, @@ -362,7 +363,6 @@ jQuery( ( $ ) => { ).filter( Boolean ).length ) { expressCheckoutButtonUi.showContainer(); - expressCheckoutButtonUi.getButtonSeparator().show(); } } ); diff --git a/includes/class-wc-payments-woopay-button-handler.php b/includes/class-wc-payments-woopay-button-handler.php index a42fe8046a4..7eeec73af7d 100644 --- a/includes/class-wc-payments-woopay-button-handler.php +++ b/includes/class-wc-payments-woopay-button-handler.php @@ -333,7 +333,7 @@ public function display_woopay_button_html() { $settings = $this->get_button_settings(); ?> -
express_checkout_helper->is_product() ); ?>> +
express_checkout_helper->is_product() ); ?>>