From 63184d1ac9e848548e71c0fa09ff2af7f22c114a Mon Sep 17 00:00:00 2001 From: Daniel Guerra Date: Mon, 13 Jan 2025 13:03:51 -0600 Subject: [PATCH 01/16] Show Express Checkout button previews in editor when the elements do not load --- .../images/cards/google-pay-preview-dark.svg | 1 + .../images/cards/google-pay-preview-light.svg | 1 + .../express-checkout-button-preview.js | 61 +++++++++++++++++ .../components/express-checkout-component.js | 67 ++++++++++++++----- .../blocks/express-checkout-element.scss | 22 ++++++ 5 files changed, 134 insertions(+), 18 deletions(-) create mode 100644 assets/images/cards/google-pay-preview-dark.svg create mode 100644 assets/images/cards/google-pay-preview-light.svg create mode 100644 client/tokenized-express-checkout/blocks/components/express-checkout-button-preview.js diff --git a/assets/images/cards/google-pay-preview-dark.svg b/assets/images/cards/google-pay-preview-dark.svg new file mode 100644 index 00000000000..b41f9203c0e --- /dev/null +++ b/assets/images/cards/google-pay-preview-dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/images/cards/google-pay-preview-light.svg b/assets/images/cards/google-pay-preview-light.svg new file mode 100644 index 00000000000..758d7c66103 --- /dev/null +++ b/assets/images/cards/google-pay-preview-light.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/client/tokenized-express-checkout/blocks/components/express-checkout-button-preview.js b/client/tokenized-express-checkout/blocks/components/express-checkout-button-preview.js new file mode 100644 index 00000000000..fb7289dd8f1 --- /dev/null +++ b/client/tokenized-express-checkout/blocks/components/express-checkout-button-preview.js @@ -0,0 +1,61 @@ +/** + * External dependencies + */ +import { useMemo } from 'react'; + +/** + * Internal dependencies + */ +import GooglePayAssetDark from 'assets/images/cards/google-pay-preview-dark.svg?asset'; +import GooglePayAssetLight from 'assets/images/cards/google-pay-preview-light.svg?asset'; +import { getExpressCheckoutButtonAppearance } from 'wcpay/express-checkout/utils'; + +const ExpressCheckoutButtonPreviewComponent = ( { + expressPaymentMethod, + options, + buttonAttributes, +} ) => { + const appearance = useMemo( + () => getExpressCheckoutButtonAppearance( buttonAttributes ), + [ buttonAttributes ] + ); + + const buttonStyle = { + height: `${ options.buttonHeight }px`, + borderRadius: appearance.variables.borderRadius, + }; + + const theme = options.buttonTheme[ expressPaymentMethod ]; + + if ( expressPaymentMethod === 'applePay' ) { + buttonStyle.WebkitAppearance = '-apple-pay-button'; + if ( theme === 'black' ) { + buttonStyle.ApplePayButtonStyle = 'black'; + } else if ( theme === 'outline' ) { + buttonStyle.ApplePayButtonStyle = 'white-outline'; + } else { + buttonStyle.ApplePayButtonStyle = 'white'; + } + } + + if ( expressPaymentMethod === 'googlePay' ) { + if ( theme === 'black' ) { + buttonStyle.backgroundColor = 'black'; + buttonStyle.backgroundImage = `url(${ GooglePayAssetDark })`; + } else { + buttonStyle.backgroundColor = 'white'; + buttonStyle.backgroundImage = `url(${ GooglePayAssetLight })`; + } + } + + return ( +