Skip to content

Commit b33525c

Browse files
authored
Feature/disable max height new fix (#2485)
* Initial changes for disable max height fix, added a styleUtils.js file and renamed responsive-test to styleUtils-test. Created new function getResponsiveStyleVariablesDisableMaxHeight. * Updated getResponsiveStyleVariables to handle disableMaxHeight and return new sizes for BUTTON_DISABLE_HEIGHT_SIZE. CSS for disableMaxHeight added to end and returned in buttonResponsiveStyle() * Updated code to fix flow errors * Added tests for disable max height responsiveness. Added new breakpoints for button sizes medium/large-small/big. Refactored getResponsiveVariables and added disable max height logic to new function, getDisableMaxHeightResponsiveVariables * Added disableMaxHeight tests for rebrand button and refactored responsive.js by creating a new function to generate the disableMaxHeight styles * Fixed eslint errors * Updated code to account for edge cases with APM buttons, Apple Pay, and the menu button. New functions created in styleUtils to calculate the css properties for these cases according to break points * dist/ files restored and variable name updated in config.js * Updated disable max height button size configurations * Updated test cases with new style variables and added test case to test shouldResizeLable parameter * restoring dist/button files to main * Updated variable names to include MAX in BUTTON_DISABLE_MAX_HEIGHT_SIZE/STYLE and added shouldResizeLabel test cases for getResponsiveVariables
1 parent da139fa commit b33525c

File tree

6 files changed

+1319
-266
lines changed

6 files changed

+1319
-266
lines changed

Diff for: src/constants/button.js

+12
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ export const BUTTON_SIZE = {
3838
RESPONSIVE: ("responsive": "responsive"),
3939
};
4040

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+
4153
export const BUTTON_SHAPE = {
4254
PILL: ("pill": "pill"),
4355
RECT: ("rect": "rect"),

Diff for: src/ui/buttons/config.js

+69-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
/* @flow */
22
/* eslint no-template-curly-in-string: off, max-lines: off */
33

4-
import { BUTTON_SIZE, BUTTON_LAYOUT } from "../../constants";
4+
import {
5+
BUTTON_SIZE,
6+
BUTTON_DISABLE_MAX_HEIGHT_SIZE,
7+
BUTTON_LAYOUT,
8+
} from "../../constants";
59

610
export const MINIMUM_SIZE: {|
711
[$Values<typeof BUTTON_LAYOUT>]: $Values<typeof BUTTON_SIZE>,
@@ -33,6 +37,14 @@ type ButtonStyleMap = {
3337
|},
3438
};
3539

40+
type ButtonDisableMaxHeightStyleMap = {
41+
[$Values<typeof BUTTON_DISABLE_MAX_HEIGHT_SIZE>]: {|
42+
defaultHeight: number,
43+
minHeight: number,
44+
maxHeight: number,
45+
|},
46+
};
47+
3648
export const BUTTON_SIZE_STYLE: ButtonStyleMap = {
3749
[BUTTON_SIZE.TINY]: {
3850
defaultWidth: 75,
@@ -79,3 +91,59 @@ export const BUTTON_SIZE_STYLE: ButtonStyleMap = {
7991
maxHeight: 55,
8092
},
8193
};
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+
};

Diff for: src/ui/buttons/styles/responsive.js

+153-73
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow */
22

3-
import { max, perc, roundUp } from "@krakenjs/belter/src";
3+
import { max, perc } from "@krakenjs/belter/src";
44
import {
55
FUNDING,
66
type FundingEligibilityType,
@@ -12,96 +12,38 @@ import {
1212
BUTTON_NUMBER,
1313
CLASS,
1414
ATTRIBUTE,
15-
BUTTON_SIZE,
1615
} from "../../../constants";
17-
import { BUTTON_SIZE_STYLE, BUTTON_RELATIVE_STYLE } from "../config";
16+
import {
17+
BUTTON_SIZE_STYLE,
18+
BUTTON_RELATIVE_STYLE,
19+
BUTTON_DISABLE_MAX_HEIGHT_STYLE,
20+
} from "../config";
1821
import { isBorderRadiusNumber } from "../util";
1922
import type { Experiment } from "../../../types";
2023

21-
const BUTTON_MIN_ASPECT_RATIO = 2.2;
22-
const MIN_SPLIT_BUTTON_WIDTH = 300;
24+
import {
25+
getResponsiveStyleVariables,
26+
getDisableMaxHeightResponsiveStyleVariables,
27+
} from "./styleUtils";
2328

2429
const FIRST_BUTTON_PERC = 50;
2530
const WALLET_BUTTON_PERC = 60;
2631

27-
export function getResponsiveStyleVariables({
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 = ({
9133
height,
9234
fundingEligibility,
9335
disableMaxWidth,
9436
disableMaxHeight,
9537
borderRadius,
96-
experiment = {},
38+
experiment,
9739
}: {|
9840
height?: ?number,
9941
fundingEligibility: FundingEligibilityType,
10042
disableMaxWidth?: ?boolean,
10143
disableMaxHeight?: ?boolean,
10244
borderRadius?: ?number,
10345
experiment: Experiment,
104-
|}): string {
46+
|}): string => {
10547
return Object.keys(BUTTON_SIZE_STYLE)
10648
.map((size) => {
10749
const {
@@ -121,7 +63,6 @@ export function buttonResponsiveStyle({
12163

12264
return `
12365
@media only screen and (min-width: ${style.minWidth}px) {
124-
12566
.${CLASS.CONTAINER} {
12667
min-width: ${style.minWidth}px;
12768
${disableMaxWidth ? "" : `max-width: ${style.maxWidth}px;`};
@@ -409,8 +350,147 @@ export function buttonResponsiveStyle({
409350
display: block;
410351
}
411352
}
353+
`;
354+
})
355+
.join("\n");
356+
};
412357

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+
`;
414460
})
415461
.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;
416496
}

0 commit comments

Comments
 (0)