mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 10:55:00 +08:00
🚧 Migrate the addButton logic
This commit is contained in:
parent
a4b3f2a079
commit
e0f0ec973b
1 changed files with 25 additions and 37 deletions
|
@ -233,17 +233,6 @@ class ApplePayButton extends PaymentButton {
|
|||
|
||||
super.init();
|
||||
this.checkEligibility();
|
||||
|
||||
const button = this.addButton();
|
||||
|
||||
if ( ! button ) {
|
||||
return;
|
||||
}
|
||||
|
||||
button.addEventListener( 'click', ( evt ) => {
|
||||
evt.preventDefault();
|
||||
this.onButtonClick();
|
||||
} );
|
||||
}
|
||||
|
||||
reinit() {
|
||||
|
@ -310,40 +299,39 @@ class ApplePayButton extends PaymentButton {
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds an Apple Pay purchase button.
|
||||
*
|
||||
* @return {HTMLElement|null} The newly created `<apple-pay-button>` element. Null on failure.
|
||||
* Applies CSS classes and inline styling to the payment button wrapper.
|
||||
*/
|
||||
addButton() {
|
||||
this.log( 'addButton' );
|
||||
applyWrapperStyles() {
|
||||
super.applyWrapperStyles();
|
||||
|
||||
const wrapper = this.wrapperElement;
|
||||
const style = this.buttonStyle;
|
||||
const id = 'apple-' + this.wrapperId;
|
||||
const { height } = this.style;
|
||||
|
||||
if ( ! wrapper ) {
|
||||
return null;
|
||||
}
|
||||
if ( height ) {
|
||||
const wrapper = this.wrapperElement;
|
||||
|
||||
const ppcpStyle = this.ppcpStyle;
|
||||
|
||||
wrapper.innerHTML = `<apple-pay-button id='${ id }' buttonstyle='${ style.color }' type='${ style.type }' locale='${ style.lang }' />`;
|
||||
wrapper.classList.remove( 'ppcp-button-rect', 'ppcp-button-pill' );
|
||||
wrapper.classList.add(
|
||||
`ppcp-button-${ ppcpStyle.shape }`,
|
||||
'ppcp-button-apm',
|
||||
'ppcp-button-applepay'
|
||||
);
|
||||
|
||||
if ( ppcpStyle.height ) {
|
||||
wrapper.style.setProperty(
|
||||
'--apple-pay-button-height',
|
||||
`${ ppcpStyle.height }px`
|
||||
`${ height }px`
|
||||
);
|
||||
wrapper.style.height = `${ ppcpStyle.height }px`;
|
||||
}
|
||||
|
||||
return wrapper.querySelector( 'apple-pay-button' );
|
||||
wrapper.style.height = `${ height }px`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the payment button and calls `this.insertButton()` to make the button visible in the
|
||||
* correct wrapper.
|
||||
*/
|
||||
addButton() {
|
||||
const { color, type, language } = this.style;
|
||||
|
||||
const button = document.createElement( 'apple-pay-button' );
|
||||
button.id = 'apple-' + this.wrapperId;
|
||||
button.setAttribute( 'buttonstyle', color );
|
||||
button.setAttribute( 'type', type );
|
||||
button.setAttribute( 'locale', language );
|
||||
|
||||
this.insertButton( button );
|
||||
}
|
||||
|
||||
//------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue