Skip to content

Commit ebe3af3

Browse files
wjrosadaledupreez
andauthored
Increase the OC checkout font size (#4564)
* Increase the OC checkout font size * Changelog and readme entries * Unit test * Fix parsing of decimal values * Moving the font definition to getAppearance * Update client/stripe-utils/utils.js Co-authored-by: daledupreez <[email protected]> * Fix method comment * Update client/stripe-utils/__tests__/utils.test.js Co-authored-by: daledupreez <[email protected]> * Test case for decimals --------- Co-authored-by: daledupreez <[email protected]>
1 parent c16b463 commit ebe3af3

File tree

6 files changed

+79
-1
lines changed

6 files changed

+79
-1
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Changelog ***
22

33
= 9.8.0 - xxxx-xx-xx =
4+
* Update - Increases the default font size for the Optimized Checkout payment element to match the rest of the checkout form
45
* Fix - Checks for the subscription payment method (if it is Stripe) when verifying for the payment method detachment
56
* Update - Removes the ability to change the title for the Optimized Checkout payment element, as it is now set to "Stripe" by default
67
* Update - Copy for the Optimized Checkout settings and notices
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { getFontSizeBase } from '../utils';
2+
3+
describe( 'utils', () => {
4+
describe( 'getFontSizeBase', () => {
5+
const globalValues = global.wc_stripe_upe_params;
6+
7+
beforeEach( () => {
8+
global.wc_stripe_upe_params = {
9+
isOCEnabled: false,
10+
};
11+
} );
12+
13+
afterEach( () => {
14+
global.wc_stripe_upe_params = globalValues;
15+
} );
16+
17+
it( 'Optimized Checkout - should increase the provided font size by 2', () => {
18+
global.wc_stripe_upe_params = { isOCEnabled: true };
19+
20+
const fontSize = '16px';
21+
const expectedFontSize = '18px';
22+
const result = getFontSizeBase( fontSize );
23+
expect( result ).toBe( expectedFontSize );
24+
} );
25+
26+
it( 'Optimized Checkout - should increase the provided font size by 2 (decimal value)', () => {
27+
global.wc_stripe_upe_params = { isOCEnabled: true };
28+
29+
const fontSize = '16.5px';
30+
const expectedFontSize = '18.5px';
31+
const result = getFontSizeBase( fontSize );
32+
expect( result ).toBe( expectedFontSize );
33+
} );
34+
35+
it( 'default size', () => {
36+
const fontSize = '16px';
37+
const expectedFontSize = '16px';
38+
const result = getFontSizeBase( fontSize );
39+
expect( result ).toBe( expectedFontSize );
40+
} );
41+
} );
42+
} );

client/stripe-utils/utils.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,3 +842,22 @@ export const maybeClearBlikCodeValidation = () => {
842842
);
843843
}
844844
};
845+
846+
/**
847+
* Gets the base font size for both the regular checkout and the Optimized Checkout (which is 2px larger than the default font size).
848+
* So it matches the rest of the checkout form when it is scaled down.
849+
*
850+
* @param {string} defaultFontSize The default font size of the checkout form, e.g. '16px'.
851+
* @return {string} The base font size.
852+
*/
853+
export const getFontSizeBase = ( defaultFontSize ) => {
854+
if ( getStripeServerData()?.isOCEnabled ) {
855+
// Find numbers for font size.
856+
const matches = defaultFontSize.match( /(\d+(?:\.\d+)?)/ );
857+
if ( matches.length > 0 ) {
858+
return parseFloat( matches[ 0 ] ) + 2 + 'px';
859+
}
860+
}
861+
862+
return defaultFontSize;
863+
};

client/styles/upe/__tests__/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ describe( 'Getting styles for automated theming', () => {
2424
},
2525
};
2626

27+
const globalValues = global.wc_stripe_upe_params;
28+
29+
beforeEach( () => {
30+
global.wc_stripe_upe_params = {
31+
isOCEnabled: false,
32+
};
33+
} );
34+
35+
afterEach( () => {
36+
global.wc_stripe_upe_params = globalValues;
37+
} );
38+
2739
it( 'getFieldStyles returns correct styles for inputs', () => {
2840
jest.spyOn( document, 'querySelector' ).mockImplementation( () => {
2941
return mockElement;
@@ -103,6 +115,8 @@ describe( 'Getting styles for automated theming', () => {
103115
} );
104116

105117
it( 'getAppearance returns the object with filtered CSS rules for UPE theming', () => {
118+
global.wc_stripe_upe_params = { isOCEnabled: false };
119+
106120
jest.spyOn( document, 'querySelector' ).mockImplementation( () => {
107121
return mockElement;
108122
} );

client/styles/upe/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
getBackgroundColor,
66
isColorLight,
77
} from './utils.js';
8+
import { getFontSizeBase } from 'wcstripe/stripe-utils';
89

910
const appearanceSelectors = {
1011
default: {
@@ -387,7 +388,7 @@ export const getAppearance = ( isBlocksCheckout = false ) => {
387388
? inputRules.color
388389
: paragraphRules.color,
389390
fontFamily: paragraphRules.fontFamily,
390-
fontSizeBase: paragraphRules.fontSize,
391+
fontSizeBase: getFontSizeBase( paragraphRules.fontSize ),
391392
};
392393

393394
const appearance = {

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
111111
== Changelog ==
112112

113113
= 9.8.0 - xxxx-xx-xx =
114+
* Update - Increases the default font size for the Optimized Checkout payment element to match the rest of the checkout form
114115
* Fix - Checks for the subscription payment method (if it is Stripe) when verifying for the payment method detachment
115116
* Update - Removes the ability to change the title for the Optimized Checkout payment element, as it is now set to "Stripe" by default
116117
* Update - Copy for the Optimized Checkout settings and notices

0 commit comments

Comments
 (0)