Skip to content

Commit c4e039a

Browse files
committed
Added disableMaxHeight tests for rebrand button and refactored responsive.js by creating a new function to generate the disableMaxHeight styles
1 parent a3529b9 commit c4e039a

File tree

3 files changed

+221
-47
lines changed

3 files changed

+221
-47
lines changed

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

+52-16
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,7 +12,6 @@ import {
1212
BUTTON_NUMBER,
1313
CLASS,
1414
ATTRIBUTE,
15-
BUTTON_SIZE,
1615
} from "../../../constants";
1716
import {
1817
BUTTON_SIZE_STYLE,
@@ -29,25 +28,22 @@ import {
2928
const FIRST_BUTTON_PERC = 50;
3029
const WALLET_BUTTON_PERC = 60;
3130

32-
export function buttonResponsiveStyle({
31+
const generateButtonSizeStyles = ({
3332
height,
3433
fundingEligibility,
3534
disableMaxWidth,
3635
disableMaxHeight,
3736
borderRadius,
38-
experiment = {},
37+
experiment,
3938
}: {|
4039
height?: ?number,
4140
fundingEligibility: FundingEligibilityType,
4241
disableMaxWidth?: ?boolean,
4342
disableMaxHeight?: ?boolean,
4443
borderRadius?: ?number,
4544
experiment: Experiment,
46-
|}): string {
47-
let button_size_style_obj = "";
48-
let button_disable_max_style = "";
49-
50-
Object.keys(BUTTON_SIZE_STYLE)
45+
|}): string => {
46+
return Object.keys(BUTTON_SIZE_STYLE)
5147
.map((size) => {
5248
const {
5349
style,
@@ -64,7 +60,7 @@ export function buttonResponsiveStyle({
6460
size,
6561
});
6662

67-
button_size_style_obj += `
63+
return `
6864
@media only screen and (min-width: ${style.minWidth}px) {
6965
.${CLASS.CONTAINER} {
7066
min-width: ${style.minWidth}px;
@@ -356,9 +352,17 @@ export function buttonResponsiveStyle({
356352
`;
357353
})
358354
.join("\n");
355+
};
359356

360-
if (disableMaxHeight) {
361-
Object.keys(BUTTON_DISABLE_MAX_HEIGHT_STYLE).map((disableMaxHeightSize) => {
357+
const generateDisableMaxHeightStyles = ({
358+
fundingEligibility,
359+
experiment,
360+
}: {|
361+
fundingEligibility: FundingEligibilityType,
362+
experiment: Experiment,
363+
|}): string => {
364+
return Object.keys(BUTTON_DISABLE_MAX_HEIGHT_STYLE)
365+
.map((disableMaxHeightSize) => {
362366
const {
363367
disableHeightStyle,
364368
labelHeight,
@@ -373,7 +377,7 @@ export function buttonResponsiveStyle({
373377

374378
const { minHeight, maxHeight } = disableHeightStyle;
375379

376-
button_disable_max_style += `
380+
return `
377381
@media (min-height: ${minHeight}px) and (max-height: ${maxHeight}px) {
378382
.${CLASS.CONTAINER} .${CLASS.BUTTON_ROW} .${CLASS.TEXT},
379383
.${CLASS.CONTAINER} .${CLASS.BUTTON_ROW} .${CLASS.SPACE} {
@@ -396,8 +400,40 @@ export function buttonResponsiveStyle({
396400
}
397401
}
398402
`;
399-
});
400-
}
403+
})
404+
.join("\n");
405+
};
406+
407+
export function buttonResponsiveStyle({
408+
height,
409+
fundingEligibility,
410+
disableMaxWidth,
411+
disableMaxHeight,
412+
borderRadius,
413+
experiment = {},
414+
}: {|
415+
height?: ?number,
416+
fundingEligibility: FundingEligibilityType,
417+
disableMaxWidth?: ?boolean,
418+
disableMaxHeight?: ?boolean,
419+
borderRadius?: ?number,
420+
experiment: Experiment,
421+
|}): string {
422+
const buttonSizeStyles = generateButtonSizeStyles({
423+
height,
424+
fundingEligibility,
425+
disableMaxWidth,
426+
disableMaxHeight,
427+
borderRadius,
428+
experiment,
429+
});
430+
431+
const disableMaxHeightStyles = disableMaxHeight
432+
? generateDisableMaxHeightStyles({
433+
fundingEligibility,
434+
experiment,
435+
})
436+
: "";
401437

402-
return button_size_style_obj + button_disable_max_style;
438+
return buttonSizeStyles + disableMaxHeightStyles;
403439
}

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

+6-13
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ const MIN_SPLIT_BUTTON_WIDTH = 300;
1414
const FIRST_BUTTON_PERC = 50;
1515
const WALLET_BUTTON_PERC = 60;
1616

17-
export function getLabelHeight({
17+
function getLabelHeight({
1818
height,
1919
shouldApplyRebrandedStyles,
2020
shouldResizeLabel,
2121
}: {
2222
height: number,
23-
shouldApplyRebrandedStyles: boolean,
23+
shouldApplyRebrandedStyles?: boolean,
2424
shouldResizeLabel: boolean,
2525
}): number {
2626
const labelPercPercentage = shouldResizeLabel ? 32 : 35;
@@ -33,7 +33,7 @@ export function getLabelHeight({
3333
return parseInt(labelHeight, 10);
3434
}
3535

36-
export function getFontSize({
36+
function getFontSize({
3737
height,
3838
shouldResizeLabel,
3939
}: {
@@ -46,15 +46,14 @@ export function getFontSize({
4646
return parseInt(textSize, 10);
4747
}
4848

49-
export function getMarginTop({
49+
function getMarginTop({
5050
height,
5151
shouldResizeLabel,
5252
}: {
5353
height: number,
5454
shouldResizeLabel: boolean,
5555
}): number {
5656
const marginTopPercPercentage = shouldResizeLabel ? 32 : 36;
57-
5857
const marginTop = `${perc(
5958
max(perc(height, marginTopPercPercentage), 10),
6059
10
@@ -63,7 +62,7 @@ export function getMarginTop({
6362
return parseInt(marginTop, 10);
6463
}
6564

66-
export function getSpinnerSize({ height }: { height: number }): number {
65+
function getSpinnerSize({ height }: { height: number }): number {
6766
const spinner = `${perc(height, 50)}`;
6867

6968
return parseInt(spinner, 10);
@@ -147,11 +146,6 @@ export function getDisableMaxHeightResponsiveStyleVariables({
147146

148147
const disableHeightStyle =
149148
BUTTON_DISABLE_MAX_HEIGHT_STYLE[disableMaxHeightSize];
150-
151-
if (!disableHeightStyle) {
152-
return {};
153-
}
154-
155149
const buttonHeight = disableHeightStyle.defaultHeight;
156150

157151
const { paylater } = fundingEligibility;
@@ -161,12 +155,11 @@ export function getDisableMaxHeightResponsiveStyleVariables({
161155
paylater?.products?.payIn3?.variant === "IT" ||
162156
paylater?.products?.payIn3?.variant === "ES";
163157

164-
let labelHeight = getLabelHeight({
158+
const labelHeight = getLabelHeight({
165159
height: buttonHeight,
166160
shouldApplyRebrandedStyles,
167161
shouldResizeLabel,
168162
});
169-
170163
const fontSize = getFontSize({
171164
height: buttonHeight,
172165
shouldApplyRebrandedStyles,

0 commit comments

Comments
 (0)