Skip to content

Commit d5187c4

Browse files
Add/1427 style woopay express checkout button (#5153)
1 parent a4b8157 commit d5187c4

File tree

11 files changed

+276
-56
lines changed

11 files changed

+276
-56
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Significance: patch
2+
Type: update
3+
Comment: Updating the styling of the WooPay Express Checkout button which is currently behind a feature flag and not yet available to the public.
4+
5+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import ReactDOM from 'react-dom';
5+
6+
/**
7+
* Internal dependencies
8+
*/
9+
import { WoopayExpressCheckoutButton } from './woopay-express-checkout-button';
10+
11+
const renderPlatformCheckoutExpressButton = () => {
12+
const platformCheckoutContainer = document.getElementById(
13+
'wcpay-platform-checkout-button'
14+
);
15+
16+
if ( platformCheckoutContainer ) {
17+
ReactDOM.render(
18+
<WoopayExpressCheckoutButton
19+
buttonSettings={ global.wcpayWooPayExpressParams.button }
20+
/>,
21+
platformCheckoutContainer
22+
);
23+
}
24+
};
25+
26+
window.addEventListener( 'load', () => {
27+
renderPlatformCheckoutExpressButton();
28+
} );
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { sprintf, __ } from '@wordpress/i18n';
5+
6+
/**
7+
* Internal dependencies
8+
*/
9+
import WoopayIcon from './woopay-icon';
10+
11+
export const WoopayExpressCheckoutButton = ( {
12+
isPreview = false,
13+
buttonSettings,
14+
} ) => {
15+
const { type: buttonType, text, height, size, theme } = buttonSettings;
16+
17+
const initPlatformCheckout = ( e ) => {
18+
e.preventDefault();
19+
20+
if ( isPreview ) {
21+
return; // eslint-disable-line no-useless-return
22+
}
23+
24+
// Add buton functionality.
25+
};
26+
27+
return (
28+
<button
29+
key={ `${ buttonType }-${ theme }-${ size }` }
30+
onClick={ initPlatformCheckout }
31+
className="woopay-express-button"
32+
data-type={ buttonType }
33+
data-size={ size }
34+
data-theme={ theme }
35+
style={ { height: `${ height }px` } }
36+
>
37+
{ 'default' !== buttonType
38+
? sprintf( __( `%s with`, 'woocommerce-payments' ), text )
39+
: '' }
40+
<WoopayIcon />
41+
</button>
42+
);
43+
};

client/checkout/platform-checkout/express-button/woopay-icon.js

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/checkout/platform-checkout/style.scss

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,77 @@
121121
}
122122
}
123123
}
124+
125+
.woopay-express-button {
126+
font-size: 20px;
127+
font-weight: normal;
128+
font-family: 'SF Pro Text', 'Helvetica Neue', 'Helvetica', 'Roboto', 'Arial',
129+
sans-serif;
130+
line-height: 42px;
131+
background: $white;
132+
border: 1px solid $white;
133+
color: $studio-woocommerce-purple-60;
134+
width: 100%;
135+
border-radius: 4px;
136+
padding-top: 1px;
137+
padding-bottom: 1px;
138+
display: flex;
139+
align-items: center;
140+
justify-content: center;
141+
142+
svg {
143+
fill: $studio-woocommerce-purple-60;
144+
position: relative;
145+
top: 1px;
146+
}
147+
148+
&[data-theme='dark'] {
149+
background: $studio-woocommerce-purple-60;
150+
color: $white;
151+
152+
svg {
153+
fill: $white;
154+
}
155+
}
156+
157+
&[data-theme='light-outline'] {
158+
border-color: $studio-woocommerce-purple-60;
159+
}
160+
161+
&[data-size='medium'] {
162+
font-size: 25px;
163+
line-height: 48px;
164+
165+
svg {
166+
top: 2px;
167+
width: auto;
168+
height: 27px;
169+
}
170+
}
171+
172+
&[data-size='large'] {
173+
font-size: 29px;
174+
line-height: 56px;
175+
176+
svg {
177+
top: 3px;
178+
width: auto;
179+
height: 32px;
180+
}
181+
}
182+
183+
&[data-type='buy'],
184+
&[data-type='book'],
185+
&[data-type='donate'] {
186+
svg {
187+
margin-left: 8px;
188+
}
189+
190+
&[data-size='medium'],
191+
&[data-size='large'] {
192+
svg {
193+
margin-left: 10px;
194+
}
195+
}
196+
}
197+
}

client/settings/express-checkout-settings/index.scss

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,25 @@
134134
font-size: 20px;
135135
font-weight: normal;
136136
line-height: 42px;
137-
background: #fff;
138-
border: 1px solid #fff;
139-
color: $studio-woocommerce-purple-70;
137+
background: $white;
138+
border: 1px solid $white;
139+
color: $studio-woocommerce-purple-60;
140140
width: 100%;
141141
border-radius: 4px;
142142
padding-top: 1px;
143143
padding-bottom: 1px;
144144

145145
&[class*='dark'] {
146-
background: $studio-woocommerce-purple-70;
147-
color: #fff;
146+
background: $studio-woocommerce-purple-60;
147+
color: $white;
148+
149+
svg {
150+
fill: $white;
151+
}
148152
}
149153

150154
&[class*='outline'] {
151-
border-color: $studio-woocommerce-purple-70;
155+
border-color: $studio-woocommerce-purple-60;
152156
}
153157

154158
&[class*='medium'] {
@@ -160,4 +164,8 @@
160164
font-size: 32px;
161165
line-height: 56px;
162166
}
167+
168+
svg {
169+
fill: $studio-woocommerce-purple-60;
170+
}
163171
}

client/settings/express-checkout-settings/platform-checkout-button-preview.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

client/settings/express-checkout-settings/platform-checkout-settings.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
usePlatformCheckoutButtonTheme,
2828
usePlatformCheckoutLocations,
2929
} from 'wcpay/data';
30-
import PlatformCheckoutButtonPreview from './platform-checkout-button-preview';
30+
import { WoopayExpressCheckoutButton } from 'wcpay/checkout/platform-checkout/express-button/woopay-express-checkout-button';
3131

3232
const CUSTOM_MESSAGE_MAX_LENGTH = 100;
3333

@@ -167,6 +167,43 @@ const PlatformCheckoutSettings = ( { section } ) => {
167167
}
168168
};
169169

170+
const getButtonSettings = () => {
171+
let text = '';
172+
switch ( buttonType ) {
173+
case 'buy':
174+
text = 'Buy';
175+
break;
176+
case 'donate':
177+
text = 'Donate';
178+
break;
179+
case 'book':
180+
text = 'Book';
181+
break;
182+
default:
183+
text = '';
184+
}
185+
186+
let height = 0;
187+
switch ( size ) {
188+
case 'medium':
189+
height = 48;
190+
break;
191+
case 'large':
192+
height = 56;
193+
break;
194+
default:
195+
height = 40;
196+
}
197+
198+
return {
199+
type: buttonType,
200+
text,
201+
theme,
202+
height,
203+
size,
204+
};
205+
};
206+
170207
return (
171208
<div className="platform-checkout-settings">
172209
{ 'enable' === section && (
@@ -345,7 +382,10 @@ const PlatformCheckoutSettings = ( { section } ) => {
345382
onChange={ setTheme }
346383
/>
347384
<p>{ __( 'Preview', 'woocommerce-payments' ) }</p>
348-
<PlatformCheckoutButtonPreview />
385+
<WoopayExpressCheckoutButton
386+
isPreview={ true }
387+
buttonSettings={ getButtonSettings() }
388+
/>
349389
</CardBody>
350390
</Card>
351391
) }

client/settings/express-checkout-settings/test/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { render, screen, within } from '@testing-library/react';
1010
*/
1111
import ExpressCheckoutSettings from '..';
1212
import PaymentRequestButtonPreview from '../payment-request-button-preview';
13-
import PlatformCheckoutButtonPreview from '../platform-checkout-button-preview';
1413

1514
jest.mock( '../../../data', () => ( {
1615
useSettings: jest.fn().mockReturnValue( {} ),
@@ -47,9 +46,6 @@ jest.mock( '@wordpress/data', () => ( {
4746
jest.mock( '../payment-request-button-preview' );
4847
PaymentRequestButtonPreview.mockImplementation( () => '<></>' );
4948

50-
jest.mock( '../platform-checkout-button-preview' );
51-
PlatformCheckoutButtonPreview.mockImplementation( () => '<></>' );
52-
5349
jest.mock( '@stripe/react-stripe-js', () => ( {
5450
Elements: jest.fn().mockReturnValue( null ),
5551
} ) );

0 commit comments

Comments
 (0)