@paypal/checkout-components 5.0.356 → 5.0.357
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/button.js +1 -1
- package/dist/test/button.js +1 -1
- package/package.json +1 -1
- package/src/constants/button.js +12 -0
- package/src/ui/buttons/config.js +69 -1
- package/src/ui/buttons/styles/responsive.js +153 -73
- package/src/ui/buttons/styles/styleUtils.js +209 -0
- package/src/ui/buttons/styles/styleUtils.test.js +876 -0
- package/src/ui/buttons/styles/responsive.test.js +0 -192
package/package.json
CHANGED
package/src/constants/button.js
CHANGED
|
@@ -38,6 +38,18 @@ export const BUTTON_SIZE = {
|
|
|
38
38
|
RESPONSIVE: ("responsive": "responsive"),
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
+
export const BUTTON_DISABLE_MAX_HEIGHT_SIZE = {
|
|
42
|
+
TINY: ("tiny": "tiny"),
|
|
43
|
+
SMALL: ("small": "small"),
|
|
44
|
+
MEDIUM_SMALL: ("mediumSmall": "mediumSmall"),
|
|
45
|
+
MEDIUM_BIG: ("mediumBig": "mediumBig"),
|
|
46
|
+
LARGE_SMALL: ("largeSmall": "largeSmall"),
|
|
47
|
+
LARGE_BIG: ("largeBig": "largeBig"),
|
|
48
|
+
XL: ("xl": "xl"),
|
|
49
|
+
XXL: ("xxl": "xxl"),
|
|
50
|
+
XXXL: ("xxxl": "xxxl"),
|
|
51
|
+
};
|
|
52
|
+
|
|
41
53
|
export const BUTTON_SHAPE = {
|
|
42
54
|
PILL: ("pill": "pill"),
|
|
43
55
|
RECT: ("rect": "rect"),
|
package/src/ui/buttons/config.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
/* eslint no-template-curly-in-string: off, max-lines: off */
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
BUTTON_SIZE,
|
|
6
|
+
BUTTON_DISABLE_MAX_HEIGHT_SIZE,
|
|
7
|
+
BUTTON_LAYOUT,
|
|
8
|
+
} from "../../constants";
|
|
5
9
|
|
|
6
10
|
export const MINIMUM_SIZE: {|
|
|
7
11
|
[$Values<typeof BUTTON_LAYOUT>]: $Values<typeof BUTTON_SIZE>,
|
|
@@ -33,6 +37,14 @@ type ButtonStyleMap = {
|
|
|
33
37
|
|},
|
|
34
38
|
};
|
|
35
39
|
|
|
40
|
+
type ButtonDisableMaxHeightStyleMap = {
|
|
41
|
+
[$Values<typeof BUTTON_DISABLE_MAX_HEIGHT_SIZE>]: {|
|
|
42
|
+
defaultHeight: number,
|
|
43
|
+
minHeight: number,
|
|
44
|
+
maxHeight: number,
|
|
45
|
+
|},
|
|
46
|
+
};
|
|
47
|
+
|
|
36
48
|
export const BUTTON_SIZE_STYLE: ButtonStyleMap = {
|
|
37
49
|
[BUTTON_SIZE.TINY]: {
|
|
38
50
|
defaultWidth: 75,
|
|
@@ -79,3 +91,59 @@ export const BUTTON_SIZE_STYLE: ButtonStyleMap = {
|
|
|
79
91
|
maxHeight: 55,
|
|
80
92
|
},
|
|
81
93
|
};
|
|
94
|
+
|
|
95
|
+
export const BUTTON_DISABLE_MAX_HEIGHT_STYLE: ButtonDisableMaxHeightStyleMap = {
|
|
96
|
+
[BUTTON_DISABLE_MAX_HEIGHT_SIZE.TINY]: {
|
|
97
|
+
defaultHeight: 25,
|
|
98
|
+
minHeight: 25,
|
|
99
|
+
maxHeight: 30,
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
[BUTTON_DISABLE_MAX_HEIGHT_SIZE.SMALL]: {
|
|
103
|
+
defaultHeight: 30,
|
|
104
|
+
minHeight: 30,
|
|
105
|
+
maxHeight: 35,
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
[BUTTON_DISABLE_MAX_HEIGHT_SIZE.MEDIUM_SMALL]: {
|
|
109
|
+
defaultHeight: 35,
|
|
110
|
+
minHeight: 35,
|
|
111
|
+
maxHeight: 40,
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
[BUTTON_DISABLE_MAX_HEIGHT_SIZE.MEDIUM_BIG]: {
|
|
115
|
+
defaultHeight: 40,
|
|
116
|
+
minHeight: 40,
|
|
117
|
+
maxHeight: 45,
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
[BUTTON_DISABLE_MAX_HEIGHT_SIZE.LARGE_SMALL]: {
|
|
121
|
+
defaultHeight: 45,
|
|
122
|
+
minHeight: 45,
|
|
123
|
+
maxHeight: 50,
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
[BUTTON_DISABLE_MAX_HEIGHT_SIZE.LARGE_BIG]: {
|
|
127
|
+
defaultHeight: 50,
|
|
128
|
+
minHeight: 50,
|
|
129
|
+
maxHeight: 55,
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
[BUTTON_DISABLE_MAX_HEIGHT_SIZE.XL]: {
|
|
133
|
+
defaultHeight: 55,
|
|
134
|
+
minHeight: 55,
|
|
135
|
+
maxHeight: 65,
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
[BUTTON_DISABLE_MAX_HEIGHT_SIZE.XXL]: {
|
|
139
|
+
defaultHeight: 65,
|
|
140
|
+
minHeight: 65,
|
|
141
|
+
maxHeight: 75,
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
[BUTTON_DISABLE_MAX_HEIGHT_SIZE.XXXL]: {
|
|
145
|
+
defaultHeight: 75,
|
|
146
|
+
minHeight: 75,
|
|
147
|
+
maxHeight: 200,
|
|
148
|
+
},
|
|
149
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
|
|
3
|
-
import { max, perc
|
|
3
|
+
import { max, perc } from "@krakenjs/belter/src";
|
|
4
4
|
import {
|
|
5
5
|
FUNDING,
|
|
6
6
|
type FundingEligibilityType,
|
|
@@ -12,88 +12,30 @@ import {
|
|
|
12
12
|
BUTTON_NUMBER,
|
|
13
13
|
CLASS,
|
|
14
14
|
ATTRIBUTE,
|
|
15
|
-
BUTTON_SIZE,
|
|
16
15
|
} from "../../../constants";
|
|
17
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
BUTTON_SIZE_STYLE,
|
|
18
|
+
BUTTON_RELATIVE_STYLE,
|
|
19
|
+
BUTTON_DISABLE_MAX_HEIGHT_STYLE,
|
|
20
|
+
} from "../config";
|
|
18
21
|
import { isBorderRadiusNumber } from "../util";
|
|
19
22
|
import type { Experiment } from "../../../types";
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
import {
|
|
25
|
+
getResponsiveStyleVariables,
|
|
26
|
+
getDisableMaxHeightResponsiveStyleVariables,
|
|
27
|
+
} from "./styleUtils";
|
|
23
28
|
|
|
24
29
|
const FIRST_BUTTON_PERC = 50;
|
|
25
30
|
const WALLET_BUTTON_PERC = 60;
|
|
26
31
|
|
|
27
|
-
|
|
28
|
-
height,
|
|
29
|
-
fundingEligibility,
|
|
30
|
-
experiment = {},
|
|
31
|
-
size,
|
|
32
|
-
}: {|
|
|
33
|
-
height?: ?number,
|
|
34
|
-
fundingEligibility: FundingEligibilityType,
|
|
35
|
-
experiment: Experiment,
|
|
36
|
-
size: $Values<typeof BUTTON_SIZE>,
|
|
37
|
-
|}): Object {
|
|
38
|
-
const { isPaypalRebrandEnabled, defaultBlueButtonColor } = experiment;
|
|
39
|
-
const shouldApplyRebrandedStyles =
|
|
40
|
-
isPaypalRebrandEnabled && defaultBlueButtonColor !== "gold";
|
|
41
|
-
|
|
42
|
-
const style = BUTTON_SIZE_STYLE[size];
|
|
43
|
-
|
|
44
|
-
const buttonHeight = height || style.defaultHeight;
|
|
45
|
-
const minDualWidth = Math.max(
|
|
46
|
-
Math.round(
|
|
47
|
-
buttonHeight * BUTTON_MIN_ASPECT_RATIO * (100 / WALLET_BUTTON_PERC)
|
|
48
|
-
),
|
|
49
|
-
MIN_SPLIT_BUTTON_WIDTH
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
const { paylater } = fundingEligibility;
|
|
53
|
-
|
|
54
|
-
const shouldResizeLabel =
|
|
55
|
-
paylater?.products?.paylater?.variant === "DE" ||
|
|
56
|
-
paylater?.products?.payIn3?.variant === "IT" ||
|
|
57
|
-
paylater?.products?.payIn3?.variant === "ES";
|
|
58
|
-
|
|
59
|
-
const textPercPercentage = shouldResizeLabel ? 32 : 36;
|
|
60
|
-
const labelPercPercentage = shouldResizeLabel ? 32 : 35;
|
|
61
|
-
|
|
62
|
-
let smallerLabelHeight = max(
|
|
63
|
-
roundUp(perc(buttonHeight, labelPercPercentage) + 5, 2),
|
|
64
|
-
12
|
|
65
|
-
);
|
|
66
|
-
let labelHeight = max(roundUp(perc(buttonHeight, 35) + 5, 2), 12);
|
|
67
|
-
|
|
68
|
-
const pillBorderRadius = Math.ceil(buttonHeight / 2);
|
|
69
|
-
|
|
70
|
-
if (shouldApplyRebrandedStyles) {
|
|
71
|
-
labelHeight = roundUp(perc(buttonHeight, 76), 1);
|
|
72
|
-
// smallerLabelHeight gets triggered at widths < 320px
|
|
73
|
-
// We will need to investigate why the labels need to get significantly smaller at this breakpoint
|
|
74
|
-
smallerLabelHeight = labelHeight;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const styleVariables = {
|
|
78
|
-
style,
|
|
79
|
-
buttonHeight,
|
|
80
|
-
minDualWidth,
|
|
81
|
-
textPercPercentage,
|
|
82
|
-
smallerLabelHeight,
|
|
83
|
-
labelHeight,
|
|
84
|
-
pillBorderRadius,
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
return styleVariables;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function buttonResponsiveStyle({
|
|
32
|
+
const generateButtonSizeStyles = ({
|
|
91
33
|
height,
|
|
92
34
|
fundingEligibility,
|
|
93
35
|
disableMaxWidth,
|
|
94
36
|
disableMaxHeight,
|
|
95
37
|
borderRadius,
|
|
96
|
-
experiment
|
|
38
|
+
experiment,
|
|
97
39
|
}: {|
|
|
98
40
|
height?: ?number,
|
|
99
41
|
fundingEligibility: FundingEligibilityType,
|
|
@@ -101,7 +43,7 @@ export function buttonResponsiveStyle({
|
|
|
101
43
|
disableMaxHeight?: ?boolean,
|
|
102
44
|
borderRadius?: ?number,
|
|
103
45
|
experiment: Experiment,
|
|
104
|
-
|}): string {
|
|
46
|
+
|}): string => {
|
|
105
47
|
return Object.keys(BUTTON_SIZE_STYLE)
|
|
106
48
|
.map((size) => {
|
|
107
49
|
const {
|
|
@@ -121,7 +63,6 @@ export function buttonResponsiveStyle({
|
|
|
121
63
|
|
|
122
64
|
return `
|
|
123
65
|
@media only screen and (min-width: ${style.minWidth}px) {
|
|
124
|
-
|
|
125
66
|
.${CLASS.CONTAINER} {
|
|
126
67
|
min-width: ${style.minWidth}px;
|
|
127
68
|
${disableMaxWidth ? "" : `max-width: ${style.maxWidth}px;`};
|
|
@@ -409,8 +350,147 @@ export function buttonResponsiveStyle({
|
|
|
409
350
|
display: block;
|
|
410
351
|
}
|
|
411
352
|
}
|
|
353
|
+
`;
|
|
354
|
+
})
|
|
355
|
+
.join("\n");
|
|
356
|
+
};
|
|
412
357
|
|
|
413
|
-
|
|
358
|
+
const generateDisableMaxHeightStyles = ({
|
|
359
|
+
fundingEligibility,
|
|
360
|
+
experiment,
|
|
361
|
+
}: {|
|
|
362
|
+
fundingEligibility: FundingEligibilityType,
|
|
363
|
+
experiment: Experiment,
|
|
364
|
+
|}): string => {
|
|
365
|
+
return Object.keys(BUTTON_DISABLE_MAX_HEIGHT_STYLE)
|
|
366
|
+
.map((disableMaxHeightSize) => {
|
|
367
|
+
const {
|
|
368
|
+
disableHeightStyle,
|
|
369
|
+
buttonHeight,
|
|
370
|
+
labelHeight,
|
|
371
|
+
fontSize,
|
|
372
|
+
marginTop,
|
|
373
|
+
spinnerSize,
|
|
374
|
+
pillBorderRadius,
|
|
375
|
+
APMHeight,
|
|
376
|
+
applePayHeight,
|
|
377
|
+
} = getDisableMaxHeightResponsiveStyleVariables({
|
|
378
|
+
fundingEligibility,
|
|
379
|
+
experiment,
|
|
380
|
+
disableMaxHeightSize,
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
const { minHeight, maxHeight } = disableHeightStyle;
|
|
384
|
+
|
|
385
|
+
return `
|
|
386
|
+
@media (min-height: ${minHeight}px) and (max-height: ${maxHeight}px) {
|
|
387
|
+
.${CLASS.CONTAINER} .${CLASS.BUTTON_ROW} .${CLASS.TEXT},
|
|
388
|
+
.${CLASS.CONTAINER} .${CLASS.BUTTON_ROW} .${CLASS.SPACE} {
|
|
389
|
+
font-size: ${fontSize}px;
|
|
390
|
+
margin-top: -${marginTop}px;
|
|
391
|
+
line-height: ${labelHeight}px;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
.${CLASS.CONTAINER} .${CLASS.BUTTON_ROW} .${CLASS.TEXT} * {
|
|
395
|
+
margin-top: ${marginTop}px;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
.${CLASS.BUTTON} .${CLASS.SPINNER} {
|
|
399
|
+
height: ${spinnerSize}px;
|
|
400
|
+
width: ${spinnerSize}px;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
.${CLASS.BUTTON} > .${CLASS.BUTTON_LABEL} {
|
|
404
|
+
margin: 0 4vw;
|
|
405
|
+
height: ${labelHeight}px;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
.${CLASS.BUTTON}[${ATTRIBUTE.FUNDING_SOURCE}=${FUNDING.APPLEPAY}]
|
|
409
|
+
.${CLASS.BUTTON_LABEL} {
|
|
410
|
+
height: ${applePayHeight}px;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
.${CLASS.BUTTON}[${ATTRIBUTE.FUNDING_SOURCE}=${FUNDING.APPLEPAY}]
|
|
414
|
+
.${CLASS.BUTTON_LABEL} .${CLASS.TEXT} {
|
|
415
|
+
line-height: ${applePayHeight}px;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
.${CLASS.BUTTON}[${ATTRIBUTE.FUNDING_SOURCE}=${FUNDING.EPS}]
|
|
419
|
+
.${CLASS.BUTTON_LABEL},
|
|
420
|
+
.${CLASS.BUTTON}[${ATTRIBUTE.FUNDING_SOURCE}=${FUNDING.MYBANK}]
|
|
421
|
+
.${CLASS.BUTTON_LABEL} {
|
|
422
|
+
height: ${APMHeight}px;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
.${CLASS.BUTTON}[${ATTRIBUTE.FUNDING_SOURCE}=${FUNDING.EPS}]
|
|
426
|
+
.${CLASS.BUTTON_LABEL} .${CLASS.TEXT},
|
|
427
|
+
.${CLASS.BUTTON}[${ATTRIBUTE.FUNDING_SOURCE}=${FUNDING.EPS}]
|
|
428
|
+
.${CLASS.BUTTON_LABEL} .${CLASS.SPACE},
|
|
429
|
+
.${CLASS.BUTTON}[${ATTRIBUTE.FUNDING_SOURCE}=${FUNDING.MYBANK}]
|
|
430
|
+
.${CLASS.BUTTON_LABEL} .${CLASS.TEXT},
|
|
431
|
+
.${CLASS.BUTTON}[${ATTRIBUTE.FUNDING_SOURCE}=${FUNDING.MYBANK}]
|
|
432
|
+
.${CLASS.BUTTON_LABEL} .${CLASS.SPACE} {
|
|
433
|
+
line-height: ${APMHeight}px;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
.${CLASS.BUTTON}.${CLASS.SHAPE}-${BUTTON_SHAPE.PILL} {
|
|
437
|
+
border-radius: ${pillBorderRadius}px;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
.${CLASS.BUTTON_ROW}.${CLASS.SHAPE}-${BUTTON_SHAPE.PILL}
|
|
441
|
+
.menu-button {
|
|
442
|
+
border-top-right-radius: ${pillBorderRadius}px;
|
|
443
|
+
border-bottom-right-radius: ${pillBorderRadius}px;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
.${CLASS.BUTTON_ROW}.${CLASS.WALLET}.${CLASS.WALLET_MENU}
|
|
447
|
+
.${CLASS.BUTTON} {
|
|
448
|
+
width: calc(100% - ${buttonHeight + 2}px);
|
|
449
|
+
border-top-right-radius: 0px;
|
|
450
|
+
border-bottom-right-radius: 0px;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
.menu-button {
|
|
454
|
+
height: 100%;
|
|
455
|
+
width: auto;
|
|
456
|
+
aspect-ratio: 1;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
`;
|
|
414
460
|
})
|
|
415
461
|
.join("\n");
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
export function buttonResponsiveStyle({
|
|
465
|
+
height,
|
|
466
|
+
fundingEligibility,
|
|
467
|
+
disableMaxWidth,
|
|
468
|
+
disableMaxHeight,
|
|
469
|
+
borderRadius,
|
|
470
|
+
experiment = {},
|
|
471
|
+
}: {|
|
|
472
|
+
height?: ?number,
|
|
473
|
+
fundingEligibility: FundingEligibilityType,
|
|
474
|
+
disableMaxWidth?: ?boolean,
|
|
475
|
+
disableMaxHeight?: ?boolean,
|
|
476
|
+
borderRadius?: ?number,
|
|
477
|
+
experiment: Experiment,
|
|
478
|
+
|}): string {
|
|
479
|
+
const buttonSizeStyles = generateButtonSizeStyles({
|
|
480
|
+
height,
|
|
481
|
+
fundingEligibility,
|
|
482
|
+
disableMaxWidth,
|
|
483
|
+
disableMaxHeight,
|
|
484
|
+
borderRadius,
|
|
485
|
+
experiment,
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
const disableMaxHeightStyles = disableMaxHeight
|
|
489
|
+
? generateDisableMaxHeightStyles({
|
|
490
|
+
fundingEligibility,
|
|
491
|
+
experiment,
|
|
492
|
+
})
|
|
493
|
+
: "";
|
|
494
|
+
|
|
495
|
+
return buttonSizeStyles + disableMaxHeightStyles;
|
|
416
496
|
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
|
|
3
|
+
import { max, perc, roundUp } from "@krakenjs/belter/src";
|
|
4
|
+
import type { FundingEligibilityType } from "@paypal/sdk-constants/src";
|
|
5
|
+
|
|
6
|
+
import type { Experiment } from "../../../types";
|
|
7
|
+
import { BUTTON_DISABLE_MAX_HEIGHT_STYLE, BUTTON_SIZE_STYLE } from "../config";
|
|
8
|
+
import {
|
|
9
|
+
BUTTON_SIZE,
|
|
10
|
+
BUTTON_DISABLE_MAX_HEIGHT_SIZE,
|
|
11
|
+
} from "../../../constants";
|
|
12
|
+
|
|
13
|
+
const BUTTON_MIN_ASPECT_RATIO = 2.2;
|
|
14
|
+
const MIN_SPLIT_BUTTON_WIDTH = 300;
|
|
15
|
+
|
|
16
|
+
const WALLET_BUTTON_PERC = 60;
|
|
17
|
+
|
|
18
|
+
function getLabelHeight({
|
|
19
|
+
height,
|
|
20
|
+
shouldApplyRebrandedStyles,
|
|
21
|
+
shouldResizeLabel,
|
|
22
|
+
}: {|
|
|
23
|
+
height: number,
|
|
24
|
+
shouldApplyRebrandedStyles?: boolean,
|
|
25
|
+
shouldResizeLabel: boolean,
|
|
26
|
+
|}): number {
|
|
27
|
+
const labelPercPercentage = shouldResizeLabel ? 32 : 35;
|
|
28
|
+
let labelHeight = max(roundUp(perc(height, labelPercPercentage) + 5, 2), 12);
|
|
29
|
+
|
|
30
|
+
if (shouldApplyRebrandedStyles) {
|
|
31
|
+
labelHeight = roundUp(perc(height, 76), 1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return parseInt(labelHeight, 10);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function getFontSize({
|
|
38
|
+
height,
|
|
39
|
+
shouldResizeLabel,
|
|
40
|
+
}: {|
|
|
41
|
+
height: number,
|
|
42
|
+
shouldResizeLabel: boolean,
|
|
43
|
+
|}): number {
|
|
44
|
+
const fontPercPercentage = shouldResizeLabel ? 32 : 36;
|
|
45
|
+
const textSize = `${max(perc(height, fontPercPercentage), 10)}`;
|
|
46
|
+
|
|
47
|
+
return parseInt(textSize, 10);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getMarginTop({
|
|
51
|
+
height,
|
|
52
|
+
shouldResizeLabel,
|
|
53
|
+
}: {|
|
|
54
|
+
height: number,
|
|
55
|
+
shouldResizeLabel: boolean,
|
|
56
|
+
|}): number {
|
|
57
|
+
const marginTopPercPercentage = shouldResizeLabel ? 32 : 36;
|
|
58
|
+
const marginTop = `${perc(
|
|
59
|
+
max(perc(height, marginTopPercPercentage), 10),
|
|
60
|
+
10
|
|
61
|
+
)}`;
|
|
62
|
+
|
|
63
|
+
return parseInt(marginTop, 10);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getSpinnerSize({ height }: {| height: number |}): number {
|
|
67
|
+
const spinner = `${perc(height, 50)}`;
|
|
68
|
+
|
|
69
|
+
return parseInt(spinner, 10);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function getAPMButtonHeight({ height }: {| height: number |}): number {
|
|
73
|
+
const buttonHeight = perc(height, 50) + 5;
|
|
74
|
+
|
|
75
|
+
return parseInt(buttonHeight, 10);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function getApplePayButtonHeight({ height }: {| height: number |}): number {
|
|
79
|
+
const buttonHeight = perc(height, 80) + 5;
|
|
80
|
+
|
|
81
|
+
return parseInt(buttonHeight, 10);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function getResponsiveStyleVariables({
|
|
85
|
+
height,
|
|
86
|
+
fundingEligibility,
|
|
87
|
+
experiment = {},
|
|
88
|
+
size,
|
|
89
|
+
}: {|
|
|
90
|
+
height?: ?number,
|
|
91
|
+
fundingEligibility: FundingEligibilityType,
|
|
92
|
+
experiment: Experiment,
|
|
93
|
+
size: $Values<typeof BUTTON_SIZE>,
|
|
94
|
+
|}): Object {
|
|
95
|
+
const { isPaypalRebrandEnabled, defaultBlueButtonColor } = experiment;
|
|
96
|
+
const shouldApplyRebrandedStyles =
|
|
97
|
+
isPaypalRebrandEnabled && defaultBlueButtonColor !== "gold";
|
|
98
|
+
|
|
99
|
+
const style = BUTTON_SIZE_STYLE[size];
|
|
100
|
+
|
|
101
|
+
const buttonHeight = height || style.defaultHeight;
|
|
102
|
+
const minDualWidth = Math.max(
|
|
103
|
+
Math.round(
|
|
104
|
+
buttonHeight * BUTTON_MIN_ASPECT_RATIO * (100 / WALLET_BUTTON_PERC)
|
|
105
|
+
),
|
|
106
|
+
MIN_SPLIT_BUTTON_WIDTH
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const { paylater } = fundingEligibility;
|
|
110
|
+
|
|
111
|
+
const shouldResizeLabel =
|
|
112
|
+
paylater?.products?.paylater?.variant === "DE" ||
|
|
113
|
+
paylater?.products?.payIn3?.variant === "IT" ||
|
|
114
|
+
paylater?.products?.payIn3?.variant === "ES";
|
|
115
|
+
|
|
116
|
+
const textPercPercentage = shouldResizeLabel ? 32 : 36;
|
|
117
|
+
const labelPercPercentage = shouldResizeLabel ? 32 : 35;
|
|
118
|
+
|
|
119
|
+
let smallerLabelHeight = max(
|
|
120
|
+
roundUp(perc(buttonHeight, labelPercPercentage) + 5, 2),
|
|
121
|
+
12
|
|
122
|
+
);
|
|
123
|
+
let labelHeight = max(roundUp(perc(buttonHeight, 35) + 5, 2), 12);
|
|
124
|
+
|
|
125
|
+
const pillBorderRadius = Math.ceil(buttonHeight / 2);
|
|
126
|
+
|
|
127
|
+
if (shouldApplyRebrandedStyles) {
|
|
128
|
+
labelHeight = roundUp(perc(buttonHeight, 76), 1);
|
|
129
|
+
// smallerLabelHeight gets triggered at widths < 320px
|
|
130
|
+
// We will need to investigate why the labels need to get significantly smaller at this breakpoint
|
|
131
|
+
smallerLabelHeight = labelHeight;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const styleVariables = {
|
|
135
|
+
style,
|
|
136
|
+
buttonHeight,
|
|
137
|
+
minDualWidth,
|
|
138
|
+
textPercPercentage,
|
|
139
|
+
smallerLabelHeight,
|
|
140
|
+
labelHeight,
|
|
141
|
+
pillBorderRadius,
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
return styleVariables;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function getDisableMaxHeightResponsiveStyleVariables({
|
|
148
|
+
fundingEligibility,
|
|
149
|
+
experiment,
|
|
150
|
+
disableMaxHeightSize,
|
|
151
|
+
}: {|
|
|
152
|
+
fundingEligibility: FundingEligibilityType,
|
|
153
|
+
experiment: Experiment,
|
|
154
|
+
disableMaxHeightSize: $Values<typeof BUTTON_DISABLE_MAX_HEIGHT_SIZE>,
|
|
155
|
+
|}): Object {
|
|
156
|
+
const { isPaypalRebrandEnabled, defaultBlueButtonColor } = experiment;
|
|
157
|
+
const shouldApplyRebrandedStyles =
|
|
158
|
+
isPaypalRebrandEnabled && defaultBlueButtonColor !== "gold";
|
|
159
|
+
|
|
160
|
+
const disableHeightStyle =
|
|
161
|
+
BUTTON_DISABLE_MAX_HEIGHT_STYLE[disableMaxHeightSize];
|
|
162
|
+
const buttonHeight = disableHeightStyle.defaultHeight;
|
|
163
|
+
|
|
164
|
+
const { paylater } = fundingEligibility;
|
|
165
|
+
|
|
166
|
+
const shouldResizeLabel =
|
|
167
|
+
paylater?.products?.paylater?.variant === "DE" ||
|
|
168
|
+
paylater?.products?.payIn3?.variant === "IT" ||
|
|
169
|
+
paylater?.products?.payIn3?.variant === "ES";
|
|
170
|
+
|
|
171
|
+
const labelHeight = getLabelHeight({
|
|
172
|
+
height: buttonHeight,
|
|
173
|
+
shouldApplyRebrandedStyles,
|
|
174
|
+
shouldResizeLabel,
|
|
175
|
+
});
|
|
176
|
+
const fontSize = getFontSize({
|
|
177
|
+
height: buttonHeight,
|
|
178
|
+
shouldResizeLabel,
|
|
179
|
+
});
|
|
180
|
+
const marginTop = getMarginTop({
|
|
181
|
+
height: buttonHeight,
|
|
182
|
+
shouldResizeLabel,
|
|
183
|
+
});
|
|
184
|
+
const spinnerSize = getSpinnerSize({
|
|
185
|
+
height: buttonHeight,
|
|
186
|
+
});
|
|
187
|
+
const APMHeight = getAPMButtonHeight({
|
|
188
|
+
height: buttonHeight,
|
|
189
|
+
});
|
|
190
|
+
const applePayHeight = getApplePayButtonHeight({
|
|
191
|
+
height: buttonHeight,
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
const pillBorderRadius = Math.ceil(buttonHeight / 2);
|
|
195
|
+
|
|
196
|
+
const styleVariables = {
|
|
197
|
+
disableHeightStyle,
|
|
198
|
+
buttonHeight,
|
|
199
|
+
labelHeight,
|
|
200
|
+
fontSize,
|
|
201
|
+
marginTop,
|
|
202
|
+
spinnerSize,
|
|
203
|
+
pillBorderRadius,
|
|
204
|
+
APMHeight,
|
|
205
|
+
applePayHeight,
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
return styleVariables;
|
|
209
|
+
}
|