mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Refactor separate button style determination
This commit is contained in:
parent
e3b3d43d67
commit
240f430393
2 changed files with 22 additions and 10 deletions
20
modules/ppcp-button/resources/js/modules/Helper/Style.js
Normal file
20
modules/ppcp-button/resources/js/modules/Helper/Style.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
export const normalizeStyleForFundingSource = (style, fundingSource) => {
|
||||
const commonProps = {};
|
||||
['shape', 'height'].forEach(prop => {
|
||||
if (style[prop]) {
|
||||
commonProps[prop] = style[prop];
|
||||
}
|
||||
});
|
||||
|
||||
switch (fundingSource) {
|
||||
case 'paypal':
|
||||
return style;
|
||||
case 'paylater':
|
||||
return {
|
||||
color: style.color,
|
||||
...commonProps
|
||||
};
|
||||
default:
|
||||
return commonProps;
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ import merge from "deepmerge";
|
|||
import {loadScript} from "@paypal/paypal-js";
|
||||
import {keysToCamelCase} from "../Helper/Utils";
|
||||
import widgetBuilder from "./WidgetBuilder";
|
||||
import {normalizeStyleForFundingSource} from "../Helper/Style";
|
||||
|
||||
class Renderer {
|
||||
constructor(creditCardRenderer, defaultSettings, onSmartButtonClick, onSmartButtonsInit) {
|
||||
|
@ -36,16 +37,7 @@ class Renderer {
|
|||
} else {
|
||||
// render each button separately
|
||||
for (const fundingSource of paypal.getFundingSources().filter(s => !(s in enabledSeparateGateways))) {
|
||||
let style = settings.button.style;
|
||||
if (fundingSource !== 'paypal') {
|
||||
style = {
|
||||
shape: style.shape,
|
||||
color: style.color,
|
||||
};
|
||||
if (fundingSource !== 'paylater') {
|
||||
delete style.color;
|
||||
}
|
||||
}
|
||||
const style = normalizeStyleForFundingSource(settings.button.style, fundingSource);
|
||||
|
||||
this.renderButtons(
|
||||
settings.button.wrapper,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue