Provide means to update styling of a button

Before this, we needed to create a new button instance to display changes in button style. This allows updating an existing button instance
This commit is contained in:
Philipp Stracker 2024-08-08 17:53:59 +02:00
parent 3538a69402
commit 722289a545
No known key found for this signature in database
4 changed files with 69 additions and 38 deletions

View file

@ -185,8 +185,6 @@ class GooglepayButton extends PaymentButton {
this.allowedPaymentMethods = this.googlePayConfig.allowedPaymentMethods;
this.baseCardPaymentMethod = this.allowedPaymentMethods[ 0 ];
this.log( 'CONFIG', transactionInfo );
}
init() {
@ -231,10 +229,6 @@ class GooglepayButton extends PaymentButton {
}
reinit() {
if ( ! this.isInitialized ) {
return;
}
super.reinit();
this.init();
}

View file

@ -6,6 +6,13 @@ import GooglepayButton from './GooglepayButton';
* A single GooglePay preview button instance.
*/
export default class GooglePayPreviewButton extends PreviewButton {
/**
* Instance of the preview button.
*
* @type {?PaymentButton}
*/
#button = null;
constructor( args ) {
super( args );
@ -36,20 +43,23 @@ export default class GooglePayPreviewButton extends PreviewButton {
null
);
/* Intentionally using `new` keyword, instead of the `.createButton()` factory,
* as the factory is designed to only create a single button per context, while a single
* page can contain multiple instances of a preview button.
*/
const button = new GooglepayButton(
'preview',
null,
buttonConfig,
this.ppcpConfig,
contextHandler
);
if ( ! this.#button ) {
/* Intentionally using `new` keyword, instead of the `.createButton()` factory,
* as the factory is designed to only create a single button per context, while a single
* page can contain multiple instances of a preview button.
*/
this.#button = new GooglepayButton(
'preview',
null,
buttonConfig,
this.ppcpConfig,
contextHandler
);
}
button.configure( this.apiConfig, null );
button.init();
this.#button.configure( this.apiConfig, null );
this.#button.applyButtonStyles( buttonConfig, this.ppcpConfig );
this.#button.reinit();
}
/**