@paypal/checkout-components 5.0.215 → 5.0.218

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paypal/checkout-components",
3
- "version": "5.0.215",
3
+ "version": "5.0.218",
4
4
  "description": "PayPal Checkout components, for integrating checkout products.",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -122,15 +122,16 @@ export function getCardConfig() : FundingSourceConfig {
122
122
  },
123
123
 
124
124
  Label: ({ logo, locale, content, custom }) => {
125
- if (custom) {
125
+ if (custom && custom.label && custom.label.length) {
126
126
  const validLabels = {
127
127
  checkout: 'Checkout'
128
128
  };
129
129
 
130
- let label = 'Checkout';
130
+ let label = validLabels.checkout;
131
131
 
132
- if (custom.label && typeof custom.label === 'string' && validLabels[custom.label.toLowerCase()]) {
133
- label = validLabels[custom.label];
132
+ const lowerCaseLabel = custom.label.toLowerCase();
133
+ if (validLabels[lowerCaseLabel]) {
134
+ label = validLabels[lowerCaseLabel];
134
135
  }
135
136
 
136
137
  return (
package/src/types.js CHANGED
@@ -54,10 +54,10 @@ export type Requires = {|
54
54
  |};
55
55
 
56
56
  export type CustomStyle = {|
57
- css : {|
57
+ css? : {|
58
58
  [string] : string
59
59
  |},
60
- label : string
60
+ label? : string
61
61
  |};
62
62
 
63
63
  export type LazyExport<T> = {|
@@ -46,7 +46,7 @@ export function Button({ fundingSource, style, multiple, locale, env, fundingEli
46
46
  userIDToken, personalization, onClick = noop, content, tagline, commit, experiment, instrument, experience } : IndividualButtonProps) : ElementNode {
47
47
 
48
48
  const { custom, layout, shape } = style;
49
- const inlineExperience = experience === EXPERIENCE.INLINE && custom;
49
+ const inlineExperience = experience === EXPERIENCE.INLINE && custom && custom.label;
50
50
  const fundingConfig = getFundingConfig()[fundingSource];
51
51
 
52
52
  if (!fundingConfig) {
@@ -130,7 +130,7 @@ export function Button({ fundingSource, style, multiple, locale, env, fundingEli
130
130
  personalization={ personalization }
131
131
  tagline={ tagline }
132
132
  content={ content }
133
- custom={ inlineExperience ? custom : null }
133
+ custom={ inlineExperience ? custom : undefined }
134
134
  experiment={ experiment }
135
135
  />
136
136
  );
@@ -102,7 +102,7 @@ export function Buttons(props : ButtonsProps) : ElementNode {
102
102
  nonce, components, onShippingChange, personalization, userIDToken, content, flow, experiment, applePaySupport,
103
103
  supportsPopups, supportedNativeBrowser, experience } = normalizeButtonProps(props);
104
104
  const { custom, layout, shape, tagline } = style;
105
- const inlineExperience = experience === EXPERIENCE.INLINE && custom;
105
+ const inlineExperience = experience === EXPERIENCE.INLINE && custom && custom.label;
106
106
 
107
107
  let fundingSources = determineEligibleFunding({ fundingSource, layout, remembered, platform, fundingEligibility, components, onShippingChange, flow, wallet, applePaySupport, supportsPopups, supportedNativeBrowser, experiment });
108
108
  const multiple = fundingSources.length > 1;
@@ -138,7 +138,7 @@ export type ButtonStyle = {|
138
138
  menuPlacement : $Values<typeof MENU_PLACEMENT>,
139
139
  period? : number,
140
140
  height? : number,
141
- custom? : CustomStyle
141
+ custom? : ?CustomStyle
142
142
  |};
143
143
 
144
144
  export type ButtonStyleInputs = {|
@@ -149,7 +149,7 @@ export type ButtonStyleInputs = {|
149
149
  layout? : $Values<typeof BUTTON_LAYOUT> | void,
150
150
  period? : number | void,
151
151
  height? : number | void,
152
- custom? : CustomStyle
152
+ custom? : ?CustomStyle
153
153
  |};
154
154
 
155
155
  type PersonalizationComponentProps = {|
@@ -454,6 +454,28 @@ export function normalizeButtonStyle(props : ?ButtonPropsInputs, style : ButtonS
454
454
  }
455
455
  }
456
456
 
457
+ if (custom) {
458
+ if (custom.label && typeof custom.label !== 'string') {
459
+ throw new Error(`style.custom.label is expected to be a String.`);
460
+ }
461
+
462
+ if (custom.css && typeof custom.css !== 'object') {
463
+ throw new Error(`style.custom.css is expected to be JSON.`);
464
+ }
465
+
466
+ if (custom.css && custom.label && custom.label.length === 0) {
467
+ throw new Error(`Expected style.custom.label to be used with style.custom.css`);
468
+ }
469
+
470
+ if (custom.label && custom.label.length > 0 && !custom.css) {
471
+ custom.css = {
472
+ 'background-color': 'black',
473
+ 'height': '48px',
474
+ 'margin-bottom': '15px'
475
+ }
476
+ }
477
+ }
478
+
457
479
  return { custom, label, layout, color, shape, tagline, height, period, menuPlacement };
458
480
  }
459
481
 
@@ -15,7 +15,7 @@ type StyleProps = {|
15
15
 
16
16
  export function Style({ style, nonce, fundingEligibility } : StyleProps) : ElementNode {
17
17
 
18
- const { custom, height } = style;
18
+ const { custom = { label: undefined, css: undefined }, height } = style;
19
19
  const css = componentStyle({ custom, height, fundingEligibility });
20
20
 
21
21
  return (
@@ -11,7 +11,7 @@ import { buttonResponsiveStyle } from './responsive';
11
11
  import { buttonColorStyle } from './color';
12
12
  import { customStyle } from './custom';
13
13
 
14
- export function componentStyle({ custom, height, fundingEligibility } : {| custom? : CustomStyle, height? : ?number, fundingEligibility : FundingEligibilityType |}) : string {
14
+ export function componentStyle({ custom, height, fundingEligibility } : {| custom? : ?CustomStyle, height? : ?number, fundingEligibility : FundingEligibilityType |}) : string {
15
15
  return `
16
16
  ${ pageStyle }
17
17
  ${ buttonStyle }
@@ -3,7 +3,7 @@
3
3
  import type { CustomStyle } from '../../../types';
4
4
  import { CLASS } from '../../../constants';
5
5
 
6
- export const customStyle = ({ custom } : {| custom? : CustomStyle |}) : string => {
6
+ export const customStyle = ({ custom } : {| custom? : ?CustomStyle |}) : string => {
7
7
  const { css } = custom || {};
8
8
 
9
9
  if (!css) {
@@ -10,6 +10,7 @@ import { getLogger } from '@paypal/sdk-client/src';
10
10
  import type { ZoidProps } from '@krakenjs/zoid/src';
11
11
 
12
12
  import { DEFAULT_POPUP_SIZE } from '../checkout';
13
+ import { EXPERIENCE } from '../../constants';
13
14
  import { Buttons } from '../../ui';
14
15
  import { type ButtonProps } from '../../ui/buttons/props';
15
16
 
@@ -41,7 +42,7 @@ export function PrerenderedButtons({ nonce, onRenderCheckout, props } : Prerende
41
42
  [ FPTI_KEY.CHOSEN_FUNDING]: fundingSource
42
43
  }).flush();
43
44
 
44
- if (fundingSource === FUNDING.VENMO || fundingSource === FUNDING.APPLEPAY) {
45
+ if (fundingSource === FUNDING.VENMO || fundingSource === FUNDING.APPLEPAY || (fundingSource === FUNDING.CARD && props.experience === EXPERIENCE.INLINE)) {
45
46
  // wait for button to load
46
47
  } else if (supportsPopups() && !props.merchantRequestedPopupsDisabled) {
47
48
  // remember the popup window to prevent showing a new popup window on every click in the prerender state