Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Skeleton loading component to the PMME element on the PDP #9166

Merged
merged 12 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/9126-add-pmme-pdp-skeleton-loader
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: add

Adds skeleton loading element for BNPL payment messaging element on product details page.
25 changes: 17 additions & 8 deletions client/product-details/bnpl-site-messaging/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,26 @@ export const initializeBnplSiteMessaging = async () => {
}

// Set the `--wc-bnpl-margin-bottom` CSS variable to the computed bottom margin of the price element.
document
.getElementById( 'payment-method-message' )
.style.setProperty( '--wc-bnpl-margin-bottom', bottomMargin );
const paymentMessageContainer = document.getElementById(
'payment-method-message'
);
paymentMessageContainer.style.setProperty(
'--wc-bnpl-margin-bottom',
bottomMargin
);

// When the payment message element is ready, add the `ready` class so the necessary CSS rules are applied.
paymentMessageElement.on( 'ready', () => {
document
.getElementById( 'payment-method-message' )
.classList.add( 'ready' );
let paymentMessageLoading;
if ( ! isCart ) {
paymentMessageLoading = document.createElement( 'div' );
paymentMessageLoading.classList.add( 'pmme-loading' );
paymentMessageContainer.prepend( paymentMessageLoading );
}

paymentMessageElement.on( 'ready', () => {
// On the cart page, get the height of the PMME after it's rendered and store it in a CSS variable. This helps
// prevent layout shifts when the PMME is loaded asynchronously upon cart total update.
if ( isCart ) {
paymentMessageContainer.classList.add( 'ready' );
// An element that won't be removed with the cart total update.
const cartCollaterals = document.querySelector(
'.cart-collaterals'
Expand Down Expand Up @@ -200,6 +207,8 @@ export const initializeBnplSiteMessaging = async () => {

pmme.style.setProperty( '--wc-bnpl-margin-bottom', '-4px' );
}, 2000 );
} else {
paymentMessageLoading.remove();
}
} );
}
Expand Down
27 changes: 16 additions & 11 deletions client/product-details/bnpl-site-messaging/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@
--wc-bnpl-margin-bottom: 0;
}

// Only apply the adjusted margins on the bnpl element when it immediately follows .price or .wp-block-woocommerce-product-price and the `ready` class has been added.
.price,
.wp-block-woocommerce-product-price {
&:has( + #payment-method-message.ready ) {
margin-bottom: 0;
}
.pmme-loading {
animation: pmme-loading 1s linear infinite alternate;
background: #afafaf;
}

+ #payment-method-message.ready {
margin-top: 0.5rem;
margin-bottom: var( --wc-bnpl-margin-bottom );
.summary,
.wp-block-woocommerce-product-price + {
#payment-method-message {
height: 4em;
position: relative;

.pmme-loading {
position: absolute;
width: 100%;
max-width: 20em;
height: 100%;
}
}
}

Expand All @@ -35,8 +42,6 @@
}

.pmme-loading {
animation: pmme-loading 1s linear infinite alternate;
background: #afafaf;
height: var( --wc-bnpl-container-height );
margin: -4px 1em var( --wc-bnpl-loader-margin ) 1em;
}
Expand Down
Loading